• Tim Wilson 27
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hello,

I have this scenario where I have a child object called 'reserve__c'  for an 'opportunity' as a parent.

when a new opportunity is created ,I want to make sure user creates reserve__c record as well.
Can someone please help me with the solution! 

This is the trigger written to add the users to the opportunity team member related list


trigger oppTeammember2 on Opportunity (before insert) {
    
 
    list<opportunityteamMember> opp=new list<opportunityteamMember>();
user u=[select id from user where alias='cgowd' limit 1];
    for(opportunity o:trigger.new)
    {
        if(o.Amount>5000000)
        {
         opportunityteamMember o1=new opportunityteamMember();
           
             o1.TeamMemberRole='Account Manager';
            o1.userId=u.id;
            o1.OpportunityAccessLevel = 'All';
            o1.OpportunityId=o.id;
           
            opp.add(o1);
            
        }
         
        }
   insert opp;
            
    }

I am getting the error as:
oppTeammember2: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [OpportunityId]: [OpportunityId] Trigger.oppTeammember2: line 21, column 1
 Any help is appreciable 
Thank you