You need to sign in to do that
Don't have an account?
Denise Crosby
need help with trigger bulkification
Hello. I wrote an Apex trigger that works fine to update a custom field on the opportunity when an opportunitylineitem is updated. The problem is when I try to import 200 records I get the error: UpdateOpptyProductText: System.LimitException: Too many SOQL queries: 101. Many thanks for helping.
trigger UpdateOpptyProductText on OpportunityLineItem (after insert, after update) { for (OpportunityLineItem oli : Trigger.New) { Opportunity o = [select id from Opportunity where id =: oli.OpportunityId]; o.Opportunity_Products__c = ''; OpportunityLineItem[] lis = [Select id, name, product2id from opportunitylineitem where opportunityid=:o.Id]; integer count = 0; for (OpportunityLineItem li : lis) { if (count > 0) { o.Opportunity_Products__c += '; '; } Product2 p = [select id,name from Product2 where id =: li.Product2Id]; o.Opportunity_Products__c += p.name; count ++; } update o; } }
Please use below code as a refrence. This code is working for me for to get Contact Count on Account and Printing contact names on Account. Please change your Object names and fields needed.
Please let me know if helped by marking best answer.
Regards,
Ramakant
All Answers
Please use below code as a refrence. This code is working for me for to get Contact Count on Account and Printing contact names on Account. Please change your Object names and fields needed.
Please let me know if helped by marking best answer.
Regards,
Ramakant
Can you point me to any links explaining this syntax below. I'm having some trouble understanding.
Map<Id,List<Opportunity>> oppListIdMap = new Map<Id,List<Opportunity>>();
Map<Id,List<String>> prodListIdMapString = new Map<Id,List<String>>();
I started converting your pseudo code and got stuck on a few lines. Thanks for your help