You need to sign in to do that
Don't have an account?
Prakhyat sapra
Create the opportunity whose state is closewon & account is !null then update closedate__c on account as todat date by trigger handler
Create the opportunity whose state is closewon & account is !null then update closedate__c on account as todat date by trigger handler ??
Can you specify your requirement more clearly. Does user created opportunity manully or do we need some automation for this. if any opportunity is created with closed won then update the account closeddate to todays date. Is this your requirement.
Is it only for create scenerio or for update as well?
Thanks,
Kindly refer to the below code ->
// Trigger =>
trigger OpportunityTrigger on Opportunity(after Insert) {
if(Trigger.isAfter){
if(Trigger.isInsert){
OpportunityTriggerHandler.afterInsert(Trigger.new);
}
}
}
// Handler Class =>
public class OpportunityTriggerHandler {
public static void afterInsert(List<Opportunity> oppList){
Set<Id> oppIdSet = new Set<Id>();
for(Opportunity o : oppList){
oppIdSet.add(o.AccountId);
}
List<Account> accList = [SELECT Id, Name, Close_Date__c FROM Account WHERE Id IN : oppIdSet];
List<Account> aList = new List<Account>();
for(Opportunity o : oppList){
for(Account acc : accList){
if(o.StageName == 'Closed Won'){
acc.Close_Date__c = System.today();
aList.add(acc);
// System.debug(aList);
}
}
}
update aList;
}
}
If this solves your problem, kindly mark it as the best answer.
Regards,
Harshit Kumar