You need to sign in to do that
Don't have an account?
Urgent Help Needed!! Help copying fields to a custom object via trigger (code provided)
I created a custom object called Impressions. Every time a Opportunity Product is created with a Product Family = Impressions I would like copy some fields from this Opportunity Product and insert them into a new row on the Impressions object.
For example if I add an Impression Product to an Opportunity with the Quantity of 50 and a Date of 6/1/2013, I would like a new row to be created in the Impressions object with ID = 1 (Autonumber), Quantity = 50, and Date = 6/1/2013.
Here is the code that I have. It is not triggering any errors. I have placed the trigger in the Opportunit Product triggers, and it is active; however, when I create a new object to see if it works, it does not. Can anyone offer any assistance?? I think the code is OK, but maybe I'm missing something?? Your help is EXTREMELY appreicated!
trigger createImpression on OpportunityLineItem (after insert) { List <Impressions__c> impToInsert = new List <Impressions__c> (); for (OpportunityLineItem o : Trigger.new) { // Check if Opportunity Product Meets my criteria if (o.Product_Family__c == 'Impression') { Impressions__c i = new Impressions__c (); //Instantiating new object to put values for future record // Mapping Opportunity Product fields to new Impressions object i.Bill_Date__c = o.ServiceDate; i.Expected_Impressions__c = o.Quantity; i.Predicted_Revenue__c = o.TotalPrice; //Adding new object to list that will be inserted. impToInsert.add(i); } } //Loop has finished; Inserting new records in SF try { insert impToInsert; } catch (system.Dmlexception e) { system.debug (e); } }
Thank you!
hi
try this i add one line
i.OpportunityLineItem =o.id;
trigger createImpression on OpportunityLineItem (after insert) {
List <Impressions__c> impToInsert = new List <Impressions__c> ();
for (OpportunityLineItem o : Trigger.new) {
// Check if Opportunity Product Meets my criteria
if (o.Product_Family__c == 'Impression') {
Impressions__c i = new Impressions__c (); //Instantiating new object to put values for future record
// Mapping Opportunity Product fields to new Impressions object
i.Bill_Date__c = o.ServiceDate;
i.Expected_Impressions__c = o.Quantity;
i.Predicted_Revenue__c = o.TotalPrice;
i.OpportunityLineItem =o.id;
//Adding new object to list that will be inserted.
impToInsert.add(i);
}
}
Thanks
arjun
Please Mark this as solution (if it was helpful) to make it available to others for similar problem & Don't forget to give me KUDOS by Clicking on STAR icon