+ Start a Discussion
Blake Reeves 9Blake Reeves 9 

I am getting this error when building in Process Builder "The formula expression is invalid: Syntax error. Missing '='". What is wrong with my code?

I am trying to update a record field with type formula. Below is the formula that I have written. Any help?

List<[Order_Item__c> Orders = [SELECT Product_Record_Type__c, Total_Price__c FROM [Order_Item__c]];
Integer total = 0;

for ([Order_Item__c] order : Orders){

IF(order.Product_Record_Type__c == "Building Option",
total += order.Total_Price__c;
)

};

return total;
Best Answer chosen by Blake Reeves 9
SATHISH REDDY.SATHISH REDDY.
Okay! you cannot write apex logic in Process builder, instead you need to use the logic as Salesforce formula or invoke an apex by placing the above logic in a class. My next question for you is, on which field are you storing this "Total".
 

All Answers

Blake Reeves 9Blake Reeves 9
I thought for sure that would be it, but I still get this error after the changes: "Your changes are saved, but you can't activate this process until you resolve the following errors.
The formula expression is invalid: Syntax error. Missing '='".
SATHISH REDDY.SATHISH REDDY.
Hi Blake,

Can you please share the snapshot of process builder aswell, that helps us understand better.

Cheers!
Sathish
Blake Reeves 9Blake Reeves 9
User-added image
SATHISH REDDY.SATHISH REDDY.
Okay! you cannot write apex logic in Process builder, instead you need to use the logic as Salesforce formula or invoke an apex by placing the above logic in a class. My next question for you is, on which field are you storing this "Total".
 
This was selected as the best answer
Blake Reeves 9Blake Reeves 9
I am now just creating an invocable method. What return types do invocable methods allow?
SATHISH REDDY.SATHISH REDDY.
If you are using the invocable method then you can perform all the logic within that. Please refer below example which will help you.
https://www.desynit.com/dev-zone/salesforce-development/replacing-apex-triggers-processes-invocable-actions/