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
cool 183cool 183 

Auto approval process record unlock

hi,

I have created a custom button and a vf page to edit a record that is locked due to approval process. I wrote a trigger for auto approval process using after update and after insert events.The problem arises when i use after update in trigger.when i make some changes in the vf page and try saving it, it throws this error,
Visualforce ErrorHelp for this Page
System.DmlException: Update failed. First exception on row 0 with id 0069000000bgC3WAAU; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Approvalprocess1: execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: ALREADY_IN_PROCESS, Cannot submit object already in process.: [] Trigger.Approvalprocess1: line 12, column 1: []
Error is in expression '{!saveAs}' in component <apex:commandButton> in page edit_opportunity: Class.EditOpportunity.saveAs: line 38, column 1
Class.EditOpportunity.saveAs: line 38, column 1

This error does not occur when i use only after insert event. can anyone please help me ..
CvrKCvrK
Have you Checked the Record lock and Record editability options(the check boxes),if not get there and see,how those options are set.

Record editability options (make sure the second option is selected from below)

Only Administrator should unlock the record,once submitted
Both Admin or Approver can unlock the record during approval request

Record Lock options (Make sure "Unlock the record for editing is selected" from below options)

Lock the record from being edited
Unlock the record for editing

​Hope this helps.
cool 183cool 183
hi,
I wanted the record owner to edit the record even after submitted for approval.. I checked wat u have said, but tat dint work for my scenario.. I have created a custom button in object detail page..This button redirects u to a vf page similar to the obj detail page. if i make changes in that page and try saving it, it throws the above said error..I have used after update and after insert events to initiate the approval process for a record.. after update event causes this error..
CvrKCvrK
May i know what made you to create that button that redirects to a VF page for editing coz,what i wonder is,the changes that you are going to make will finally reflect on record and will be displayed on the detail page of the record,hence saved in the database, why could not you make it directly on the record itself?
cool 183cool 183
because the record is locked as it is inprogress of approval process. In this case only system admin can edit the record or the approvers(if so permission given).I want the record owner also to be given permission to edit the record which cant be made using configuration. so i created that button and visualforce page..
vinsrivvinsriv
Hi ,

Can you check the below link .You need not create Button and VF Page .You can control using record type . 

https://developer.salesforce.com/forums/?id=906F00000008xk5IAA

Let me know if this does not helps .

--Vineet