You need to sign in to do that
Don't have an account?
chaithaly gowda
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
required fields in opportunity teammember object
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
This trigger should be on 'after insert' instead of 'before insert'. As to insert an opportunity team member record 'OpportunityId' is required which will be available in after insert trigger. i.e.
Please mark this as answer if it works for you.
Thanks
All Answers
This trigger should be on 'after insert' instead of 'before insert'. As to insert an opportunity team member record 'OpportunityId' is required which will be available in after insert trigger. i.e.
Please mark this as answer if it works for you.
Thanks