function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
siddarth rajsiddarth raj 

Can the record Order be locked from Apex code

Hi Force devs

Can we lock the record order from the apex code. not from approval process.

Rgrds
SR
Vidhyasagaran MuralidharanVidhyasagaran Muralidharan
Check this whether it is helpful
https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_locking_statements.htm
siddarth rajsiddarth raj
Link explains what happens internally when the any sObjec (order) in SOQL update force platform locks that object to avoid any race condition . and to keep thread safe.

Where I wanted it is ..want to lock the object Orders once its status changed to "submitted". I could lock if the status changes from the Approval process and here Order status changes to "submitted" from the VF page written by us when user select submitt button.


Gigi.OchoaGigi.Ochoa
You could change the Record Type of that record when the Status is changed to Submitted.  Then update the page layout for that record type to have all the fields read only.

Otherwise, if you want the lock hte record the same manner as an Approval Process, you could auto submit for approval when the status is changed in an apex trigger.