7

I am inserting the record using apex and visual force page.

I want to lock the record when i click submit on the visualforce page.i.e when i open the record in salesforce I don't want the records to be edited

Can I know is there any way to achieve such senario

  • Non editable to everyone? If so can't you manage it with object settings and Field Level Security? – highfive Oct 14 '14 at 7:19
  • i have 2 button in vf page 1) allows edit for the created records 2) doesn't allow record for further editing – user6833 Oct 14 '14 at 7:31
  • so i cant manage with fied level security on some condition i am restricting the edit options – user6833 Oct 14 '14 at 7:32
  • You can fire off an approval process programmatically that could lock the record on insert via a trigger. I've done this before but can confuse users as to why the record is awaiting approval. If you have overridden view pages with VF then this isn't so obvious. – Richard Durrant Oct 14 '14 at 8:15
8

Create a validation rule on your object that doesn't allow editing if a custom checkbox field is checked:

(Locking_Checkbox__c == TRUE)

Check that box when they click the button, and do not give users the chance to change the value on that checkbox field. You could also allow specific Profiles to edit a locked record:

AND(Locking_Checkbox__c == TRUE, $Profile.Name != 'System Administrator')
  • I tried the above one – user6833 Oct 14 '14 at 13:27
3

This was released as part of winter16. There's now a setting to enable it, and an Apex method on the approval class to lock/unlock the records.

Release notes reference: http://docs.releasenotes.salesforce.com/en-us/winter16/release-notes/rn_apex_approval_locks_unlocks.htm

2

There is no way to lock the record. But you can change the record type of record based on your condition. Different record type will have different page layout. From one layout you can remove edit button.

1

If you are using a Visualforce page, you can using locking statements on click of submit button on your page which will not allow anyone else of update those particular records which you want to lock.

Please read this link to know about locking statements.

Update:

Locking statement is good for one time transaction but if you want to keep a record locked after certain stage then as @Richard Durrant said Approval Process is one option. Like on click of "Submit" button on your page, update some field that can hold the submitted stage of that record. Create Approval process with entry criteria of submitted record and don't unlock record even after approval.

Another option is to override the standard Edit button with custom VF page. If a particular record status is submitted (which you should keep in certain field once a record is submitted, best to use some checkbox), VF page will show an error that "you can't further update this record". If record is not submitted, show the fields in edited form.

I will not suggest using recordtype and pagelayout, because one can easily update a record by playing with url.

  • The lock created by lock statement won't survive to the next request. – Marcin Sz. Oct 14 '14 at 13:06
  • @BigBallOfMud: Yes you are right, I misunderstood the question. Updating my answer. – Aditi Jain Oct 14 '14 at 13:18
  • The link provided would lock record while performing some dml operations it wont lock the record permanently – user6833 Oct 14 '14 at 13:29
  • @user6833 Please see my updated answer – Aditi Jain Oct 14 '14 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.