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
MaarikaMaarika 

How to create a trigger that updates a checkbox on Opportunity when Opportunity team contains two required types of member roles

Hello,

I'm clearly a newbie here and would need to implement the following scenario using an update trigger:

If opportunity team contains members of two required roles (team must have a minimum one member per each role), a checkbox field gets ticked on the opportunity.

On Opportunity object-
API name : Engineers_assigned__c
Field type : Checkbox

On Opportunity Team object-
Member roles required : 'Pre-Sales Consultant' AND 'Implementation Engineer'
(minimum one of each role)

Could anyone please help with this?

Thanks so much,

M

Waqar Hussain SFWaqar Hussain SF
trigger testTrigger on OpportunityTeam (after insert, after update) {
    
List<Opportunity> Opp = [Select Id , Name, Engineers_assigned__c From Opportunity Where Id in:Trigger.New.OpportunityId]; 
    for (OpportunityTeam  p : Trigger.new) {
        if((p.Member roles__c.Contains('Pre-Sales Consultant') && p.Member roles__c.Contains('Implementation Engineer')){
            Opp.Engineers_assigned__c=true;
        Update Opp;
        }

    }

}