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

Automating Case approval process when Case is created
Hello,
I am very new to working with apex triggers and classes, and I am hoping for some help with creating an automated solution to the following scenerio....
When a case is created with a specific record type, the approval process that has been created will automatically start without the user having to press the submit for approval button.
Any ideas how I woudl do this on the standard case object and how to write the trigger and class itself???
Help me please, I woudl greatly appreciate it!
Thank you in advance,
Shawn
I am very new to working with apex triggers and classes, and I am hoping for some help with creating an automated solution to the following scenerio....
When a case is created with a specific record type, the approval process that has been created will automatically start without the user having to press the submit for approval button.
Any ideas how I woudl do this on the standard case object and how to write the trigger and class itself???
Help me please, I woudl greatly appreciate it!
Thank you in advance,
Shawn
The below code will helpful for you...!
Thanks again,
Shawn
2. Insert case record with matching criteria and add this criteria in the above code for example i have checked "RecordType.Name = 'Your record type Name' " in IF Condition and if you want multiple condition add those criteria in if condition..
If your problem solved, mark this as a best answer.
Thanks...
Still the record does not go into the approval process. I am doing this in sandbox if that makes any difference???
Thank you for your help and for helping to resolve this....
Shawn
trigger CaseApproval on Case (after insert, after update) {
for (Case currentCase : Trigger.new) {
if (currentCase.RecordType.Name == 'SF_Dev_Requests')
{
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setComments('Submitted for approval. Please approve.');
req.setObjectId(currentCase.Id);
Approval.ProcessResult result = Approval.process(req);
}
}
I have two approval processes on the case object...one is titled - SF Dev Requests (One we shoudl work with on this example) and the other is titled Sym request approval process. The approval processes have the criteria of the specific record types when these cases are created and submitted.
Thank you again for your help!
This code works fine no issue with this code.
While copy and paste this into your environment, try to remove single quotation where ever available and type it. This might be problem..
Thanks...
What coudl I have done wrong, or what coudl be stopping this?
Liek I said I have two approval processes for the case object, how does this trigger know which one to fire?
Shawn
Do you have any additional insight to why the trigger is not firing?
I thank you for your continued support and help with achieving this goal!
Shawn
1. Please make sure both trigger and approval process must be active.
2. Verify if the trigger or approval process meeting criteria to fire approval process.
Let me know stil face any issue...!
Thanks..