You need to sign in to do that
Don't have an account?

Approval process error by apex trigger
Hello everyone,
I'm executing the approval process by apex trigger on my customobject. While inserting record i'm facing the below error:
"Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, getApproverValueFromApproversGroup: execution of BeforeInsert caused by: System.DmlException: Process failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, missing required field: [objectId]: [objectId] Trigger.getApproverValueFromApproversGroup: line 31, column 1: []"
trigger logic:
Set<Id> ordrprdctIds = new Set<Id>();
for(RMA_Request__c r:trigger.new){
Id prdctid=ordrPrdctMap.get(r.Order_Product__c);
if(aprvrGrpMap.get(prdctid)!=null)
r.Approver__c= aprvrGrpMap.get(prdctid);
// Create an approval request for the RMA
if(r.Status__c=='In-Progress' && r.Approver__c!=null){
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for RMA Approval ');
req1.setObjectId(r.id);
req1.setNextApproverIds(new Id[] {r.Approver__c});
System.Debug('Approver value@@'+r.Approver__c);
// Submit the approval request for the RMA
Approval.ProcessResult result = Approval.process(req1);---> Error line
}
}
Please assist me with your valuable solution.
Thanks in advance!!
I'm executing the approval process by apex trigger on my customobject. While inserting record i'm facing the below error:
"Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, getApproverValueFromApproversGroup: execution of BeforeInsert caused by: System.DmlException: Process failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, missing required field: [objectId]: [objectId] Trigger.getApproverValueFromApproversGroup: line 31, column 1: []"
trigger logic:
Set<Id> ordrprdctIds = new Set<Id>();
for(RMA_Request__c r:trigger.new){
Id prdctid=ordrPrdctMap.get(r.Order_Product__c);
if(aprvrGrpMap.get(prdctid)!=null)
r.Approver__c= aprvrGrpMap.get(prdctid);
// Create an approval request for the RMA
if(r.Status__c=='In-Progress' && r.Approver__c!=null){
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for RMA Approval ');
req1.setObjectId(r.id);
req1.setNextApproverIds(new Id[] {r.Approver__c});
System.Debug('Approver value@@'+r.Approver__c);
// Submit the approval request for the RMA
Approval.ProcessResult result = Approval.process(req1);---> Error line
}
}
Please assist me with your valuable solution.
Thanks in advance!!
All Answers
Here is the sample code for the trigger on approval process which will help you:
http://blog.jeffdouglas.com/2010/01/04/automating-salesforce-approval-processes-with-apex-triggers/
Thanks,
Pratik
Thanks
Shaijan
It is for before trigger.
@Pratik,
My trigger is also exactly like that only but this error is coming on record creation, not on the updation.
There are many persons in this world, that they will do all the things which are not possible also but they usually forget to correct small small mistakes.
That i did today, there is no object ID on before triggers. Thank you for ur idea and time :) :) .