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
Proposal ButtonProposal Button 

Error while creating a Trigger ( Error: Compile Error: unexpected token: ':' at line 11 column 84)

Hi I am trying to create a trigger to update the check box whenever the Opportunity stage changes from Closed Won to a new stage. Here is the trigger i wrote and it is throwing me an error. Please let me know whether the way i wrote the trigger is write or wrong. I mentioned the error in Red color 

 

 

trigger OpportunityUpdate on Opportunity (after update)
{
List <Opportunity> OppList;
List <Id> oppIdList = new List <Id>();
for(Integer i=0; i<Trigger.new.size(); i++)
{
    if (Trigger.old[i].StageName == 'Closed Won' && Trigger.new[i].StageName != 'Closed Won')
        
        oppIdList.add(Trigger.new[i].Id);
}   
OppList = [select Opportunity.Not_Closed_won__c from Opportunity where opportunity  :oppIdList];
if (OppList.size() > 0)
{
  
        if (Opportunity.Not_Closed_won__c != true)
        {
           Opportunity.Not_Closed_won__c = true;  
           }
    }
    
    update OppList;
    }

 

Best Answer chosen by Admin (Salesforce Developers) 
dotnet developedotnet develope

Hi,

 

List <Id> oppIdList = new List <Id>(); 
change the above code to
Set<id> oppidList = new Set<id>();
and in the query
OppList = [select Opportunity.Not_Closed_won__c from Opportunity where id IN :oppIdList];

All Answers

VPrakashVPrakash

Change your query to 

 

OppList = [select Opportunity.Not_Closed_won__c from Opportunity where id  in:oppIdList];

Proposal ButtonProposal Button

Hi Prakash I changed the query as you said. This is the error it is throwing now

 

 

 Compile Error: Expression cannot be assigned at line -1 column -1
dotnet developedotnet develope

Hi,

 

List <Id> oppIdList = new List <Id>(); 
change the above code to
Set<id> oppidList = new Set<id>();
and in the query
OppList = [select Opportunity.Not_Closed_won__c from Opportunity where id IN :oppIdList];
This was selected as the best answer