+ Start a Discussion
Diego GuevaraDiego Guevara 

How to save a math operation in a field from a visualforce page?

Is it possible to save a variable value in a field from a visualforce page?

This is the code:

<strong>$</strong> <apex:outputText value="{0, number, ####,###.00}">
               <apex:param value="{!total + total*Cotizaci_n__c.Percent_of_utility__c/100}"/>
            </apex:outputText>
I need to save this result in a Field call "BIGTOTAL", is this possible?

PD: (total + total*Cotizaci_n__c.Percent_of_utility__c), total is a total of many variables in the visualforce page, and percent is a field. This operation works! but like i said, i need to save this result into a field.
Thanks!
NagendraNagendra (Salesforce Developers) 
Hi Diego,

Depends on how are you calculating total.

Where ever you are calculating total you can update the field as well. I have written some code where I am getting the record and updating the same by using a variable in the controller.
public class stdCtrAccount {

    public double TotalAmount {get;set;}
    public string accId {get;set;}
    public Account acc {get;set;}

    public stdCtrAccount(ApexPages.StandardController controller) {
        acc = (Account)controller.getrecord();
    }
    
    public void calculateAmount(){
        TotalAmount  = acc.NumberOfEmployees * 500;
        acc.AnnualRevenue = TotalAmount ;
        Update acc;
    }

}
In this case, you have to call this action method to save the value. 

If you are trying to fetch this value on PDF using render as then it may not work. However, if you are creating your VF page and getting PDF then you may use output field for getting into the output instead of referring to that field.

Hope this helps.

Regards,
Nagendra.