+ Start a Discussion

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


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,


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')){
        Update Opp;