You need to sign in to do that
Don't have an account?
RAJNag
Update field value
Hi
i wrote the trigger my task is whenever Asset price field changes then update the same value in product object custom field New_Price_Value__c
trigger updateContactDesriptionWithAccount on Product2(after insert,after update){
set<id> conids=new set<id>();
for(Product2 con:trigger.new){
conids.add(con.id);
}
list<Product2> conlst=[select id,New_Price_Value__c,(select Price from Assets) from Product2 where id in:conids];
for(Product2 c:conlst){
New_Price_Value__c = c.Asset.Price ;
}
update conlst;
}
trigger updateContactDesriptionWithAccount on Product2(after insert,after update){
set<id> conids=new set<id>();
for(Product2 con:trigger.new){
conids.add(con.id);
}
list<Product2> conlst=[select id,nagaraju__New_Price_Value__c,(select Price from Assets) from Product2 where id in:conids];
for(Product2 c:conlst){
c.trigger updateContactDesriptionWithAccount on Product2(after insert,after update){
set<id> conids=new set<id>();
for(Product2 con:trigger.new){
conids.add(con.id);
}
list<Product2> conlst=[select id,nagaraju__New_Price_Value__c,(select Price from Assets) from Product2 where id in:conids];
for(Product2 c:conlst){
c.nagaraju__New_Price_Value__c = c.Asset.Price ;
}
update conlst;
}= c.Asset.Price ;
}
update conlst;
}
but i got the error like this *Error: Compile Error: Invalid foreign key relationship: Product2.Asset at line 15 column 40
Plz Can any one help me
i wrote the trigger my task is whenever Asset price field changes then update the same value in product object custom field New_Price_Value__c
trigger updateContactDesriptionWithAccount on Product2(after insert,after update){
set<id> conids=new set<id>();
for(Product2 con:trigger.new){
conids.add(con.id);
}
list<Product2> conlst=[select id,New_Price_Value__c,(select Price from Assets) from Product2 where id in:conids];
for(Product2 c:conlst){
New_Price_Value__c = c.Asset.Price ;
}
update conlst;
}
trigger updateContactDesriptionWithAccount on Product2(after insert,after update){
set<id> conids=new set<id>();
for(Product2 con:trigger.new){
conids.add(con.id);
}
list<Product2> conlst=[select id,nagaraju__New_Price_Value__c,(select Price from Assets) from Product2 where id in:conids];
for(Product2 c:conlst){
c.trigger updateContactDesriptionWithAccount on Product2(after insert,after update){
set<id> conids=new set<id>();
for(Product2 con:trigger.new){
conids.add(con.id);
}
list<Product2> conlst=[select id,nagaraju__New_Price_Value__c,(select Price from Assets) from Product2 where id in:conids];
for(Product2 c:conlst){
c.nagaraju__New_Price_Value__c = c.Asset.Price ;
}
update conlst;
}= c.Asset.Price ;
}
update conlst;
}
but i got the error like this *Error: Compile Error: Invalid foreign key relationship: Product2.Asset at line 15 column 40
Plz Can any one help me
Please try below code and make sure which asset price you want to populate over product field as there can be many assets for one product.
Let us know if it helps you.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger nagaraju.updateContactDesriptionWithAccount1 caused an unexpected exception, contact your administrator: nagaraju.updateContactDesriptionWithAccount1: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 01t280000006BJHAA2; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, nagaraju.updateContactDesriptionWithAccount1: maximum trigger depth exceeded Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH]: []: Trigger.nagaraju.updateContactDesriptionWithAccount1: line 21, column 1
trigger updateContactDesriptionWithAccount1 on Product2(after insert,after update){
set<id> conids=new set<id>();
for(Product2 con:trigger.new){
conids.add(con.id);
}
list<Product2> conlst=[select id,nagaraju__New_Price_Value__c,(select Price from Assets) from Product2 where id in:conids];
List<Product2> conlstToUpdate = new List<Product2> ();
for(Product2 c:conlst)
{
for(Asset a:c.Assets)
{
c.nagaraju__New_Price_Value__c = a.Price ;
}
conlstToUpdate.add(c);
}
//update conlst;
update conlstToUpdate;
}
Error is
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger nagaraju.updateContactDesriptionWithAccount1 caused an unexpected exception, contact your administrator: nagaraju.updateContactDesriptionWithAccount1: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 01t280000006BJHAA2; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, nagaraju.updateContactDesriptionWithAccount1: maximum trigger depth exceeded Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH] Product2 trigger event AfterUpdate for [01t280000006BJH]: []: Trigger.nagaraju.updateContactDesriptionWithAccount1: line 24, column 1