function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
farah sheriffarah sherif 

guys i need help with the trigger below please

this is supposed to be the function of the trigger:
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

I wrote the below trigger but I can't write the part where is copies the actual cancellation




trigger CopyDateTrigger on Asset (after update, after delete) {

    map<id,date> toupdate = new map<id,date>();
    
    for(Asset a:trigger.new){
        
        if(a.Actual_Cancellation_Date__c != null){
            toupdate.put(a.Opportunity_Product_ID__c,a.Actual_Cancellation_Date__c);

        }
    }
    if(!toupdate.isEmpty() ){
        for(Id i:toupdate.keySet()){
        
        }
    }
}
Best Answer chosen by farah sherif
Raj VakatiRaj Vakati
Try this
 
trigger CopyDateTrigger on Asset (after update, after delete) {

    map<id,date> toupdate = new map<id,date>();
    
	Map<Id ,Date> oppLines = new Map<Id ,Date >() ;
	
    for(Asset a:trigger.new){
        
        if(a.Actual_Cancellation_Date__c != null){
          //  toupdate.put(a.Opportunity_Product_ID__c,a.Actual_Cancellation_Date__c);
oppLines.put(a.Opportunity_Product_ID__c ,a.Actual_Cancellation_Date__c);
        }
    }
    if(!oppLines.isEmpty() ){
List<OpportunitylineItem> opplines =[select id from  OpportunitylineItem where Id In : oppLines.keySet()];

for(     OpportunitylineItem o : opplines){
	o.Actual_Cancellation_Date__c = oppLines.get(o.Id);
}
update oppLines ;

	   }
}