You need to sign in to do that
Don't have an account?
Kiran kumar 193
Asynchronous execution
HI Need help on this approach
I have a method Called
private void CreatechildRecords(List<Case> cases, Map<id,Case> oldmap) {
// Existing logic
}
when this method runnung in production we are getting 101 soql query exception.
This method is called from another method called
public void CreateCases(list<Case> newList, list<Case> oldList,map<Id,Case> oldMap)
{
CreatechildRecords(newlist, oldMap);
}
and this method is calling from trigger by passing context variables. Now My requirement is I want to execute child cases method to be asyncronous. PLease suggest how do I modify the code to support @future annotation.
Please help
I have a method Called
private void CreatechildRecords(List<Case> cases, Map<id,Case> oldmap) {
// Existing logic
}
when this method runnung in production we are getting 101 soql query exception.
This method is called from another method called
public void CreateCases(list<Case> newList, list<Case> oldList,map<Id,Case> oldMap)
{
CreatechildRecords(newlist, oldMap);
}
and this method is calling from trigger by passing context variables. Now My requirement is I want to execute child cases method to be asyncronous. PLease suggest how do I modify the code to support @future annotation.
Please help
1) https://help.salesforce.com/apex/HTViewSolution?id=000181404&language=en_US
2) https://help.salesforce.com/apex/HTViewSolution?id=000213152&language=en_US
Here are some best practices that will stop the error messages and/or help you avoid hitting the Governors Limit:
1. Since Apex runs on a Multitenant structure, Apex runtime engine strictly enforces limits to ensure code doesn't monopolize shared resources. Learn about the Governors Limit.
2. Avoid SOQL queries that are inside FOR loop.
3. Check out the Salesforce Developer Blog where you can find Best Practices for Triggers.
4. Review best practices for Trigger and Bulk requests on our Force.com Apex Code Developer's Guide.
5. Be sure you're following the key coding principals for Apex Code in our Developer's Guide.
Let us know if this will help you
Thanks
Amit Chaudhary
All you need to do is
1. Please stop cyclic execution. Here trigger written on case is caling it self because while creation of case in same execution you are creating child records.
Approach: keep a static variable of any any class and switch its value just after your one execution.
2. If you really want to keep chid record insertion in asynchronous way then you just need to apply @future annotation on method of CreatechildRecords
Here you get an idea how to use future method
https://developer.salesforce.com/blogs/developer-relations/2013/06/passing-objects-to-future-annotated-methods.html
Thanks
Sandeep Singhal
http://www.codespokes.com/
Thanks for your reply....
Here is my Create Child cases code... I tried put Static variable and @ future annotation. This is the method which is calling from class along with other methods.
Can you Please help me on the above code... and Afterupdate method calling from Trigger