function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger opplineCount on Contact ( after insert, after update,after delete,after undelete) { Set<Id> accountIdSet=new Set<Id>(); List<Account> accListToUpdate=new List<Account>(); if(Trigger.isInsert || Trigger.isUpdate || Trigger.isUndelete){ for(Contact con : Trigger.new){ if(con.AccountId != null) accountIdSet.add(con.AccountId); } }If(Trigger.isDelete){ for(Contact con: Trigger.old){ if(con.AccountId != null) accountIdSet.add(con.AccountId); } } for(AggregateResult res : [SELECT count(Id)can,AccountId FROM Contact WHERE AccountId IN :accountIdSet group by AccountId]) { accListToUpdate.add(new Opportunity(Id=(Id)res.get('AccountId'),Contact_Count__c=(Integer)res.get('can'))); } try{ update accListToUpdate; }catch(DmlException de){ System.debug(de); } }
trigger countContact on Contact(after insert,after update,after delete) { set<Id> accontIds = new set<Id>{}; list<Account> projIds = new list<Account>(); if(trigger.isInsert || trigger.isUpdate) { for(Contact p:trigger.new) accontIds.add(p.accountId); } if(trigger.isDelete) { for(Contact p:trigger.old) accontIds.add(p.accountID); } AggregateResult[] groupedResults = [select accountid,count(id) countt from Contact where accountid in :accontIds group by accountid]; for (AggregateResult ar : groupedResults) projIds.add(new Account(id=(ID)ar.get('accountid'),Count__c = (Integer)ar.get('countt'))); update projIds; }
Try with bewo code .
Try the following code, it will be working insert and delete the contact.
How can we do the same task using the Apex class and display the Name of the Account and the Number of Contacts in the VF Page.
Could anyone help me on this .... at your earliest possible.
Regards,
Nagaraju Mogili