You need to sign in to do that
Don't have an account?
Help for trigger
Hi All,
Appreciate if you could help me correct this trigger
When a custom field(Is_Serviceable__c) on the custom object (Product_Master__c) is true, then create or update the fields on Asset by the fields of custom object(Contract_Product__c).
trigger UpdateAsset on Product_Master__c (after insert, after update) {
//List Asset to insert, update
List<Asset> insertASList = new List<Asset>();
List<Asset> updateASList = new List<Asset>();
for(Product_Master__c pm:trigger.new){
for(Contract_Product__c cp:trigger.new){
//check for the checkbox
if(trigger.isinsert && trigger.isafter && pm.Is_Serviceable__c==true){
cp.add(new Contract_Product__c(Contract_Start_Date__c=AS.Contract_Start_Date__c, Contract_End_Date__c=AS.Contract_End_Date__c));
}
//check for the checkbox update on Product_Master__c
if(trigger.isupdate && trigger.isafter && pm.Is_Serviceable__c==true){
cp.add(new Contract_Product__c(Contract_Start_Date__c=AS.Contract_Start_Date__c, Contract_End_Date__c=AS.Contract_End_Date__c));
}
}
}
insert insertASList;
update updateASList;
}
}
Hi Munna
A couple of pointers.
You can't use the trigger.new method to access Contract_Product__c information directly, as the trigger is firing on the Product Master object. You will need to run a soql query to return this related information.
Your asset lists that are declared, are not used in your processing. so you are trying to insert null objects with your DML statements. in your 'for' loops, you are trying to access varaible AS, which has not been declared.
Try writing your trigger using the following process.
Hope this information helps. Good luck!
Thanks a ton for ur reply, actually i'm very new to write any code... can you please correct the trigger code here that would be very helpful.. Thanks again.
When a custom lookup field on opportunity(Contract__c) is updated then some fields from Contract standard object should autofill the fields on opportunity.
Please help me with these two triggers... I would be really grateful to you...
When a custom field(Is_Serviceable__c) on the custom object (Product_Master__c) is true, then create or update the fields on Asset by the fields of custom object(Contract_Product__c).
trigger UpdateAsset on Product_Master__c (after insert, after update) {
//List Asset to insert, update
List<Asset> insertASList = new List<Asset>();
List<Asset> updateASList = new List<Asset>();
for(Product_Master__c pm:trigger.new){
for(Contract_Product__c cp:trigger.new){
//check for the checkbox
if(trigger.isinsert && trigger.isafter && pm.Is_Serviceable__c==true){
cp.add(new Contract_Product__c(Contract_Start_Date__c=AS.Contract_Start_Date__c, Contract_End_Date__c=AS.Contract_End_Date__c));
}
//check for the checkbox update on Product_Master__c
if(trigger.isupdate && trigger.isafter && pm.Is_Serviceable__c==true){
cp.add(new Contract_Product__c(Contract_Start_Date__c=AS.Contract_Start_Date__c, Contract_End_Date__c=AS.Contract_End_Date__c));
}
}
}
insert insertASList;
update updateASList;
}
}
You are trying to access Contract_Start_Date__c using AS variable but you haven't declared that.
You did not add any Asset to insertAsList or updateAslist.
Can you be liittle more clear with what is contrat_product__c and Asset object ?
I gave some sample field names...
Actually my trigger should be on Product_Master__c object, when a checkbox field updates on Product_Master__c (ie., Is_Serviceable=true) then a Asset is created or updated with contract_Product__c fields.
Contract_Product__c is a object, line item to contract object. Product_Master__c is lookup to Contract_Product__c.
Thank you for the reply... please help me with the trigger...