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
Akash jena 3Akash jena 3 

Invalid character in identifier: Lead__cIds

trigger TaskCount on Task (after delete, after insert, after undelete, after update) {

Set<ID> Lead__cIds = new Set<ID>();

//We only care about tasks linked to Leads.

String leadPrefix = Lead__c.SObjectType.getDescribe().getKeyPrefix();

//Add any Lead ids coming from the new data

if(trigger.new!=null){
    for (Task t : Trigger.new) {
     if (t.WhoId!= null && string.valueof(t.WhoId).startsWith(leadPrefix) ) {

if(!Lead__cIds.contains(t.WhoId)){
//adding unique lead ids since there can be many tasks with single lead
Lead__cIds.add(t.WhoId);
}
}
      }
}
 
//Also add any Lead ids coming from the old data (deletes, moving an activity from one Lead to another)

if(trigger.old!=null){
    for (Task t2 : Trigger.old) {
     if (t2.WhoId!= null && string.valueof(t2.WhoId).startsWith(leadPrefix) )
         {
if(!Lead__cIds.contains(t2.WhoId)){
//adding unique lead ids since there can be many tasks with single lead
Lead__cIds.add(t2.WhoId);
}
}
      }
}

     if (Lead__cIds.size() > 0){



List<Lead__c> leadsWithTasks = [select id,Task_Count__c,(select id from Tasks) from Lead__c where Id IN : Lead__cids];

List<Lead__c> leadsUpdatable = new List<Lead__c>();

for(Lead__c L : leadsWithTasks){

L.Task_Count__c = Lead__cids.size();
leadsUpdatable.add(L);

}

if(leadsUpdatable.size()>0){

update leadsUpdatable;
//update all the leads with activity count

}

    }
}
SwethaSwetha (Salesforce Developers) 
HI Akash,
Can you rename the variable from Lead__cIds to clds(without double underscore) or similar to see if it still throws the same error?

Related: https://salesforce.stackexchange.com/questions/246959/invalid-character-in-identifier-in-wrapper-class
Thanks
Akash jena 3Akash jena 3
i did the changes and there no error , but the trigger is not working in that object , can you please help me out
SwethaSwetha (Salesforce Developers) 
HI Akash, What is the error you are seeing? Thanks
Akash jena 3Akash jena 3
in developer console there is no error in the trigger , but for which I had written the trigger , the requirement is not fulfilling, can I share my screen with u