You need to sign in to do that
Don't have an account?
Robert Wynter
Need help creating a new class
Still having a hard time wrapping my head around classes. If someone could please help me create a class for the the below trigger. I'd like to learn/ understand this better for my self. So if you wouldn't mind, if your willing to help write it, could you please add some discriptive comments withing the class so I can understand the relationship between the trigger and the class. Thx much
trigger UpdateChildAccount on Account (after update){ //create a List of all accounts being saved List<account> accountsBeingSaved = [SELECT id, name, parentId FROM Account WHERE parentid IN :trigger.new]; //create an empty List to hold child accounts later on List<account> childAccountsToUpdate = new List<Account>(); //loop through all Accounts being saved and call it 'a' for(Account a:trigger.new) { for(account ac:accountsBeingSaved) //loop through first list of all accounts being saved and call it 'ac' { if(ac.parentid == a.id) //'ac' is a child and 'a' is the parent { //add this child account to our List childAccountsToUpdate.add(new Account(Id=ac.Id,OwnerId=a.OwnerId,Approval_Progress__c=a.Approval_Progress__c,Status__c=a.Status__c)); } } } //check to see if the List is empty or not if (childAccountsToUpdate.size() > 0) { try { update childAccountsToUpdate; //update the child accounts } catch(DmlException e) { //catch exceptions in system.debug System.debug('An unexpected error has occurred: ' + e.getMessage()); } } }
Please create one class "AccountHandler" for account handler
Please refer blog how to stop recursive trigger :-
http://amitsalesforce.blogspot.in/search/label/Trigger
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
All Answers
Please create one class "AccountHandler" for account handler
Please refer blog how to stop recursive trigger :-
http://amitsalesforce.blogspot.in/search/label/Trigger
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
Please refer below link for more help
https://developer.salesforce.com/forums/ForumsMain?id=906F000000093cKIAQ
https://developer.salesforce.com/page/Trigger_Frameworks_and_Apex_Trigger_Best_Practices
http://www.embracingthecloud.com/2010/07/08/ASimpleTriggerTemplateForSalesforce.aspx
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
caused by element : FlowRecordUpdate.myRule_1_A1
caused by: Too many SOQL queries: 101
Please port your code here or send me your code on my email id. I will help you.
Same account trigger code is failing in production ? If yes then please send me all account trigger code (if you have multiple account trigger.
Happy to help u
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com