Please try with below trigger and let me know furhter :
trigger ConvertAccountRatingToHot on Account (after insert, after update) {
// List to hold Account records to be updated
List<Account> acctsToUpdate = new List<Account>();
// Iterate through all Accounts in trigger context
for(Account a : Trigger.new){
// Query for all Opportunities related to the Account
List<Opportunity> opps = [SELECT Id, IsClosed, AccountId FROM Opportunity WHERE AccountId = :a.Id];
// Count the total number of Opportunities and closed won Opportunities
Integer totalOpps = opps.size();
Integer wonOpps = 0;
for(Opportunity o : opps){
if(o.IsClosed && o.StageName == 'Closed Won'){
wonOpps++;
}
}
// Check if the Account meets the criteria to update the rating
if(totalOpps > 10 && wonOpps >= totalOpps/2){
// Update the Account Rating to "Hot"
a.Rating = 'Hot';
acctsToUpdate.add(a);
}
}
// Update all Accounts that meet the criteria
update acctsToUpdate;
}
Please try with below trigger and let me know furhter :
trigger ConvertAccountRatingToHot on Account (after insert, after update) {
// List to hold Account records to be updated
List<Account> acctsToUpdate = new List<Account>();
// Iterate through all Accounts in trigger context
for(Account a : Trigger.new){
// Query for all Opportunities related to the Account
List<Opportunity> opps = [SELECT Id, IsClosed, AccountId FROM Opportunity WHERE AccountId = :a.Id];
// Count the total number of Opportunities and closed won Opportunities
Integer totalOpps = opps.size();
Integer wonOpps = 0;
for(Opportunity o : opps){
if(o.IsClosed && o.StageName == 'Closed Won'){
wonOpps++;
}
}
// Check if the Account meets the criteria to update the rating
if(totalOpps > 10 && wonOpps >= totalOpps/2){
// Update the Account Rating to "Hot"
a.Rating = 'Hot';
acctsToUpdate.add(a);
}
}
// Update all Accounts that meet the criteria
update acctsToUpdate;
}
Please try with below trigger and let me know furhter :
Hope the above information helps !
Thank you.
All Answers
Please try with below trigger and let me know furhter :
Hope the above information helps !
Thank you.
Try below Code :
Hope this will help.
Thanks!