You need to sign in to do that
Don't have an account?
Shruti Nigam
System.LimitException: Too many SOQL queries: 101 Apex script unhandled trigger exception by user/organization:
Hi all,
Need help on this apex class getting sql governor limit.
Trigger to call above class:
Thanks in advance
Need help on this apex class getting sql governor limit.
public class salesprice { public static void price(Id recordsales) { try { Account ac = [Select id,percent_increase1__c,FB_NET_ARR1__c from Account where id =: recordsales ]; for( Opportunity ap : [Select id,Type from Opportunity where AccountId =: ac.Id ]) { if(ap.Type == 'Renewal') { List<OpportunityLineItem> ab = [Select id,ProductCode from opportunityLineitem where opportunityId =: ap.Id ]; if(ab[0].ProductCode == '002') { ab[0].UnitPrice = ac.percent_increase1__c * ac.FB_NET_ARR1__c; update ab; } } } } catch(Exception e) { System.debug(e); } } }
Trigger to call above class:
trigger updateproduct on Account (after insert,after update) { for(Account a: Trigger.new) { salesprice.price(a.Id); } }
Thanks in advance
@shruthi,
Try below code and you please read salesforce limitation before writing apex triggers
https://developer.salesforce.com/forums/?id=906F0000000DBl8IAG
Class: Used Maps to hold record dataTrigger: Used set/List to collect ids(bulkify) and then pass it to helper calss
Please let me know if it works for you
Thanks
Ramesh
All Answers
You are using SOQL query within a for loop.
Instead try something like:
Let me know if this helps.
Thanks.
@shruthi,
Try below code and you please read salesforce limitation before writing apex triggers
https://developer.salesforce.com/forums/?id=906F0000000DBl8IAG
Class: Used Maps to hold record dataTrigger: Used set/List to collect ids(bulkify) and then pass it to helper calss
Please let me know if it works for you
Thanks
Ramesh