You need to sign in to do that
Don't have an account?
Zabi noor
Rollup the USA contact count on the Account field and add to list<contact>
rigger ContactTrigger on Contact (after insert, after update, after delete, after undelete) {
//insert --> trigger.new
//update --> trigger.new
//delete --> trigger.old
//undelete --> trigger.new
Set<Id> accIds = new Set<Id>();
for(Contact con : trigger.isDelete ? trigger.old : trigger.new) {
accIds.add(con.AccountId);
}
Map<Id,Integer> accIdConCountMap = new Map<Id,Integer>();
Map<Id,List<Contact>> accIdConLstMap = new Map<Id,List<Contact>>();
for(Contact con : [SELECT Id FROM Contact WHERE AccountId in: accIds AND MailingCountry = 'USA']) {
}
}
//insert --> trigger.new
//update --> trigger.new
//delete --> trigger.old
//undelete --> trigger.new
Set<Id> accIds = new Set<Id>();
for(Contact con : trigger.isDelete ? trigger.old : trigger.new) {
accIds.add(con.AccountId);
}
Map<Id,Integer> accIdConCountMap = new Map<Id,Integer>();
Map<Id,List<Contact>> accIdConLstMap = new Map<Id,List<Contact>>();
for(Contact con : [SELECT Id FROM Contact WHERE AccountId in: accIds AND MailingCountry = 'USA']) {
}
}
Posting here a sample code. This will add the contact's Custom field and shows Total on Accounts
NOTE: The code provided is an example. You'll need to review and make modifications for your organization.
Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you