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
sfdc007sfdc007 

Trigger Help needed for opp members

Hi,

I need to write a trigger for the below scenario as follows,

Add After Upsert trigger code (SasLineItemAfter) on SAS_Line_Item__c object to upsert SAS_Line_Item__c .SAS_Assigned_SA__c into the SAS_Line_Item__c.Engagement_Script__c.Opportunity__c Sales Team.  We are not going to remove Sales Team if the SAS_Assigned_SA__c is changed to somebody else. Watch for Sales Team validtions that may come up. We don’t want those validations to just pop unhandled in the inline VF. We should trap those errors gracefully.
Add SA(s) from the Assigned SA field of the TF to the Opportunity Sales Team (on the Opportunity) with:
  1. Status = Active
  2. Team Role = Tier 2/3 SA
  3. Opportunity Access = Read/Write
Note: if multiple SAs found, put all them in the Opportunity Sales Team
Existing Assign SAs will not be added to the Opportunity Sales Team


I have written th e below trigger . but not sure if its right , kindly help me on this  issue

MY TRIGGER :
trigger OTOpportunityTrigger on SAS_Line_Item__c (before update) {
    List<OpportunityTeamMember> listOpptyTeamMem = new List<OpportunityTeamMember>();
    Set<Id> OpptyIdSet =  new Set<Id>();
    for(SAS_Line_Item__c sas : trigger.New)
    {
        //Checking Oppty SecondaryOwner
        if(sas.SAS_Assigned_SA__c != null)
        {
            OpportunityTeamMember OTM = new OpportunityTeamMember();
            OTM.UserOrGroupId = sas.SAS_Assigned_SA__c;
            OTM.Status ='Active';
            OTM.TeamMemberRole = 'Tier 2/3 SA';
            OTM.OpportunityAccessLevel = 'Read/Write';
            listOpptyTeamMem.add(OTM);

        if(listOpptyTeamMem.size() > 0)
        insert listOpptyTeamMem;

        
}
}
}

Kindly help me pls

Thanks in advance