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
Sachin10Sachin10 

Opportunity split not getting created if we have trigger on Opportunity Team Member

Hi All,
I have trigger on opportunity which creates opportuntiy Splits.
I have trigger on opportunity Team Member which sets the Access to 'Read/Write'.

If the OpportunityTeamMember trigger is Active, the opportunity Splits are not getting generated.
If the OpportunityTeamMember trigger is De-Actived, the opportunity Splits along with the team members are getting generated.

Unable to figure out the reason or workaround for the same.
I even tried to creating a process builder instead of Opportunity Team Member trigger but of no luck.

Many Thanks!
HARSHIL U PARIKHHARSHIL U PARIKH
I am not sure If I have understood it correctly but if you are trying to have trigger which splits the opportunity amount among the team members then below is something that worth looking.
Trigger:
Trigger OpportunityAmountSplit On Opportunity(After Insert, After Update, After UnDelete)
{
    List<OpportunityTeamMember> finalListOfTeamMembers = New List<OpportunityTeamMember>();
    
    If(Trigger.IsInsert || Trigger.IsUpdate || Trigger.IsUnDelete)
    {
        For(Opportunity Opp : Trigger.New)
        {
            If(Opp.Amount != null)
            {
                
                List<OpportunityTeamMember> comingOppteam = [Select Id, Opportunity_Split_Amount__c FROM OpportunityTeamMember WHERE OpportunityId =:Opp.Id];
                If(comingOppteam.size() > 0)
                {
                    For(OpportunityTeamMember everyTeamMember : comingOppteam )
                    {
                           everyTeamMember.Opportunity_Split_Amount__c = (Opp.Amount) / comingOppteam.size();
                           finalListOfTeamMembers.add(everyTeamMember);
                    }
                }  
            }
        }
        try
        {
            If(!finalListOfTeamMembers.IsEmpty())
            {
                update finalListOfTeamMembers;
            }
        }
        Catch(Exception e)
        {
               System.debug('Thrown Exception for OpportunityAmountSplit Trigger Is: ' + e.getMessage());
        }
    }
}
Hope this helps!