You need to sign in to do that
Don't have an account?
Trigger Question
I need to insert a record into a custom object on save in opportunity. Here is my trigger:
trigger AddSRSplit on Opportunity (after insert) {
for (Opportunity o : Trigger.new) {
Sales_Rep_Split_Revenue__c Split= new Sales_Rep_Split_Revenue__c
( Name = 'No Split',
opportunity__C = o.ID,
Split__c = 100,
Sales_Rep__c = o.owner);
insert Split; }
}
The problem is that I can not get the opportunity owner to be the sales rep name in the custom object, it keeps failing saying that an ID is expected. Any help would be appreciated!
Hi,
I am providing an running example
Change Contact with your Object.
All Answers
The "Owner" field on the object is actually a reference Object to lookup to fields on the owner. For example you could do something like:
Owner.Name
Assuming you queried the Owner records that is. So in the context of the trigger it wouldn't assign anything since chances are it will be null when you first enter that Context.
Now to how to resolve your issue, use the OwnerId field instead, this should give you the Id you need straight. Lastly, you should not be using DML in a loop, you should bulk the the DML operation by adding the records to a list outside then call the insert call to the database. Try this:
Hi,
I am providing an running example
Change Contact with your Object.
This worked like a CHARM. I am very new to Salesforce and would like to learn more about how to code triggers ect. Is there a good resource that you know of?