You need to sign in to do that
Don't have an account?
Apex Trigger Code Error - Approval Process auto-Submit
I'm trying to code a trigger to auto-Submit a record through the Approval Process on a Custom Object. I want to do this to make the record Read Only (I know there are others ways to do this, but I'm up for a challenge!).
My Approval Process criteria is only: when "Locked__c" (checkbox) is "True". I also have it set to auto-reject by default and lock the record
The code I'm using is below, but I'm receiving error message:
Error: Compile Error: Variable does not exist: Locked__c at line 3 column 12
I'm new to Apex coding, so any help is greatly appreciated! If any other information is needed, just let me know.
trigger Record_Lock on Plan_and_Profile__c (after update, after insert) { for (Plan_and_Profile__c a: Trigger.new) { if (a.(Locked__c == 'True')) { // Create an approval request for the account Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setComments('Automatic record lock.'); req1.setObjectID(a.id); // Submit the approval request for the account Approval.ProcessResult result = Approval.process (req1); } } }
Hi....Sorry my bad..I can see the Locked__c field is of type boolean, so you don't need to put the comparision values in single quotes. you'll need to compare it like this..
All Answers
Hi..On Line # 3 change it to. The (.) dot notation has to be between object & field.
magicforce9, when I use that, I receive this error message :
Error: Compile Error: Comparison arguments must be compatible types: Boolean, String at line 3 column 9
Hi....Sorry my bad..I can see the Locked__c field is of type boolean, so you don't need to put the comparision values in single quotes. you'll need to compare it like this..