You need to sign in to do that
Don't have an account?
thomas rosicky
How could the use of Lists, Sets, or Maps help avoid governor limit exceptions in the following code? Please give a detailed description which would be helpful.
for (Account a : trigger.new){
for (Contact c : [select id,otherphone from contact where accountid = :a.id]) {
c.OtherPhone= a.Phone; update c;
}
for (Contact c : [select id,otherphone from contact where accountid = :a.id]) {
c.OtherPhone= a.Phone; update c;
}
PLease check below code which you can understand by the help of comments .
Let me know if it help !!
Thanks
Manoj
I found two issue in your code
1) DML inside loop
2) SOQL inside Loop
for (Account a : trigger.new){
for (Contact c : [select id,otherphone from contact where accountid = :a.id]) {
c.OtherPhone= a.Phone; update c;
}
Please try below code :-
Always Salesforce best Practice
http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.html
Please let us know if this will help you
Thanks
Amit Chaudhary