You need to sign in to do that
Don't have an account?
LorrMc
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
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
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
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.
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
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
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
I have tried to save the class but received this:
Error: Compile Error: Expecting '}' but was: '<EOF>' at line 36 column 1
Error: Compile Error: Variable does not exist: allContactID at line 11 column 13
Line 11. allContactIDs.add(var.ContactID );
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;
}
}
}
try this one
Error: Compile Error: Expecting ')' but was: 'var' at line 14 column 42
Lorr
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
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
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;
}
}
}
Or, declare the method as non-static as:
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<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;
}
}
}
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;
}
}
}
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