Another Salesforce blog!!!

Salesforce, Apex

Trigger event


trigger changeForecastCategory on Opportunity (after update) {

	// Create empty opportunity list
	List<Opportunity> oppsToUpdate = new List<Opportunity>();
	
	//Create empty set
	Set<Id> oppIds = new Set<Id>();
	
	// Interate selected opp records
	for (Opportunity opp : Trigger.new){
		oppIds.add(opp.id);
		
	}
    
    // Fetch selected records
    List<Opportunity> opportunityList = [select Id, OwnerId, ForecastCategoryName, CA__Forecast__c, CA__Debug_MassUpdate__c from Opportunity where Id in:oppIds];

	for (Opportunity opportunityRecord:opportunityList){
		
		opportunityRecord.CA__Debug_MassUpdate__c = 'Test';
		oppsToUpdate.add(opportunityRecord);
		
	}
	
	if (!oppsToUpdate.isEmpty()){
	update oppsToUpdate;
	} 
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*