• jboesso
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

Guys, i'm pretty new to apex and development on Salesforce, I'm trying to build a trigger where it populates the field Fase_Ciclo_vida__c on lead with current the stagename on Opportunity.

 

Anything i'm missing?

 

 

trigger OpportunityAfter on Opportunity (after insert, after update) {
    
    if (LibCommonFunctions.isTriggerStatusActive()) {
        
        if (trigger.isUpdate) {
            
            if (trigger.new.size() == 1) {
                
                if (trigger.new[0].IsWon) {
                    
                    Opportunity ls = [Select Id, StageName from Opportunity where IsWon=True];
                    
                    if (trigger.new[0].ConvertedOpportunityId != null) {
                        
                        Lead o = [Select Id From Lead Where Id =: trigger.new[0].Id];
                        o.Fase_Ciclo_de_vida__c = ls.Stagename;
                        update o;
                        
                    }
                    
                }
                
            }
            
        }
        
    }

}