+ Start a Discussion
podgerpodger 

Trigger to populate opportunity lookup on Opportunity Team

I am trying to create a trigger that will populate a custom lookup field (Opportunity1_c) to Opportunities on Opp Team  with the value of the Opp that the Team Member is being added onto.

 

The reason being that I want to run workflows etc off the vlaues from the parent Opp but it cant be got to by standard methods - can this be done with a trigger?

 

 I have started to try and code one but my skills are not the best. Any help would be appreciated 

 

Here is what I have come up with so far 

 

trigger Opp_Team on OpportunityTeamMember (before insert, before update) {

Map <String, Opportunity > OppMap = new Map <String, Opportunity>();
for (Opportunity p : [SELECT Id, Name from Opportunity])
{
OppMap.put(p.Name,p);
}

for (OpportunityTeamMember a: Trigger.new)
{
a.Opportunity1__c = OppMap.get(Opportunity);
}


}

Best Answer chosen by Admin (Salesforce Developers) 
Mariappan PerumalMariappan Perumal

Hi

 

try this snippet

 

trigger Opp_Team on OpportunityTeamMember (before insert, before update)

{

for (OpportunityTeamMember a: Trigger.new)
{
a.Opportunity1__c = a.OpportunityId;
}

}

 

I think the above change is fine for your requirement . and am not sure why you are creating anothere lookup field to opportunity eventhough a standard lookup field (opportunity) in opportunity team member object.

 

kindly let me know incase the problem exist even after this.

All Answers

digamber.prasaddigamber.prasad

Hi,

 

You already have a field 'Opportunity" on "Opportunity Team Member" object, which gets populated as soon as a Opp Team Member record gets created.

 

I may not be understanding your requirement correctly. Let me know your exact requirement then I will be in better position to help you out.

 

Happy to help you!

Mariappan PerumalMariappan Perumal

Hi

 

try this snippet

 

trigger Opp_Team on OpportunityTeamMember (before insert, before update)

{

for (OpportunityTeamMember a: Trigger.new)
{
a.Opportunity1__c = a.OpportunityId;
}

}

 

I think the above change is fine for your requirement . and am not sure why you are creating anothere lookup field to opportunity eventhough a standard lookup field (opportunity) in opportunity team member object.

 

kindly let me know incase the problem exist even after this.

This was selected as the best answer
podgerpodger

thanks - thats works beautifully 

 

I couldnt use the standard Opportunityy Lookup field that is there as you cant access it in worklows/validations etc