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 

Compile Error: Loop with query must provide a statement at line 4 column 12

I am trying to update parent stage(Opportunity: StageName) with child stage (Line_item__c : Stage__C) and get the error:

Compile Error: Loop with query must provide a statement at line 4 column 12


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;
                optId.add(opt);
            
      }
     }
         if(opportunityId != null & opportunityId.Size()>0)
            upsert opportunityId;
}
Best Answer chosen by Ramanjot Sidhu
Vivek DeshmaneVivek Deshmane
Hi 
Try this and let me know.
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;
                optId.add(opt);
            
      }
     }
         if(opportunityId != null & opportunityId.Size()>0)
            upsert opportunityId;
}

Best Regards,
-Vivek

All Answers

Vivek DeshmaneVivek Deshmane
Hi 
Try this and let me know.
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;
                optId.add(opt);
            
      }
     }
         if(opportunityId != null & opportunityId.Size()>0)
            upsert opportunityId;
}

Best Regards,
-Vivek
This was selected as the best answer
Jason BealJason Beal
On line 5 you have a semicolon "null]);{" remove the semicolon. 
Ramanjot SidhuRamanjot Sidhu

Hi, I tried the new trigger, but now i get the following error:

 

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

Vivek DeshmaneVivek Deshmane
Hi,
paste your code and let me check

Best Regards,
-Vivek
Ramanjot SidhuRamanjot Sidhu

Hi Vivek, I used the same code but removed the semi colon,

 

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;
                optId.add(opt);
            
      }
     }
         if(opportunityId != null & opportunityId.Size()>0)
            upsert opportunityId;
}

Ramanjot SidhuRamanjot Sidhu
This code may be completely wrong:

I am trying to update the picklist field on the parent object (Opportunity), using the child object picklist field

 

Opportunity - StageName
Line_item__c - Stage__c
Picklist values:
Engagement Intended
Engagement - Not Commited
Verbal Commitment
Signed Commitment
Closed Won
Closed Lost

When I update the stage field on my custom object (child object), I want to create at rigger to automatically update the stage field on the opportunity object.
Ramanjot SidhuRamanjot Sidhu
ERROR:
Error: Compile Error: 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;
               
       
 }     
}
}
Vivek DeshmaneVivek Deshmane
Hi ,
For me it's wokring fine . please let me know what steps you following.

Regards,
-Vivek
Vivek DeshmaneVivek Deshmane
Hi,
Please mark the Best Answer.
Regards,
-Vivek