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
Daniel Madhure 7Daniel Madhure 7 

Opportunity Team member trigger

Hello Team,

I have user (lookup field )on opportunty i want to make that field manadatory through trigger..

i want show message user is manadatory field please select user.

trigger opportunityTeamMemberTrigger  on OpportunityTeamMember (Before Insert, Before Update) {
     for (OpportunityTeamMember oppTeam: Trigger.new)
       { 
           
           if(oppTeam.User == Null){
           
           
           oppTeam.addError('please select the user');
                     
           }
                  
                } 
      
}


the trigger is active and it not working can any one tell what went wrong 
balaji Jayararmanbalaji Jayararman
Hi,

Please write a trigger on Opportunity object instead of OpportunityTeamMember Object. Below is the modified version of your code

trigger opportunityTeamMemberTrigger  on Opportunity (Before Insert, Before Update) {
     for (Opportunity oppTeam: Trigger.new) { 
           if (oppTeam.User == Null) {
                oppTeam.addError('please select the user');
           }             
     } 
}
If it does not work, Please utilize the validation rule feature in salesforce


Thanks,

 
Daniel Madhure 7Daniel Madhure 7
hello balaji ,

this trigger is not working and validation rule we cant write on opportuntyteammember 
Rohan Gupta 4Rohan Gupta 4
Hello Daniel,
If you make custom field then we used the suffix " __c"  i.e we write the name of the custom field as fieldName__c.

For more information https://codefunlife.blogspot.in/2018/02/apex-trigger.html

 
trigger opportunityTeamMemberTrigger  on Opportunity(Before Insert, Before Update) {
     for (Opportunity oppTeam: Trigger.new)
       { 
           
           if(oppTeam.User__c == Null){
           
           
           oppTeam.addError('please select the user');
                     
           }
                  
                } 
      
}
I hope your problem has solved.

Thank you
Rohan Gupta