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
Ramanjot SidhuRamanjot Sidhu 

Trigger not working: Expression cannot be assigned at line -1 column -1

 trigger ControlOpportunityStage on Line_Item__c (after update) {
       List<Opportunity> parentlist = new List<Opportunity>();
       List<Opportunity> opportunityId = new list<Opportunity>();
           for(Line_item__c lirecord : [SELECT Opportunity__r.id, Opportunity__r.StageName

from Line_item__c
               where Line_item__c.Opportunity__c <> null]){
                    
        for(Opportunity opt : parentlist)
            if(Opportunity.StageName != Line_item__c.Stage__c)
                Opportunity.StageName = Line_item__c.Stage__c;
                opportunityId.add(opportunity.Id);
       
 {
      if(opportunityId != null & opportunityId.Size()>0)
            update opportunityId;
               
       
 }     
}
}
Ramanjot SidhuRamanjot Sidhu
Can someone please help me on this trigger...I can't figure out the reason why I am getting the error.
Vivek DeshmaneVivek Deshmane
Hi Ramanjot,
you have missed { braces in your trigger code(for(Opportunity opt : parentlist)
            if(Opportunity.StageName != Line_item__c.Stage__c)
                Opportunity.StageName = Line_item__c.Stage__c;
                opportunityId.add(opportunity.Id);
       
 {) and this is main problem. try below corrected code it should work and it should work. not sure what is use of this your code but I removed error.
trigger ControlOpportunityStage on Line_Item__c (after update) {
       List<Opportunity> parentlist = new List<Opportunity>();
       List<Opportunity> opportunityId = new list<Opportunity>();
      for(Line_item__c lirecord : [SELECT Opportunity__r.id, Opportunity__r.StageName
		from Line_item__c  where Line_item__c.Opportunity__c <> null]){
		
		for(Opportunity opt : parentlist)
		{
			if(opt.StageName != Line_item__c.Stage__c)
			{
			 opt.StageName = Line_item__c.Stage__c;
			 opportunityId.add(opt);
			}
		}
		
		}
		
		if(opportunityId != null & opportunityId.Size()>0)
            update opportunityId;
			
		
	}
PLease let me if it works.

Best Regards,
-Vivek
Ramanjot SidhuRamanjot Sidhu
This does not work, I still get the error