You need to sign in to do that
Don't have an account?
Developement
Please Help with this trigger
trigger ContactS on Contact (after delete, after insert)
{
Contact[] con;
con = Trigger.new;
Set<ID> acctIds = new Set<ID>();
Map<ID, Account> Update = new Map<ID, Account>([select Id,Count__c from Account where Id in :acctIds]);
for (Account acct : acctsToUpdate.values()) {
Set<ID> conIds = new Set<ID>();
if (acct.Count__c != conIds.size())
acct.Count__c = conIds.size();
}
update acctUpdate.values();
}
Thanks.
On which fields of Account you want to populate Billing Contact Name, email and Phone number.If you can give me the fields ,I can then help you out.
Bname_c
Bphone_c
Bemail_c
Thanks
Bname_c
Bphone_c
Bemail_c
Why are you using a trigger? I would add a rollup summary field on the Account object. The roll up type would be "count" for records matching criterium Field/Operator/Value: "CW_Contact_Type__c" "contains" "Billing"
You already have 10 rollup summaries on Account? Have you considered building a dashboard that accesses summary reports?
i have tried all possible ways to update field on account page.So lastly i was left with no choice and only to use triggers.
Hi,
Try below :-
trigger ContactSumTrigger on Contact (after delete, after insert, after undelete,after update)
{
Contact[] cons;
if (Trigger.isDelete)
cons = Trigger.old;
else
cons = Trigger.new;
Set<ID> acctIds = new Set<ID>();
for (Contact con : cons) {
acctIds.add(con.AccountId);
}
Map<ID, Contact> contactsForAccounts = new Map<ID, Contact>([select Id,AccountId,name,phone,email from Contact where AccountId in:acctIds and CW_Contact_Type__c like '%Billing%']);
Map<ID, Account> acctsToUpdate = new Map<ID, Account>([select Id,Count__c from Account where Id in :acctIds]);
for (Account acct : acctsToUpdate.values()) {
Set<ID> conIds = new Set<ID>();
for (Contact con : contactsForAccounts.values()) {
acct.Bname_c = contactsForAccounts.get(con.AccountId).Name;
acct.Bphone_c = contactsForAccounts.get(con.AccountId).phone;
acct.Bemail_c = contactsForAccounts.get(con.AccountId).email;
if (con.AccountId == acct.Id){
conIds.add(con.Id);
}
if (acct.Count__c != conIds.size()){
acct.Count__c = conIds.size();
}
}
}
update acctsToUpdate.values();
}