You need to sign in to do that
Don't have an account?
farah sherif
hello guys the below trigger is not working can anyone help
this is the requirment:
When Cancellation_Received_Date__c is populated on an AssetRecord,
Copy Actual_Cancellation_Date__c from the Asset Object
To Actual_Cancellation_Date__c on the OpportunityLineItem Object
Use Opportunity_Product_ID__c on the Asset Object to determine which Opportunityline item to update
trigger CopyDateTrigger on Asset (after update, after delete) {
map<id,date> toupdate = new map<id,date>();
map<id,id> toupdate2 = new map<id,id>();
map<Asset,id> toupdate3 = new map<Asset,id>();
//set<id> opp = new set<id>();
for(Asset a:trigger.new){
if(a.Cancellation_Received_Date__c != null){
toupdate.put(a.Opportunity_Product_ID__c,a.Actual_Cancellation_Date__c);
toupdate2.put(a.Opportunity__c,a.Opportunity_Product_ID__c);
toupdate3.put(a,a.Opportunity_Product_ID__c);
}
}
if(!toupdate.isEmpty() ){
List<OpportunityLineItem> o = [select Casesafeid__c,Actual_Cancellation_Date__c from OpportunityLineItem where Casesafeid__c in:toupdate.keySet()];
for(OpportunityLineItem opp:o){
for(Asset ast:toupdate3.keySet()){
if(ast.Opportunity_Product_ID__c == opp.Casesafeid__c){
opp.Actual_Cancellation_Date__c =ast.Actual_Cancellation_Date__c;
}
}
}
}
}
When Cancellation_Received_Date__c is populated on an AssetRecord,
Copy Actual_Cancellation_Date__c from the Asset Object
To Actual_Cancellation_Date__c on the OpportunityLineItem Object
Use Opportunity_Product_ID__c on the Asset Object to determine which Opportunityline item to update
trigger CopyDateTrigger on Asset (after update, after delete) {
map<id,date> toupdate = new map<id,date>();
map<id,id> toupdate2 = new map<id,id>();
map<Asset,id> toupdate3 = new map<Asset,id>();
//set<id> opp = new set<id>();
for(Asset a:trigger.new){
if(a.Cancellation_Received_Date__c != null){
toupdate.put(a.Opportunity_Product_ID__c,a.Actual_Cancellation_Date__c);
toupdate2.put(a.Opportunity__c,a.Opportunity_Product_ID__c);
toupdate3.put(a,a.Opportunity_Product_ID__c);
}
}
if(!toupdate.isEmpty() ){
List<OpportunityLineItem> o = [select Casesafeid__c,Actual_Cancellation_Date__c from OpportunityLineItem where Casesafeid__c in:toupdate.keySet()];
for(OpportunityLineItem opp:o){
for(Asset ast:toupdate3.keySet()){
if(ast.Opportunity_Product_ID__c == opp.Casesafeid__c){
opp.Actual_Cancellation_Date__c =ast.Actual_Cancellation_Date__c;
}
}
}
}
}
All Answers