+ Start a Discussion
kb15kb15 

Parsing and evaluating the expression

Need to parse and evaluate the expression entered via InputText, user  may enter text as below into the given text Field

 

Opportunity.Amount  * 1.5

 

It should evaluate the value of Opportunity.Amount and also it should perform arithmatic operation.

 

Any help will be appreciated.

 

Chamil MadusankaChamil Madusanka

You can use <apex:variable> with your code.

 

Refer following example

http://visualforcemadeeasy.blogspot.com/2010/04/how-to-use-apex-variable-for-total.html

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

kb15kb15

Thanks for the inputs, but really not sure how this will be helpful  in the current scenario

 

Basically   we need to perform arithmatic operation in the apex  class or Trigger. So need to evaluate the string to perform the mathematical operation and give the result. Similar to JS function eval. I could have directly used this js function eval but this is to be done on the apex/trigger side. So if the user enters - Opportunity.Amount (sObject.Field), this can be evaluated at apex side.

Chamil MadusankaChamil Madusanka

Ohh my bad, You want to get the value of String and do the operation. If so, you need to refer this link and solve your problem

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_string.htm

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

sornasorna

Hi, did you find any solution for this?

We also have a similar requirement - need to evaluate a string expression from a trigger. Please let me know is there a solution or any workarounds for this.

 

Thanks,

Sorna

kb15kb15

Hi 

 

We achieved this by sending the string content to dot NET program which evaluated the actual value + arithmetic operation and returned the result.

 

You can try this by either .NET or Java.

 

Let me know if this helps you?

 

Thanks

DellaStreetDellaStreet

Thanks, Chamil!

 

String.valueOf(   was exactly what I needed.

 

:}