Certain corrections that will help:
- In For loop on Opportunity, take the product associated with Opp in Set and then outside of the for loop do the query of Product that fetches the data from Set. Set will ensure that we have unique and collected data at once.
In For loop on Opportunity, take the product associated with Opp in Set and then outside of the for loop do the query of Product that fetches the data from Set. Set will ensure that we have unique and collected data at once.
Set<String> productSet = new Set<String>(); for(opportunity oppAfter : trigger.New){ productSet.add(oppAfter.Quote_line_Product_Name__c); } List<Product2> prList = [select Id, Name from Product2 where Name IN: productSet];
Set<String> productSet = new Set<String>(); for(opportunity oppAfter : trigger.New){ productSet.add(oppAfter.Quote_line_Product_Name__c); } List<Product2> prList = [select Id, Name from Product2 where Name IN: productSet];
In the similar manner, what all is needed in queries in further part of code, take that in set and do the queries outside of for loop.
- Rather than inserting the quote in between, take the values in List or Map and use them further when inserting the Quote Line Items as well as when doing the for loop over the product. This way for within for that is, nested for can be avoided.