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
shakila Gshakila G 

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 12 column 23

Hi All,

Am trying to auto Populate the Task WhatID lookup Based Contact Lookup.

Am getting Following Error:
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 12 column 23

Kindly let me know what I have to do here?

This is my Trigger.
trigger populateAccount on task (before insert, before update)
{
  Set<ID> setConIds = new Set<ID>(); 
  
  for(task obj : trigger.new)
   {
       if(obj.whoid!= null)
       setConIds.add(obj.Whoid);
   
   } 
   MAP<ID,Contact> mapCon =
   new MAP<ID,Contact>([Select Account_name__C from Contact where id in: setConIds]);
   
   
   for(Task  obj : trigger.new)
   {
        if(obj.Whoid!= null)
          {
            Contact  c = mapCon.add(obj.WhoiD);
            obj.WhatID= c.Account_name__C;         
       
   }
   

}
RazaRaza
Plz Try It
trigger populateAccount on Task (before insert){
    Set<Id> setConIds = new Set<Id>();
    
    for(Task obj : trigger.new)
    {
        if(obj.whoId!= null)
            setConIds.add(obj.Whoid);
        
    }
    Map<Id,Contact> mapCon =new Map<Id,Contact>([Select Account_name__c from Contact where id IN: setConIds]);
    
    
    for(Task obj : trigger.new)
    {
        if(obj.Whoid!= null)
        {
            Contact  con= mapCon.add(obj.whoId);
            obj.WhatID= con.Account_name__c;         
            
        }
        
      }
 }  
HI shakila G ,
your problem is slove
thanks
shakila Gshakila G
Hi Mohad,

Thanks for the reply am getting following error.

User-added image

While Executing the below trigger

trigger Autopopulate on task (Before insert){
  Set<ID> setConId = new Set<ID>(); 
  
     for(Task obj : Trigger.New){   
        If(Trigger.Isinsert) {
        
            if(obj.Whoid !=''){
            
                setConId.add(obj.Whoid);            
                system.debug('****setConId'+setConId);     
                
            }
        }
        
        if(Trigger.isupdate && obj.Whoid !='') {
        
         if(obj.Whoid !=Null){
            
                setConId.add(obj.Whoid);           
                system.debug('****setConId'+setConId);   
          
        }
        
    }
    
    }
   
   list<contact> lsc=[Select ID,Account_name__C from Contact where id in:setConId];
    map <ID, Contact> contactMap= new map <ID, Contact>();
     for(Contact ct: lsc) {
        contactMap.put(ct.Account_name__C , ct);
        }
    
    for(task obj : Trigger.New)
   {
        if(obj.Whoid!= null)
          {
           obj.WhatID= contactMap.get(obj.whoid ).Account_name__C ;       
       
   }
   
  
 }  

}
RazaRaza
Please update complete scenario Because I do not understand your problem