You need to sign in to do that
Don't have an account?
Anshii
Approve automatically using trigger
Hi everyone , I have written a trigger so for for submitting a record for approval.i need to set the trigger to approval automatically please help me out.
Trigger:1
trigger contactcreated on Contact (after insert) {
for(contact c : trigger.new){
if(c.isprimary__c == True){
// create the new approval request to submit
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setComments('Submitted for approval. Please approve.');
req.setObjectId(c.Id);
// submit the approval request for processing
Approval.ProcessResult result = Approval.process(req);
// display if the reqeust was successful
System.debug('Submitted for approval successfully: '+result.isSuccess());
}
}
}
Trigger2:
trigger Contactcreatedapprocess on Contact (after insert) {
user u1=[select id from user where alias='anshu'];
for(contact c:Trigger.new){
if(c.isprimary__c==true){
//step1:create a approval req to submit
Approval.ProcessSubmitRequest req=new Approval.ProcessSubmitRequest();
req.setComments('submitted for approval please submit');
req.setObjectId(c.Id);
req.setSubmitterId(u1.id);
//submit the request for approval
Approval.ProcessResult result=Approval.process(req);
}
}
}
Thanks in Advance
Trigger:1
trigger contactcreated on Contact (after insert) {
for(contact c : trigger.new){
if(c.isprimary__c == True){
// create the new approval request to submit
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setComments('Submitted for approval. Please approve.');
req.setObjectId(c.Id);
// submit the approval request for processing
Approval.ProcessResult result = Approval.process(req);
// display if the reqeust was successful
System.debug('Submitted for approval successfully: '+result.isSuccess());
}
}
}
Trigger2:
trigger Contactcreatedapprocess on Contact (after insert) {
user u1=[select id from user where alias='anshu'];
for(contact c:Trigger.new){
if(c.isprimary__c==true){
//step1:create a approval req to submit
Approval.ProcessSubmitRequest req=new Approval.ProcessSubmitRequest();
req.setComments('submitted for approval please submit');
req.setObjectId(c.Id);
req.setSubmitterId(u1.id);
//submit the request for approval
Approval.ProcessResult result=Approval.process(req);
}
}
}
Thanks in Advance
You have to handle the different cases as approved, reject.
Please follow the below link as everything is given in detail:-
https://salesforcescool.blogspot.com/2018/11/submit-approval-process-using-apex.html
Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi
All Answers
You have to handle the different cases as approved, reject.
Please follow the below link as everything is given in detail:-
https://salesforcescool.blogspot.com/2018/11/submit-approval-process-using-apex.html
Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi
Have you check this link which is similar to your use case:
https://www.jitendrazaa.com/blog/salesforce/dynamic-approval-process-based-on-the-apex-and-trigger/
If it helps please mark it as best answer.
Thanks!
Where are you getting the approver from?
If it is a related user, can you set the criteria in the approval process that if the field is != that value put in the process else approve record?
Otherwise, you will have to write a trigger on the object that was actually submitted for approval
Here is some code I use in a test method to approve a record
Another nice post to refer
http://www.jitendrazaa.com/blog/salesforce/dynamic-approval-process-based-on-the-apex-and-trigger/