You need to sign in to do that
Don't have an account?
Samantha 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');
}
}
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');
}
}
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
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
];
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');
}
}