fork download
  1.  
  2. trigger ContactsCount On Contacts(after insert,after update,after delete,after undelete){
  3.  
  4. set<id>parentIds=new Set<id>();
  5. if(trigger.isafter&&(trigger.isinsert||trigger.isdelete)){
  6.  
  7. if(!trigger.new.isempty){
  8.  
  9. For(Contact con:trigger.new){
  10.  
  11. if(con.AccountId!=NULL){
  12.  
  13. parentIds.add(con.AccountId);
  14.  
  15. }
  16.  
  17. }
  18.  
  19. }
  20. }
  21. if(trigger.isafter&&trigger.isupdate){
  22.  
  23. if(!trigger.new.isempty){
  24. }
  25. For(Contact con:trigger.new){
  26.  
  27. If(Con.AccountId!=NULL){
  28.  
  29. If(con.AccountId!=NULL&&trigger.oldmap.get(con.AccountId)){
  30.  
  31. if(trigger.oldmap.get!=con.id).AccountId{
  32.  
  33. parentIds.add(Con.AccountId)
  34.  
  35. }
  36.  
  37. }
  38.  
  39. }
  40.  
  41. }
  42. }
  43.  
  44. If(trigger.isafter&&trigger.isdelete){
  45.  
  46. If(!trigger.old.isempty){
  47.  
  48. For(Contact con:trigger.old){
  49.  
  50. if(con.AccountId!=NULL){
  51.  
  52. parentIds.add(con.AccountId);
  53.  
  54. }
  55. }
  56. }
  57.  
  58. }
  59.  
  60. List<Account>lstAccounts=[select id,contact_count__c(select id from Contacts) from Account
  61. where Id IN:parentIds];
  62. List<Account>listToBeUpdate=new List<Account>();
  63.  
  64. if(!lstAccounts.isempty){
  65.  
  66. For(Account acc:lstAccounts){
  67.  
  68. acc.contact_count__c=acc.contacts.size();
  69. listToBeUpdate.add(acc);
  70. }
  71.  
  72. }
  73.  
  74. if(!listToBeUpdate.isempty){
  75.  
  76. update listToBeUpdate;
  77. }
  78. }
  79.  
Success #stdin #stdout #stderr 0.02s 12636KB
stdin
Standard input is empty
stdout
Object: nil error: did not understand #ContactsCount
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #ContactsCount (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:2)
Object: nil error: did not understand #insert
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #insert (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:2)
Object: nil error: did not understand #associationAt:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:114)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:7)
Object: nil error: did not understand #associationAt:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:114)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:23)
Object: nil error: did not understand #associationAt:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:114)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:46)
Object: nil error: did not understand #associationAt:ifAbsent:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt:ifAbsent: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:115)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:64)
Object: nil error: did not understand #associationAt:ifAbsent:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt:ifAbsent: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:115)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:74)
stderr
./prog:4: expected expression
./prog:7: expected expression
./prog:11: expected expression
./prog:23: expected expression
./prog:27: expected expression
./prog:29: expected expression
./prog:31: expected expression
./prog:46: expected expression
./prog:50: expected expression
./prog:64: expected expression
./prog:74: expected expression