You need to sign in to do that
Don't have an account?
Edward Scott 5
Opportunity Team member on Opportunity
Hi,
I am trying to wirte a trigger that will pull the Ad ops team member from opportunity teams to the opportunity page. I found code in the forum that I was able to tweak and make work but it the trigger is on the opporunityteam so it only updates the field when I edit the opportunity team. Since our opportunity teams are inserted automatically when the opportunity is created this is a problem. I was wondering if anyone has already solved this problem.
Thanks in advance for your help,
Edward
I am trying to wirte a trigger that will pull the Ad ops team member from opportunity teams to the opportunity page. I found code in the forum that I was able to tweak and make work but it the trigger is on the opporunityteam so it only updates the field when I edit the opportunity team. Since our opportunity teams are inserted automatically when the opportunity is created this is a problem. I was wondering if anyone has already solved this problem.
Thanks in advance for your help,
Edward
Note: When adding code use the "Add a code sample" button (icon <>) to increase readability and make it easier to reference.
I believe you are seeing this issue because when the trigger fires in the before insert context the OpportunityTeamMember record(s) does/do not yet have an id, which will cause problems with your SOQL query in line 14. I also think your SOQL query on line 16 should read 'WHERE Id IN :setOpp"
I made the changes to the code but it will still only fire after I actually update the opportunity team and not the opportunity.
Thanks again for your help.
Just want to be sure I understand your flow properly: an after insert opportunity trigger inserts one or more opportunity team member records. You also have an after insert trigger on the opportunityteammember object that should update a field on the parent opportunity record, but this isn't working. This trigger also runs in the after update context and if you edit>save an opportunityteammember record then the trigger does fire as expected? Although this should affect the logic no matter the context I did find a few other changes you might want to make to your code. First, sometimes there can be issues when you attempt to update a field for a record pulled from a SOQL query that didn't include said field. So I would change your soql query on line 16 to include the Id field and the Ad_Ops_Contact1__c field. You also might want to add code below line 22 to replace the mapOpps value with the updated opportunity record like so:
I would put some System.debug statements into your trigger to flush out the problem. You might want to debug key variable values such as the parent opportunity id from the opportunityteammember trigger. Then you can follow yourself in the Salesforce Debug Log and take a peek to get a better idea of what's going wrong.