You need to sign in to do that
Don't have an account?
case comments
too many future calls
I have an after insert trigger that creates related cases when a certain type of case is created.
The snippet of code that I'm using to create these related cases are below. It worked originally, but the more I added to it, eventually I ran into the future calls error. Is there a better way for me to write out this code? Any help is appreciated. Thanks.
//Create related cases for launch cases if(caseObj.Type == 'Drupal Site Launch' || caseObj.Type == 'Classic Site Launch'){ Case JDLaunchCase = new Case(); JDLaunchCase.Subject = 'JD Launch Work'; JDLaunchCase.RecordTypeId = '012A000000177IL'; JDLaunchCase.ParentId = caseObj.ID; JDLaunchCase.Type = caseObj.Type; JDLaunchCase.Request_Type__c = 'Request New Development'; JDLaunchCase.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c; relatedCases.add(JDLaunchCase); Case ACLaunchCase = new Case(); ACLaunchCase.Subject = 'AC Launch Work'; ACLaunchCase.RecordTypeId = '012A000000177IL'; ACLaunchCase.ParentId = caseObj.Id; ACLaunchCase.Type = caseObj.Type; ACLaunchCase.Request_Type__c = 'Request New Development'; ACLaunchCase.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c; relatedcases.add( ACLaunchCase); Case Content = new Case(); Content.Subject = 'Content processing for launch'; Content.RecordTypeId = '012A000000177IL'; Content.ParentId = caseObj.Id; Content.Type = caseObj.Type; Content.Request_Type__c = 'Request New Development'; Content.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c; relatedCases.add(Content); Case LaunchQA = new Case(); LaunchQA.Subject = 'Launch QA'; LaunchQA.RecordTypeId = '012A000000177IL'; LaunchQA.ParentId = caseObj.Id; LaunchQA.Type = caseObj.Type; LaunchQA.Request_Type__c = 'Request New Development'; LaunchQA.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c; relatedCases.add(LaunchQA); Case MobileSupport = new Case(); MobileSupport.Subject = 'Mobile Support for Launch'; MobileSupport.RecordTypeId = '012A000000177IL'; MobileSupport.ParentId = caseObj.Id; MobileSupport.Type = caseObj.Type; MobileSupport.Request_Type__c = 'Request New Development'; MobileSupport.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c; relatedCases.add(MobileSupport); }
if(relatedCases != null && !relatedCases.isEmpty()) insert relatedCases;
There are a few things to look in this :
1. Why do you need a future call - If you need to insert new records based on condition you could do it in after innsert/update triiger
2. In case you need to have future call make sure
You pass a collection of input data in order to work in future call like
@future
doActionInFuture( Id sObjectId )
above is wrong and you should do
@future
doActionInFuture( Set<Id> setOfSObjectId )
3. If you are inserting/updating the same object in future make sure you handle recurrsive future call as it will give exception.
let me know if you still face issue.
All Answers
There are a few things to look in this :
1. Why do you need a future call - If you need to insert new records based on condition you could do it in after innsert/update triiger
2. In case you need to have future call make sure
You pass a collection of input data in order to work in future call like
@future
doActionInFuture( Id sObjectId )
above is wrong and you should do
@future
doActionInFuture( Set<Id> setOfSObjectId )
3. If you are inserting/updating the same object in future make sure you handle recurrsive future call as it will give exception.
let me know if you still face issue.
Thanks Shashikant,
Turns out I had a recurisive string in my code. I remedied it and the code is working now. Thanks for your help.
Your welcome mate it had been while me answering on community, feel happy that I could help you.