+ Start a Discussion
Ben MertonBen Merton 

Trigger for calculating number of records in a related list

I am attempting to use some code from this blog:  https://rakeshistom.wordpress.com/tag/count-records-in-a-related-list/

The first piece of code is giving me a problem on line 4.  It is saying 'expecting right parentheses, found 'c''?  Any ideas?
 
trigger MANUALPROCEDURE on Manual_Procedure_Revisions__c (after insert, after update, after delete, after undelete) 
{
  Map<Id,Manuals_and_Procedures__c> MANUALPROCEDURE = new Map<Id,Manuals_and_Procedures__c>();
  if(Trigger.new <> nullfor (Manual_Procedure_Revisions__c c : Trigger.new)
      if(Manual_Procedure__c<>null)
        MANUALPROCEDURE.put(c.Manual_Procedure__c,new Manuals_and_Procedures__c(id=c.Manuals_and_Procedures__c));
  if(Trigger.old<>nullfor(Manual_Procedure_Revisions__c c : Trigger.old)
      if(c.Manual_Procedure__c<>null)      
        MANUALPROCEDURE.put(c.Manual_Procedure__c,new Manuals_and_Procedures__c(id=c.Manual_Procedure__c));
  update MANUALPROCEDURE.values();
}

 
Abhishek BansalAbhishek Bansal
Hi,

Please replace your code with below code :
 
trigger MANUALPROCEDURE on Manual_Procedure_Revisions__c (after insert, after update, after delete, after undelete) 
{
	Map<Id,Manuals_and_Procedures__c> MANUALPROCEDURE = new Map<Id,Manuals_and_Procedures__c>();
	if(Trigger.new != null) {
	for(Manual_Procedure_Revisions__c c : Trigger.new) {
		if(Manual_Procedure__c != null)
			MANUALPROCEDURE.put(c.Manual_Procedure__c,new Manuals_and_Procedures__c(id=c.Manuals_and_Procedures__c));
		}
	}
	if(Trigger.old != null){
		for(Manual_Procedure_Revisions__c c : Trigger.old) {
			if(c.Manual_Procedure__c != null)      
				MANUALPROCEDURE.put(c.Manual_Procedure__c,new Manuals_and_Procedures__c(id=c.Manual_Procedure__c));
		}
	}
	update MANUALPROCEDURE.values();
}
Let me know if you need more help.

Regards,
Abhishek