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
Charles McDowellCharles McDowell 

Trigger Error:no viable alternative at character '"'

trigger AddRelatedCustomer on Account (after insert) {
I am new to salesforce and I am gett the no viable alternative at character '"' from this trigger.  Can you tell me what I am doing wrong

List<Contact> cont = new List<Contact>();
    for(Account acct: Trigger.new)
    {
           cont.add(New Contact(LastName = "Stitt",FirstName = "Sonny", AccountID = acct.ID));
        insert cont;
        
    }
}
Best Answer chosen by Charles McDowell
Esther OnemaEsther Onema
Hello,
Would you kindly mark my answer as best answer/ solved so that others who do not know how to resolve this error know how. 
Thank you,
Esther.

All Answers

Esther OnemaEsther Onema
Nothing serious, your string values must be enclosed in single quotes rather than double quotes like so. It should make that error go away.
trigger AddRelatedCustomer on Account (after insert) 
{
    List <Contact> cont = new List<Contact>();
    
    for(Account acct: Trigger.new)
    {
        
        cont.add(new contact(lastname= 'Sitt', FirstName = 'Sonny', AccountId= acct.ID));
            insert cont;

    }
    
}

Feel free to give this a thumbs up/mark as best answer if the solution worked for you

Thank you,
Esther Onema
Charles McDowellCharles McDowell
Thanks, that works fine Sent from my Sprint Samsung Galaxy S® 6.
Esther OnemaEsther Onema
Hello,
Would you kindly mark my answer as best answer/ solved so that others who do not know how to resolve this error know how. 
Thank you,
Esther.
This was selected as the best answer