You need to sign in to do that
Don't have an account?
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);
}
}
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);
}
}
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
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.
Use oOpportunity.StageName = 'Closed Lost';
instead of oOpportunity.Stage = ‘Closed Lost’;
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.
Thank yu so much for ur Answer :)
Thanks,
Pratik
i got above error for ur code pratik