• Liubov Korneva
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
So here is the scenario, I want to have an error message when user click Save after he changes Opportunity Stage from 10% Probability to 20% probability. I am using Related list Object Contact Role so not sure if this is what causing the issue

trigger ContactValidate on Opportunity ( before update ) {

    Set<ID> oppId = new Set<ID>();
    
    for(Opportunity o : trigger.new){
        if(o.StageName != Trigger.oldMap.get(o.Id).StageName){
            oppId.add(o.Id);
        }
    }
    //If(oppId!=null){ 
    If(!oppId.IsEmpty()){ 
        List<OpportunityContactRole> OCR = [select id from OpportunityContactRole where OpportunityId=:oppId];
            if( OCR.size()==0 ){
                for(Opportunity o : trigger.new){
                    if(o.Probability == 10){
                        o.addError('No Contact associated with opportunity');
                     }    
                }
           }
        }
   }

 
Hi, 
I have an assignment. I have multiple record types 9and page layouts) for opportunity stages. The assignment is to create a trigger that will prevent users from moving into another stage if Primary Contact role on the Opportunity is not entered. Please help

Thank you, 

Liubov