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
Ram ChaturvediRam Chaturvedi 

Error: Compile Error: line 16:0 no viable alternative at character ' ' at line 16 column 0 ?

trigger FireMail on Lead__c (after insert,after update) {

    list<lead__c> leads = new list<lead__c>();
    string mailcontent ;
    leads = trigger.new ;
    
    for(lead__c ld : leads){
    
        string nm = ld.name ;
        string EmailId = ld.Email_Id__c ;
        
        if(EmailId != null){
            
               mailcontent ='Thanks For contacting Us ' ;           
                                                                                                        // here error is Occur
               Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
               string [] toaddress= New string[]{EmailId};
               email.setSubject('Thanks for Contacting .');
               email.setPlainTextBody(mailcontent);
               email.setToAddresses(toaddress);
               Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
        
        } 
    }
}
Dushyant SonwarDushyant Sonwar
See this....
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000938oIAA
SF AdminSF Admin
Some of the single quote characters in your class file are invalid --- perhaps because you copied and pasted the code from somewhere else. I've had this happen many times before when I've copied code from elsewhere. Starting with the quotes in: mailcontent ='Thanks For contacting Us ' ; , i'd delete the single quotes, retype them, and resave your file. Repeat for all single quotes (or do a find and replace).

Regards
KaranrajKaranraj
Are you sure? I'm not getting any error meesage while saving this code in my org. I made couple of changes in your code,

1. You are storing trigger.new in List variable and then you are using that in your for loop. Instead you can directly use the trigger.New in the for looping which will helps to reduce the heap size in the execution.

2. You are sending email inside the for loop by which you will easily hit an number of email governor limit.

Try th updated code below
trigger FireMail on Lead__c (after insert,after update) {

    string mailcontent ;    
 List<Messaging.SingleEmailMessage> theEmails = new List<Messaging.SingleEmailMessage> ();
    for(lead__c ld :  trigger.new){
    
        string nm = ld.name ;
        string EmailId = ld.Email_Id__c ;
        
        if(EmailId != null){
            
         mailcontent ='Thanks For contacting Us ' ;           
         Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
         string [] toaddress= New string[]{EmailId};
          email.setSubject('Thanks for Contacting .');
          email.setPlainTextBody(mailcontent);
          email.setToAddresses(toaddress);
theEmails.add(email);
        
        
        } 
    }
if(theEmails.size > 0)
   Messaging.sendEmail(theEmails);
}

 
Ram ChaturvediRam Chaturvedi
On another Org i am also not getting Any Error ..............  
But 
i had delete the single quotes, retype again but its giving error ....  :-(