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
Vigneshwaran LoganathanVigneshwaran Loganathan 

Newbie Error: Compile Error: line 8:29 no viable alternative at character '‘' at line 8 column 29

trigger createNewAccountOpportunity on Account (after insert) { 
    List<Opportunity> listOpportunities = new List<Opportunity>();

    for (Account oAccount : trigger.new) {
        Opportunity oOpportunity = new Opportunity();
        oOpportunity.Name = oAccount.Name;
        oOpportunity.AccountId = oAccount.Id;
        oOpportunity.Stage = ‘Closed Lost’;
        oOpportunity.CloseDate = System.today() + 30; //Closes 30 days from today

        listOpportunities.add(oOpportunity);
    }

    if (listOpportunities.isEmpty() == false) {
        Database.update(listOpportunities);
    }
}
Best Answer chosen by Vigneshwaran Loganathan
PratikPratik (Salesforce Developers) 
Hi Vigneshwaram,

You are getting that error because:

1. It shoud be  oOpportunity.StageName instead oOpportunity.Stage

2. It should be 'Closed Lost'  insted   ‘Closed Lost’  (this difference you will observe while writing trigger)

Thanks,
Pratik


P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.

All Answers

PratikPratik (Salesforce Developers) 
Hi Vigneshwaram,

Try this code:


trigger createNewAccountOpportunity on Account (after insert) {
    List<Opportunity> listOpportunities = new List<Opportunity>();

    for (Account oAccount : trigger.new) {
        Opportunity oOpportunity = new Opportunity();
        oOpportunity.Name = oAccount.Name;
        oOpportunity.AccountId = oAccount.Id;
        oOpportunity.Stagename = 'Closed Lost';
        oOpportunity.CloseDate = System.today() + 30; //Closes 30 days from today

        listOpportunities.add(oOpportunity);
    }

    if (listOpportunities.isEmpty() == false) {
        Database.update(listOpportunities);
    }
}



Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
Anoop yadavAnoop yadav
Hi,

Use oOpportunity.StageName = 'Closed Lost';
instead of oOpportunity.Stage = ‘Closed Lost’;
PratikPratik (Salesforce Developers) 
Hi Vigneshwaram,

You are getting that error because:

1. It shoud be  oOpportunity.StageName instead oOpportunity.Stage

2. It should be 'Closed Lost'  insted   ‘Closed Lost’  (this difference you will observe while writing trigger)

Thanks,
Pratik


P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
This was selected as the best answer
Vigneshwaran LoganathanVigneshwaran Loganathan
Hi Pratik,

Thank yu so much for ur Answer :)

PratikPratik (Salesforce Developers) 
Glad it helped! :)

Thanks,
Pratik
nikki goudnikki goud
Error Error: Compile Error: Variable does not exist: Name at line 6 column 29
i got above error for ur code pratik