You need to sign in to do that
Don't have an account?
Maxa
Deleting related records in a trigger
HI,
Is there a way i cna delete existing related records under opporttunity such as product, when some oportunity fied changes? how would go about it? any sample code would be gretly apreciated
you can do this in a before/after update opportunity trigger
trigger tstopp on Opportunity(before update)
{
set<id> setoppIds = Trigger.newmap.keySet();
//now query the opportunity related records
//ex. for Products
list<OpportunityLineItem> lstLineItems = [select Id from OpportunityLineItem where OpportunityId in:setoppIds];
if(lstLineItems.size() > 0)
delete lstLineItems;
}
Regards,
Shravan
All Answers
you can do this in a before/after update opportunity trigger
trigger tstopp on Opportunity(before update)
{
set<id> setoppIds = Trigger.newmap.keySet();
//now query the opportunity related records
//ex. for Products
list<OpportunityLineItem> lstLineItems = [select Id from OpportunityLineItem where OpportunityId in:setoppIds];
if(lstLineItems.size() > 0)
delete lstLineItems;
}
Regards,
Shravan
this si great, all worked perfectly
thank you
SELF_REFERENCE_FROM_TRIGGER, Object (id = 0062800000AlUGv) is currently in trigger addProductonPriceBookChange, therefore it cannot recursively update itself: []: Trigger.addProductonPriceBookChange: line 44, column 1