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
Samantha StarlingSamantha Starling 

Unexpected Token 'FROM'

I am very, very new to development and am working on my first Apex Class for a button that will update fields from a custom object (Production Details) to the Opportunity Product based on the matching of the data in two fields (Opportunity Product Number on both objects).I am getting a error message that there's an Unexpected Token 'FROM'. Any direction on materials that will help fix the error? Code below...

global class ProductionDetailConversion{
    webService
    static String copyProductionDetail(Id Production_DetailId){
        List<Production_Detail__c> lstProductionDetail =
            [
                SELECT 
                    Id, 
                    Shipping_Costs__c, 
                    Postage_Costs__c,
                    Per_Piece_Costs__c, 
                    
                FROM 
             Production_Detail__c 
                WHERE 
                    Id = :ProductionDetailId
            ];
 
    
       List <OpportunityProductLineItem> lstOpportunityProductLineItem = new 

List<OpportunityProductLineItem>();
 
        for(!OpportunityLineItem.Opportunity_Product_Number__c : Production_Detail__c.Opportunity_Product__c}){
              
                    lstOpportunityProductLineItem.add(
                        new OpportunityProductLineItem(
                            
                            Shipping_Costs__c = OpportunityLineItem.Shipping_Costs__c,
                            Postage_Costs__c = OpportunityLineItem.Postage_Costs__c,
                            Per_Piece_Costs__c = OpportunityLineItem.Per_Piece_Costs__c,
                       
                        )
                    );
               }     
      try{   
            INSERT lstOpportunityProductLineItem;
            return lstOpportunityProductLineItem[0].Id; 
        }
        catch (Exception ex){
            
            return('Error');
        }     
}
Best Answer chosen by Samantha Starling
HawkedHawked
Samantha, 

When you write a SOQL, you need to follow

SELECT (field1, field2) FROM (object to select) WHERE criteria_to_filter

In your query you have a , after the last field before the FROM part in your select statement.

try this 

List<Production_Detail__c> lstProductionDetail =
            [
                SELECT 
                    Id, 
                    Shipping_Costs__c, 
                    Postage_Costs__c,
                    Per_Piece_Costs__c 
                    
                FROM 
             Production_Detail__c 
                WHERE 
                    Id = :ProductionDetailId
            ];
 

All Answers

HawkedHawked
Samantha, 

When you write a SOQL, you need to follow

SELECT (field1, field2) FROM (object to select) WHERE criteria_to_filter

In your query you have a , after the last field before the FROM part in your select statement.

try this 

List<Production_Detail__c> lstProductionDetail =
            [
                SELECT 
                    Id, 
                    Shipping_Costs__c, 
                    Postage_Costs__c,
                    Per_Piece_Costs__c 
                    
                FROM 
             Production_Detail__c 
                WHERE 
                    Id = :ProductionDetailId
            ];
 
This was selected as the best answer
Samantha StarlingSamantha Starling
That fixed it!! Thanks :) And I was able to move along with some others fixes (like changing : to =). However, now I'm getting an error that my variable doesn't exist on the field on the OpportunityLine Item Number field. It's an auto number field and I've tried every combination I can think of to make it recognize the field. Any suggestions on that?

 for(OpportunityProductLineItem.Product_Number__c = Production_Detail__c.Opportunity_Product__c}){
              
                    lstOpportunityProductLineItem.add(
                        new OpportunityProductLineItem(
                            
                            Shipping_Costs__c = OpportunityLineItem.Shipping_Costs__c,
                            Postage_Costs__c = OpportunityLineItem.Postage_Costs__c,
                            Per_Piece_Costs__c = OpportunityLineItem.Per_Piece_Costs__c,
                       
                        )
                    );
               }     
      try{   
            INSERT lstOpportunityProductLineItem;
            return lstOpportunityProductLineItem[0].Id; 
        }
        catch (Exception ex){
            
            return('Error');
        }     
}