SlideShare a Scribd company logo
How to create a “Lock” record in Salesforce without using Apex code
                       or an approval process

A recent request from a client required Saaspoint to create a record lock
outside the usual approval process. Lead Developer Enda Traynor
identified three potential ways to create the required record lock:

    1. Use Record Types and Page Layouts with an integrated
       Javascript button which “locked” the record when clicked by
       setting all of the displayed fields to read-only.
    2. Use an update Trigger which could set the record to “locked”,
       again by setting fields to read-only.
    3. Create a simple button on the record which updates a new
       field called Locked__c



Method 3 was decided to be the most efficient and flexible solution, which can be implemented as
follows:

       Add the Lock_Record button to an Opportunity:

        {!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} //adds the proper
        code for inclusion of AJAX toolkit

        var url = parent.location.href; //string for the URL of the current
        page

        var opp = new sforce.SObject("Opportunity"); // Create an Opportunity
        object that will be used to update.
        opp.Id = '{!Opportunity.Id}'; // Set the Id so that we know which
        record we are updating.
        opp.Locked__c = true; // Set the record as ‘Locked’ by setting the
        Locked__c field.

        result = sforce.connection.update([opp]); // update the Opportunity
        record
        parent.location.href = url; //refresh the page
   The code references a simple, read-only checkbox called Locked__C which is displayed on
         the page but which the user cannot change once it is set (the value is set via the page layout
         settings).

         A validation rule is also implemented on the page with logic to allow the Locked__c field to
         be set to true:

         Locked__c && NOT(ISCHANGED(Locked__c))




Screen shots

1. Screen shot showing un-ticked and read-only checkbox and "Lock Record" button:




2.

a. Screen shot showing attempt to edit the record while it is not locked:




b. Screen shot showing record saved with successful change:
3. Screen shot showing after record was locked (see checkbox) that user cannot edit the record any
more




If you’d like to speak to Enda or a member of the Saaspoint team, please feel free to contact us on
+44 0 207 182 4707 and we’d be happy to advise you on your web self-service needs.

More Related Content

PPT
Testing Ajax Web Applications
PDF
Android - Getting Started With Firebase Auth
PDF
Firebase Auth Tutorial
PDF
Banquet 42
PPTX
PhoneGap Enterprise Viewer - ConnectCon 2015
PDF
APEX Migration
PDF
Apex behind the scenes
PDF
Using HttpWatch Plug-in with Selenium Automation in Java
Testing Ajax Web Applications
Android - Getting Started With Firebase Auth
Firebase Auth Tutorial
Banquet 42
PhoneGap Enterprise Viewer - ConnectCon 2015
APEX Migration
Apex behind the scenes
Using HttpWatch Plug-in with Selenium Automation in Java

What's hot (15)

PDF
The best wiki wizard now released
PDF
Laravel website security and performance optimization guide (pro tips to fine...
ZIP
PPTX
Selenium Automation in Java Using HttpWatch Plug-in
PPTX
Progressive web apps
PDF
WordPress, Schema & more
PPTX
07.1. Android Even Handling
PDF
Laravel mail example how to send an email using markdown template in laravel 8
PPTX
Integrate to retrieve data microsoft azure
DOCX
Installing the java sdk
PPTX
Deploy with maven
PDF
Future of Mobile Web - Coldfront conf
PDF
How to publish ASP.NET Core web application via Visual Studio 2019.pdf
PDF
The web - What it has, what it lacks and where it must go - Bulgaria Web Summ...
PDF
Progressive web apps
The best wiki wizard now released
Laravel website security and performance optimization guide (pro tips to fine...
Selenium Automation in Java Using HttpWatch Plug-in
Progressive web apps
WordPress, Schema & more
07.1. Android Even Handling
Laravel mail example how to send an email using markdown template in laravel 8
Integrate to retrieve data microsoft azure
Installing the java sdk
Deploy with maven
Future of Mobile Web - Coldfront conf
How to publish ASP.NET Core web application via Visual Studio 2019.pdf
The web - What it has, what it lacks and where it must go - Bulgaria Web Summ...
Progressive web apps
Ad

Similar to How-to Create a 'Lock' record in Salesforce (20)

DOC
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
PPTX
Chapter 8 part2
DOC
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
PPTX
Session - 1 Forms and Session management.pptx
PDF
Authorization objects a simple guide.doc (1)
PDF
R Tanenbaum .Net Portfolio
DOCX
Setting up an odi agent
PPTX
Necto 16 training 20 component mode & java script
PPTX
Solving anything in VCL
PPTX
27 - Panorama Necto 14 component mode & java script - visualization & data di...
PDF
Advanced iOS Debbuging (Reloaded)
DOCX
State management
PPTX
DEVICE CHANNELS
PDF
OpenCms Days 2014 - User Generated Content in OpenCms 9.5
PPT
Flex In30 Mins
PPTX
FSD PPT.pptx sfdb sfcdevc funcrv cf. Aaaf
PDF
How to build a chat application with react js, nodejs, and socket.io
PPTX
CSC PPT 12.pptx
ODP
Building Websocket Applications with GlassFish and Grizzly
PPTX
SCWCD : Handling exceptions : CHAP : 5
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
Chapter 8 part2
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
Session - 1 Forms and Session management.pptx
Authorization objects a simple guide.doc (1)
R Tanenbaum .Net Portfolio
Setting up an odi agent
Necto 16 training 20 component mode & java script
Solving anything in VCL
27 - Panorama Necto 14 component mode & java script - visualization & data di...
Advanced iOS Debbuging (Reloaded)
State management
DEVICE CHANNELS
OpenCms Days 2014 - User Generated Content in OpenCms 9.5
Flex In30 Mins
FSD PPT.pptx sfdb sfcdevc funcrv cf. Aaaf
How to build a chat application with react js, nodejs, and socket.io
CSC PPT 12.pptx
Building Websocket Applications with GlassFish and Grizzly
SCWCD : Handling exceptions : CHAP : 5
Ad

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
Teaching material agriculture food technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Cloud computing and distributed systems.
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
A Presentation on Artificial Intelligence
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Empathic Computing: Creating Shared Understanding
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
KodekX | Application Modernization Development
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Big Data Technologies - Introduction.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Teaching material agriculture food technology
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
Machine learning based COVID-19 study performance prediction
Cloud computing and distributed systems.
Spectral efficient network and resource selection model in 5G networks
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing
A Presentation on Artificial Intelligence
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Review of recent advances in non-invasive hemoglobin estimation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Approach and Philosophy of On baking technology
Empathic Computing: Creating Shared Understanding
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication

How-to Create a 'Lock' record in Salesforce

  • 1. How to create a “Lock” record in Salesforce without using Apex code or an approval process A recent request from a client required Saaspoint to create a record lock outside the usual approval process. Lead Developer Enda Traynor identified three potential ways to create the required record lock: 1. Use Record Types and Page Layouts with an integrated Javascript button which “locked” the record when clicked by setting all of the displayed fields to read-only. 2. Use an update Trigger which could set the record to “locked”, again by setting fields to read-only. 3. Create a simple button on the record which updates a new field called Locked__c Method 3 was decided to be the most efficient and flexible solution, which can be implemented as follows:  Add the Lock_Record button to an Opportunity: {!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} //adds the proper code for inclusion of AJAX toolkit var url = parent.location.href; //string for the URL of the current page var opp = new sforce.SObject("Opportunity"); // Create an Opportunity object that will be used to update. opp.Id = '{!Opportunity.Id}'; // Set the Id so that we know which record we are updating. opp.Locked__c = true; // Set the record as ‘Locked’ by setting the Locked__c field. result = sforce.connection.update([opp]); // update the Opportunity record parent.location.href = url; //refresh the page
  • 2. The code references a simple, read-only checkbox called Locked__C which is displayed on the page but which the user cannot change once it is set (the value is set via the page layout settings). A validation rule is also implemented on the page with logic to allow the Locked__c field to be set to true: Locked__c && NOT(ISCHANGED(Locked__c)) Screen shots 1. Screen shot showing un-ticked and read-only checkbox and "Lock Record" button: 2. a. Screen shot showing attempt to edit the record while it is not locked: b. Screen shot showing record saved with successful change:
  • 3. 3. Screen shot showing after record was locked (see checkbox) that user cannot edit the record any more If you’d like to speak to Enda or a member of the Saaspoint team, please feel free to contact us on +44 0 207 182 4707 and we’d be happy to advise you on your web self-service needs.