You need to sign in to do that
Don't have an account?
Trigger to send email to Opportunity Primary Contact Role on Opportunity Insert Only
I need to have Salesforce automatically send an email to the Primary Contact Role on an opportunity, when the opportunity is created only (not updated), when the created opportunity meets very specific criteria in 4 of its fields.
I can get this to work for one-off opps created in the UI with a combination of a trigger and a workflow rule with email alert, BUT, this is not a viable solution, because I'm hitting governor limits when opps are created in bulk.
Any code help that a dev can provide would be much appreciated.
Here are the requirements for this to work:
If:
An opportunity is created
And the following criteria are TRUE regarding that opportunity:
- Opportunity Creator = “Salesforce Leads RT”
- Opportunity Record Type = “Custom Services”
- Opportunity field called Service_Type__c = “Quick Start”
- Opportunity field called Referring_Group__c = “In-Product Sale”
Then:
Send an email from Salesforce to the Contact Role on that opportunity listed as the Primary Contact on that opportunity
Note: the email should be sent using a custom template that is already created and saved in Salesforce with name “Test”. If this is not possible and there is some other way to send the email subject/body, that is fine, as long as I can modify the subject/body content
What are the governor limit errors you are having? I've implemented something similar before and didn't have any issues. Can you post your code?
Thanks.
Basically what I have here is a simple trigger (trigger and test class below...it passes 100% with this test), that updates a custom lookup field on opp object called Primary_Contact__c (a lookup field to contact object).
The trigger just populates an opp' Primary Contact with the first contact created for the account the opp belongs to. This is good enough.
Everything works, except when I got into my sandbox and do a test insert of 1000 new opps, I get an error that says there are "too many soql queries".