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
Veeru AVeeru A 

Trigger to disable ability to add two users with same role in Opportunity Teams

Anyone have trigger code handy to disallow the  ability to add two users with same role in Opportunity Teams?
Shashikant SharmaShashikant Sharma
Do these steps :

1. Create a Text Field and make it Unique => Unique_Opp_Role__c
2. Create a Trigger : 
 
trigger ValidateDuplicateRole on OpportunityTeamMember (before insert, before update) {

    for( OpportunityTeamMember  otm : trigger.new ) {
    
        if( otm.TeamMemberRole != null  && otm.UserId != null ) {
            otm.Unique_Opp_Role__c = '' + otm.OpportunityId + otm.TeamMemberRole;
        }
    }
}