function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LorrMcLorrMc 

Compile Error: Unexpected token 'public'. at line 10 column 3

Hi,

I have been given great help on here earlier today regarding this tirgger however we have hit a wall and I cant seem to get past this error, please see code below any help appriciated. 
trigger TriggeronCarePlan on Care_Plan_Details__c (before insert, before update) {
    
    TriggerCarePlanHandler handler =  new TriggerCarePlanHandler();
    
   if(trigger.isUpdate || trigger.isInsert)
   {
       handler.UpdateActivestatus(Trigger.new);
       
              
  public void TriggerCarePlanHandler {
    
    set<id> allContactIDs = new set<id>();
    List<Care_Plan_Details__c> allrelatedCarePlans = new List<Care_Plan_Details__c>();
    List<Care_Plan_Details__c> updateRecords = new List<Care_Plan_Details__c>();
    
  public class UpdateActivestatus (List<Care_Plan_Details__c> Triggernew)
    {        
        for (Care_Plan_Details__c var : Triggernew)
        {
            allContactIDs.add(var.ContactID );
        }  
           (Care_Plan_Details__c var : Triggernew) { system.debug('care pla details'+' '+ var); // see what are all the details are being populated for contact. //allContactIDs.add(var.ContactID ); }
    
       allrelatedCarePlans = [select id, Active_Inactive__c,ContactID from Care_Plan_Details__c where ContactID in:allContactIDs ];
     
       
       for (Care_Plan_Details__c var : allrelatedCarePlans) 
           {
                   Care_Plan_Details__c record = new Care_Plan_Details__c();
                    record.Id = var.id;
                    Record.Active_Inactive__c = false;
               updateRecords.add(record);               
           }
        
        if (!updateRecords.isEmpty())
        { 
            update updateRecords;
        }
    }
}
 
Thank You
Jayant DasJayant Das
Few notes here:
1. As a best practice, you should seggregate your trigger and apex class logic, i.e., invoke the class from trigger and have the class written in a separate file
2. In your case, the error is on the declaration of the class  public void TriggerCarePlanHandler {, it should be instead
public class TriggerCarePlanHandler {
Waqar Hussain SFWaqar Hussain SF
try below code
 
public class TriggerCarePlanHandler {
    
    set<id> allContactIDs = new set<id>();
    List<Care_Plan_Details__c> allrelatedCarePlans = new List<Care_Plan_Details__c>();
    List<Care_Plan_Details__c> updateRecords = new List<Care_Plan_Details__c>();
    
  public UpdateActivestatus (List<Care_Plan_Details__c> Triggernew)
    {        
        for (Care_Plan_Details__c var : Triggernew)
        {
            allContactIDs.add(var.ContactID );
        }  
           (Care_Plan_Details__c var : Triggernew) { system.debug('care pla details'+' '+ var); // see what are all the details are being populated for contact. //allContactIDs.add(var.ContactID ); }
    
       allrelatedCarePlans = [select id, Active_Inactive__c,ContactID from Care_Plan_Details__c where ContactID in:allContactIDs ];
     
       
       for (Care_Plan_Details__c var : allrelatedCarePlans) 
           {
                   Care_Plan_Details__c record = new Care_Plan_Details__c();
                    record.Id = var.id;
                    Record.Active_Inactive__c = false;
               updateRecords.add(record);               
           }
        
        if (!updateRecords.isEmpty())
        { 
            update updateRecords;
        }
    }
}

 
LorrMcLorrMc
Thank You, 
I am really new to this and to be honest not really sure how to split them or link together, I have made the changes you mentioned however I am still getting the same error. 
I must be doing somthing wrong. 
Maharajan CMaharajan C
Hi LorrMc,

Your Trigger should be like below;

trigger TriggeronCarePlan on Care_Plan_Details__c (before insert, before update) {
    
    TriggerCarePlanHandler handler =  new TriggerCarePlanHandler();
    List<Care_Plan_Details__c> CarPlanlst = new List<Care_Plan_Details__c>();
    
   if(trigger.isUpdate || trigger.isInsert)
   {
       for(Care_Plan_Details__c cp : Trigger.new)
       {
          CarPlanlst.add(cp);
       }       
   }
   If(CarPlanlst.size() > 0)
   {
          handler.UpdateActivestatus(CarPlanlst);
   }
}


And Apex Class should be like below: (Create the Seperate Apex Class Setup --> Apex Class)

public class TriggerCarePlanHandler {
    
    set<id> allContactIDs = new set<id>();
    List<Care_Plan_Details__c> allrelatedCarePlans = new List<Care_Plan_Details__c>();
    List<Care_Plan_Details__c> updateRecords = new List<Care_Plan_Details__c>();
    
  public static void UpdateActivestatus (List<Care_Plan_Details__c> Triggernew)
    {        
        for (Care_Plan_Details__c var : Triggernew)
        {
            allContactIDs.add(var.ContactID );
        }  
        
        if(allContactIDs.size() > 0)
        {
        allrelatedCarePlans = [select id, Active_Inactive__c,ContactID from Care_Plan_Details__c where ContactID IN: allContactIDs ];
        }
       
       If(allrelatedCarePlans.size() > 0)
       {
       for (Care_Plan_Details__c var : allrelatedCarePlans) 
           {
                   Care_Plan_Details__c record = new Care_Plan_Details__c();
                    record.Id = var.id;
                    Record.Active_Inactive__c = false;
               updateRecords.add(record);               
           }
       }   
        
        if (!updateRecords.isEmpty())
        { 
            update updateRecords;
        }
    
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj
LorrMcLorrMc
Hi Raj, 
Thank you for this,

I have created the Class and received the following: 
Organization Administration Locked
The changes you requested require salesforce.com to temporarily lock your organization's administration setup. However, the administration setup has already been locked by another change. Please wait for the previous action to finish, then try again later. 

Also after creating the Trigger received the following error:
Error: Compile Error: Invalid type: TriggerCarePlanHandler at line 3 column 31

Have I done somthing wrong?

Lorr
Maharajan CMaharajan C
Hi LorrMc,

First you have to save the Class. Then 3rd line in the will Save.

If Organization Administration Locked comes then refresh the page, Again enter the code and Save.

So first Save the Class and then save the Trigger.

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj
LorrMcLorrMc
Thank you again, 

I have tried to save the class but received this:
Error: Compile Error: Expecting '}' but was: '<EOF>' at line 36 column 1
 
LorrMcLorrMc
Hi I have added a } to line 36 which seems to have fixed it but then this happens. 
Error: Compile Error: Variable does not exist: allContactID at line 11 column 13

  Line 11.    allContactIDs.add(var.ContactID );
LorrMcLorrMc
Hi Waqar, 

Apologies I have tried your code in the Class and it is returning Error: Compile Error: Expecting ')' but was: 'var' at line 13 column 38
have I done somthing wrong. 


public class TriggerCarePlanHandler {
         
        set<id> allContactIDs = new set<id>();
        List<Care_Plan_Details__c> allrelatedCarePlans = new List<Care_Plan_Details__c>();
        List<Care_Plan_Details__c> updateRecords = new List<Care_Plan_Details__c>();
         
      public UpdateActivestatus (List<Care_Plan_Details__c> Triggernew)
        {       
            for (Care_Plan_Details__c var : Triggernew)
            {
                allContactIDs.add(var.ContactID );
            } 
               (Care_Plan_Details__c var : Triggernew) { system.debug('care pla details'+' '+ var); // see what are all the details are being populated for contact. //allContactIDs.add(var.ContactID ); }
         
           allrelatedCarePlans = [select id, Active_Inactive__c,ContactID from Care_Plan_Details__cwhere ContactID in:allContactIDs ];
          
            
           for (Care_Plan_Details__c var : allrelatedCarePlans)
               {
                       Care_Plan_Details__c record = new Care_Plan_Details__c();
                        record.Id = var.id;
                        Record.Active_Inactive__c = false;
                   updateRecords.add(record);              
               }
             
            if (!updateRecords.isEmpty())
            {
                update updateRecords;
            }
        }
    }
 
Waqar Hussain SFWaqar Hussain SF
public class TriggerCarePlanHandler {
         
        
        List<Care_Plan_Details__c> allrelatedCarePlans = new List<Care_Plan_Details__c>();
        List<Care_Plan_Details__c> updateRecords = new List<Care_Plan_Details__c>();
         
      public UpdateActivestatus (List<Care_Plan_Details__c> Triggernew)
        {       
			set<id> allContactIDs = new set<id>();
            for (Care_Plan_Details__c var : Triggernew)
            {
                allContactIDs.add(var.ContactID );
            } 
               (Care_Plan_Details__c var : Triggernew) { system.debug('care pla details'+' '+ var); // see what are all the details are being populated for contact. //allContactIDs.add(var.ContactID ); }
         
           allrelatedCarePlans = [select id, Active_Inactive__c,ContactID from Care_Plan_Details__cwhere ContactID in:allContactIDs ];
          
            
           for (Care_Plan_Details__c var : allrelatedCarePlans)
               {
                       Care_Plan_Details__c record = new Care_Plan_Details__c();
                        record.Id = var.id;
                        Record.Active_Inactive__c = false;
                   updateRecords.add(record);              
               }
             
            if (!updateRecords.isEmpty())
            {
                update updateRecords;
            }
        }
    }

try this one
LorrMcLorrMc
Thank You for this Waqar however the the following was returned.

Error: Compile Error: Expecting ')' but was: 'var' at line 14 column 42

Lorr
Waqar Hussain SFWaqar Hussain SF
public class TriggerCarePlanHandler {
         
        
        List<Care_Plan_Details__c> allrelatedCarePlans = new List<Care_Plan_Details__c>();
        List<Care_Plan_Details__c> updateRecords = new List<Care_Plan_Details__c>();
         
      public UpdateActivestatus (List<Care_Plan_Details__c> Triggernew)
        {       
			set<id> allContactIDs = new set<id>();
            for (Care_Plan_Details__c var : Triggernew)
            {
                allContactIDs.add(var.ContactID );
            } 
               for(Care_Plan_Details__c var : Triggernew) { system.debug('care pla details'+' '+ var); // see what are all the details are being populated for contact. //allContactIDs.add(var.ContactID ); }
         
           allrelatedCarePlans = [select id, Active_Inactive__c,ContactID from Care_Plan_Details__cwhere ContactID in:allContactIDs ];
          
            
           for (Care_Plan_Details__c var : allrelatedCarePlans)
               {
                       Care_Plan_Details__c record = new Care_Plan_Details__c();
                        record.Id = var.id;
                        Record.Active_Inactive__c = false;
                   updateRecords.add(record);              
               }
             
            if (!updateRecords.isEmpty())
            {
                update updateRecords;
            }
        }
    }

 
LorrMcLorrMc
Nearly There, thank you sooooo much for your help you are so quick its amazing, please see below.

Error: Compile Error: Invalid identifier '          '. Apex identifiers must start with an ASCII letter (a-z or A-Z) followed by any number of ASCII letters (a-z or A-Z), digits (0 - 9), '$', '_'. at line 2 column 5
Maharajan CMaharajan C
Hi ,

Sorry for the Late Reply. Use the Proper Fields. Because i don't know your Fields Name.

public class TriggerCarePlanHandler {
    
    set<id> allContactIDs = new set<id>();
    List<Care_Plan_Details__c> allrelatedCarePlans = new List<Care_Plan_Details__c>();
    List<Care_Plan_Details__c> updateRecords = new List<Care_Plan_Details__c>();
    
  public static void UpdateActivestatus (List<Care_Plan_Details__c> Triggernew)
    {        
        for (Care_Plan_Details__c var : Triggernew)
        {
            allContactIDs.add(var.Contact__c );     /// Add the Contact Lookup field API Name or Proper Contact Field API Name from Care_Plan_Details__c Object
        }  
        
        if(allContactIDs.size() > 0)
        {
        allrelatedCarePlans = [select id, Active_Inactive__c,Contact__c from Care_Plan_Details__c where Contact__c IN: allContactIDs ];   /// Add the Contact Lookup field API Name or Proper Contact Field API Name from Care_Plan_Details__c Object
        }
       
       If(allrelatedCarePlans.size() > 0)
       {
       for (Care_Plan_Details__c var : allrelatedCarePlans) 
           {
                   Care_Plan_Details__c record = new Care_Plan_Details__c();
                    record.Id = var.id;
                    Record.Active_Inactive__c = false;
               updateRecords.add(record);               
           }
       }   
        
        if (!updateRecords.isEmpty())
        { 
            update updateRecords;
        }
    
}
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj
LorrMcLorrMc
Guys you are so good and patient I understand if you are getting fed up with this now but I really do appriciate your help, 

Waqar I ran your again and I get this:
Error: Compile Error: Invalid identifier '          '. Apex identifiers must start with an ASCII letter (a-z or A-Z) followed by any number of ASCII letters (a-z or A-Z), digits (0 - 9), '$', '_'. at line 2 column 5

Raj I also ran yours adding the lookup field API name Client_CPD__c (see below) and I get this:
Error: Compile Error: Variable does not exist: allContactIDs at line 11 column 13

public class TriggerCarePlanHandler {
    
    set<id> allContactIDs = new set<id>();
    List<Care_Plan_Details__c> allrelatedCarePlans = new List<Care_Plan_Details__c>();
    List<Care_Plan_Details__c> updateRecords = new List<Care_Plan_Details__c>();
    
  public static void UpdateActivestatus (List<Care_Plan_Details__c> Triggernew)
    {        
        for (Care_Plan_Details__c var : Triggernew)
        {
            allContactIDs.add(var.Client_CPD__c );     /// Add the Contact Lookup field API Name or Proper Contact Field API Name from Care_Plan_Details__c Object
        }  
        
        if(allContactIDs.size() > 0)
        {
        allrelatedCarePlans = [select id, Active_Inactive__c,Client_CPD__c from Care_Plan_Details__c where Client_CPD__c IN: allContactIDs ];   /// Add the Contact Lookup field API Name or Proper Contact Field API Name from Care_Plan_Details__c Object
        }
       
       If(allrelatedCarePlans.size() > 0)
       {
       for (Care_Plan_Details__c var : allrelatedCarePlans) 
           {
                   Care_Plan_Details__c record = new Care_Plan_Details__c();
                    record.Id = var.id;
                    Record.Active_Inactive__c = false;
               updateRecords.add(record);               
           }
       }   
        
        if (!updateRecords.isEmpty())
        { 
            update updateRecords;
        }
    
}
}
Jayant DasJayant Das
Because your method declaration is static, you will need to either declare the variables as static or change the method signature. Either of the below will work to fix the compilation errors.
 
private static set<id> allContactIDs = new set<id>();
private static List<Contact> allrelatedCarePlans = new List<Contact>();
private static List<Contact> updateRecords = new List<Contact>();

Or, declare the method as non-static as:
public void UpdateActivestatus (...) {...}
Waqar Hussain SFWaqar Hussain SF
Try this one
public class TriggerCarePlanHandler {
         
        
        List<Care_Plan_Details__c> allrelatedCarePlans = new List<Care_Plan_Details__c>();
        List<Care_Plan_Details__c> updateRecords = new List<Care_Plan_Details__c>();
         
      public UpdateActivestatus (List<Care_Plan_Details__c> Triggernew)
        {       
			set<id> allContactIDs = new set<id>();
            for (Care_Plan_Details__c var : Triggernew)
            {
                allContactIDs.add(var.ContactID );
            } 
               for(Care_Plan_Details__c var : Triggernew) { 
			   system.debug('care pla details'+' '+ var);
			   // see what are all the details are being populated for contact. //allContactIDs.add(var.ContactID );
			   }
         
           allrelatedCarePlans = [select id, Active_Inactive__c,ContactID from Care_Plan_Details__cwhere ContactID in:allContactIDs ];
          
            
           for (Care_Plan_Details__c var : allrelatedCarePlans)
               {
                       Care_Plan_Details__c record = new Care_Plan_Details__c();
                        record.Id = var.id;
                        Record.Active_Inactive__c = false;
                   updateRecords.add(record);              
               }
             
            if(!updateRecords.isEmpty())
            {
                update updateRecords;
            }
        }
    }

 
LorrMcLorrMc
Thank you all so much, I think I will have to admit defet on this one I have tried all and still no joy. 
Waqar - Thank you so much for your time and codes I did try this one but I am getting the same error. Compile Error: Invalid identifier '          '. Apex identifiers must start with an ASCII letter (a-z or A-Z) followed by any number of ASCII letters (a-z or A-Z), digits (0 - 9), '$', '_'. at line 2 column 5 
Jayant - Additionaly Thank You also for your time and suggestion which I did try your suggestion but think I added it wrong (see below) so also getting errors.
For Option 1 - 
public class TriggerCarePlanHandler {
    
    private static set set<id> allContactIDs = new set<id>();
    private static set List<Care_Plan_Details__c> allrelatedCarePlans = new List<Care_Plan_Details__c>();
    private static set List<Car
e_Plan_Details__c> updateRecords = new List<Care_Plan_Details__c>();
    
  public static void UpdateActivestatus (List<Care_Plan_Details__c> Triggernew)
    {        
        for (Care_Plan_Details__c var : Triggernew)
        {
            allContactIDs.add(var.Client_CPD__c );     /// Add the Contact Lookup field API Name or Proper Contact Field API Name from Care_Plan_Details__c Object
        }  
        
        if(allContactIDs.size() > 0)
        {
        allrelatedCarePlans = [select id, Active_Inactive__c,Client_CPD__c from Care_Plan_Details__c where Client_CPD__c IN: allContactIDs ];   /// Add the Contact Lookup field API Name or Proper Contact Field API Name from Care_Plan_Details__c Object
        }
       
       If(allrelatedCarePlans.size() > 0)
       {
       for (Care_Plan_Details__c var : allrelatedCarePlans) 
           {
                   Care_Plan_Details__c record = new Care_Plan_Details__c();
                    record.Id = var.id;
                    Record.Active_Inactive__c = false;
               updateRecords.add(record);               
           }
       }   
        
        if (!updateRecords.isEmpty())
        { 
            update updateRecords;
        }
    
}
}

Error: Compile Error: Unexpected token 'set'. at line 3 column 24

For Option 2 - 
Error: Compile Error: Expecting ')' but was: '.' at line 7 column 35
public class TriggerCarePlanHandler {
    
    set<id> allContactIDs = new set<id>();
    List<Care_Plan_Details__c> allrelatedCarePlans = new List<Care_Plan_Details__c>();
    List<Care_Plan_Details__c> updateRecords = new List<Care_Plan_Details__c>();
    
  public void UpdateActivestatus (...) {...}

    {        
        for (Care_Plan_Details__c var : Triggernew)
        {
            allContactIDs.add(var.Client_CPD__c );     /// Add the Contact Lookup field API Name or Proper Contact Field API Name from Care_Plan_Details__c Object
        }  
        
        if(allContactIDs.size() > 0)
        {
        allrelatedCarePlans = [select id, Active_Inactive__c,Client_CPD__c from Care_Plan_Details__c where Client_CPD__c IN: allContactIDs ];   /// Add the Contact Lookup field API Name or Proper Contact Field API Name from Care_Plan_Details__c Object
        }
       
       If(allrelatedCarePlans.size() > 0)
       {
       for (Care_Plan_Details__c var : allrelatedCarePlans) 
           {
                   Care_Plan_Details__c record = new Care_Plan_Details__c();
                    record.Id = var.id;
                    Record.Active_Inactive__c = false;
               updateRecords.add(record);               
           }
       }   
        
        if (!updateRecords.isEmpty())
        { 
            update updateRecords;
        }
    
}
}
 
Maharajan CMaharajan C
Hi,

Sorry for the mis guiding: Am in Office so not able to concentrate fully.

The below code surely will work:

public class TriggerCarePlanHandler {
    
    
  public static void UpdateActivestatus (List<Care_Plan_Details__c> Triggernew)
    {        
    
    set<id> allContactIDs = new set<id>();
    List<Care_Plan_Details__c> allrelatedCarePlans = new List<Care_Plan_Details__c>();
    List<Care_Plan_Details__c> updateRecords = new List<Care_Plan_Details__c>();
    
        for (Care_Plan_Details__c var : Triggernew)
        {
            allContactIDs.add(var.Client_CPD__c );     /// Add the Contact Lookup field API Name or Proper Contact Field API Name from Care_Plan_Details__c Object
        }  
        
        if(allContactIDs.size() > 0)
        {
        allrelatedCarePlans = [select id, Active_Inactive__c,Client_CPD__c  from Care_Plan_Details__c where Client_CPD__c IN: allContactIDs ];   /// Add the Contact Lookup field API Name or Proper Contact Field API Name from Care_Plan_Details__c Object
        }
       
       If(allrelatedCarePlans.size() > 0)
       {
       for (Care_Plan_Details__c var : allrelatedCarePlans) 
           {
                    Care_Plan_Details__c record = new Care_Plan_Details__c();
                    record.Id = var.id;
                    Record.Active_Inactive__c = false;
               updateRecords.add(record);               
           }
       }   
        
        if (!updateRecords.isEmpty())
        { 
            update updateRecords;
        }
    
}
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj