Flow Error java.lang.String cannot be cast to java.lang.Number - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Appcentrica ConsultantAppcentrica Consultant 

Flow Error java.lang.String cannot be cast to java.lang.Number

I configured a flow to query a set of line items, iterate thru them and get the highest line item in each category. Each line item is associated with a category.

Flow Attached below
User-added image

In most of the cases it works fine, but in some it fails in the second decision element (bottom - right) with the error message Error Occurred During Flow "Forecast_Summary": java.lang.String cannot be cast to java.lang.Number

I found similar issues to this error message and they reference it could be a heap limit issue, but I am getting this error with collections as small as 1 record. In some cases works no problem, in some I get the same error, always in the same step.

I made sure the variables being compared in the step are of the same type.


Any ideas?
Best Answer chosen by Appcentrica Consultant
Appcentrica ConsultantAppcentrica Consultant
This issue was very interesting

In the decision element where the flow was breaking sometimes, I was doing a comparison of a variable defined in the flow as currency against a currency field from a SObject.

For some reason, this was causing the cast issue (even though both variables were of the same type - currency).

I ended up creating a formula field (Type: Number) in the object to store the currency value. That  worked and the flow has not broken since.

 

All Answers

Ines GarciaInes Garcia
Hi Jessica,

Hmm just reading the error seems a data type mapping issue from text to cast Number
Hope this helps,

Ines
Appcentrica ConsultantAppcentrica Consultant
This issue was very interesting

In the decision element where the flow was breaking sometimes, I was doing a comparison of a variable defined in the flow as currency against a currency field from a SObject.

For some reason, this was causing the cast issue (even though both variables were of the same type - currency).

I ended up creating a formula field (Type: Number) in the object to store the currency value. That  worked and the flow has not broken since.

 
This was selected as the best answer
Ines GarciaInes Garcia
Boom brilliant, yes sometimes you need to expose the data as other type or even show on screen for example Ive done that when pulling user ID. 
Glad you found a way and thanks for confirming the workaround your issue!