function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kingsixkingsix 

The Problem with Trigger (Update stagename)

Hello, I wrote one class and one trigger for process. If someone change the Quote status to 'accepted', the opportunities stage change to 'Closed Won' automaticly. But my codes has some problem when it running. Can anyone help me?

 

Class,

 

public with sharing class Stagechange {
  
      public static void Stagech(List<Quote> myQuote){
      
      for(Quote st1 :myQuote){
        if(st1.Status ==''accepted'){
          
                  
          Opportunity a01 = new Opportunity ();
          a01.AccountId = st1.Id;
          a01.Stagename = 'Closed Won';

         update a01;  

          
        }
        
      }
      
    }
    
}

 

 

Trigger,

 

trigger test on Quote (after update) {
  
    if(Trigger.isUpdate){
      
       List<Quote> st = trigger.new;
       Stagechange.Stagech(st);        

        
    }
}

 

 

AhmedPotAhmedPot

Hi,

 

You are performing DML operation inside for loop. you need to remove DML statements outside loop. Add your Opportunity to a list and then call update statement. Also you are assigning quote id value to accountid field of Opportunity. Rest looks fine.

 

Thanks,

Ahmed