You need to sign in to do that
Don't have an account?
Samuel Gonsalves 8
Opportunity Trigger Error "Apex script unhandled trigger exception by user/organization"
Hi All,
I was updating some opportunty data through data loader but got plenty of same error
Error :
Apex script unhandled trigger exception by user/organization: 00590000002bdRR/
00D90000000siXo
OptyStatus: System.LimitException: quotesync:Too many SOQL queries: 101
"Optystatus" is the trigger which is been created in our org
This trigger is used to update all the quote status to "Rejected" when the associated Opportunity Stage is changed to "Closed Lost". trigger OptyStatus on Opportunity (after update) { try { Set<String> Opty=new Set<String>(); for(Opportunity Opp : Trigger.new) { if(Opp.StageName=='Closed Lost') { Opty.add(Opp.Id); List<Quote> Qu = [SELECT Id, Name FROM Quote WHERE OpportunityId in: Opty]; if(Qu.size()>0) { for(Quote qut : Qu) { qut.Status='Rejected'; } try { update Qu; }// try ends catch (DMLException e) { System.debug('An unexpected error has occurred while updating Quote: ' + e.getMessage()); } } } } }//try ends catch(Exception ex) { System.debug('An unexpected error has occurred: ' + ex.getMessage()); } }
Can anyone help me out to remove this error.
Thanks in advance.
Regards,
Samuel
I was updating some opportunty data through data loader but got plenty of same error
Error :
Apex script unhandled trigger exception by user/organization: 00590000002bdRR/
00D90000000siXo
OptyStatus: System.LimitException: quotesync:Too many SOQL queries: 101
"Optystatus" is the trigger which is been created in our org
This trigger is used to update all the quote status to "Rejected" when the associated Opportunity Stage is changed to "Closed Lost". trigger OptyStatus on Opportunity (after update) { try { Set<String> Opty=new Set<String>(); for(Opportunity Opp : Trigger.new) { if(Opp.StageName=='Closed Lost') { Opty.add(Opp.Id); List<Quote> Qu = [SELECT Id, Name FROM Quote WHERE OpportunityId in: Opty]; if(Qu.size()>0) { for(Quote qut : Qu) { qut.Status='Rejected'; } try { update Qu; }// try ends catch (DMLException e) { System.debug('An unexpected error has occurred while updating Quote: ' + e.getMessage()); } } } } }//try ends catch(Exception ex) { System.debug('An unexpected error has occurred: ' + ex.getMessage()); } }
Can anyone help me out to remove this error.
Thanks in advance.
Regards,
Samuel
I am new to this so can you update the code and provide it to me. It would really be a great help. Also the process how i can update it in production.
I am a salesforce administrator of the company and has very basic knowlege of development. There is no developer so need to do by myself. Can you please help me out with it.
Thanks
As Shashank suggested, you need to bulkify your code and follow the APEX best practices.
Following is the code for above functionality.
trigger OptyStatus on Opportunity (after update) {
Set<Id> Opty = new Set<Id>();
List<Quote> lstQuteToUpdate = new List<Quote>();
for(Opportunity Opp : Trigger.new) {
if(Opp.StageName == 'Closed Lost' && Opp.StageName != trigger.OldMap.get(Opp.Id).StageName){
Opty.add(Opp.Id);
}
}
if(!Opty.isEmpty()){
for(Quote qute :[SELECT Id, Name,Status FROM Quote WHERE OpportunityId IN: Opty]){
if(qute.Status != 'Rejected'){
qute.Status = 'Rejected';
lstQuteToUpdate.add(qute);
}
}
}
if(lstQuteToUpdate.size() > 0){
try{
update lstQuteToUpdate;
}catch(Exception e){
System.debug('An unexpected error has occurred while updating Quote: ' + e.getMessage());
}
}
}
Try this code in your Sandbox first then deploy it to production through changeSets. Better take help from a developer as Shashank suggested.