You need to sign in to do that
Don't have an account?

Need Help: Trigger to update opportunity Product when field on custom object is updated
Hey Guys,
I have an OPPORTUNITY LINE ITEM object. On this, I have a lookup field to SCHEDULE_HEADER__c object. Name of look up field on Opportunity line item is SCHEDULE_HEADER__c. we have one field on schedule_header__c object called SCH_ACTUAL_UNITS__C. we want whatever value is present in sch_actual_units__c, it should be copied to TOTALPRICE field on opportunity line item object. I have written a code , But i am getting this error. Please help.
Compile Error: Invalid foreign key relationship: Schedule_Header__c.OpportunityLineItem__c at line 9 column 23
trigger OppStatus on Schedule_Header__c (after insert, after update) {
List<ID> schID = New List<ID> ();
for(Schedule_Header__c sch : Trigger.new){
if(sch.Sch_Actuals_Total__c != NULL){
schID.add(sch.OpportunityLineItem__c.Id);
}
}
List<OpportunityLineItem> OppLineUpdateList = [SELECT Id,TotalPrice FROM OpportunityLineItem WHERE id in: schID];
for(integer i = 0; i < OppLineUpdateList.size(); i++){
OppLineUpdateList[i].TotalPrice = schID;
}
update OppLineUpdateList;
}
In that case you have made wrong trigger.
Try to use following trigger code.
Apex Trigger:
All Answers
Hi,
Try to use following trigger. you have made small mistake at Line No. 9.
Apex Trigger:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/
Hi Hitesh,
i am getting this error
Error: Compile Error: Invalid field OpportunityLineItem__c for SObject Schedule_Header__c at line 5 column 23
what is the API name of OpportunityLineitem Lookup field in Schedule_Header__c object?
Look up field in on opportunityLineItem and Its's looking up to Schedule_Header__c object. API name of look up field on OpportunityLineItem object is Schedule_Header__c
In that case you have made wrong trigger.
Try to use following trigger code.
Apex Trigger:
Hitesh,
It worked. Thanks for your pat reply and correcting the code. I really appreciate this.
Thanks
Hi Hitesh,
I just realized that It is not updating the totalprice value. FYI, TotalPrice is a standard field on OpportunityLine Item. Trigger is not giving any error but it is also not workong. Can you please help ?
Regards
Try to use following trigger code.
Apex Trigger:
Hi Hitesh,
Thanks for your reply. It is still not updating .
Try to use below trigger code.