function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sravikasravika 

Need immediate help

Hi,

I need a solution for this requirment..could u please help me in this context.

 

I have two conditions where in the first one I have to display the value of Formula field by calculating its value in the controller itself.

In the second case i need to display its value from the page(formula given during the field creation) into the same controller..

 

It is something like

 if(true)

{

display field value by calculating it in the controller

}
else

{

  display the value of the formula field directly

}

 

Jeff MayJeff May

It sounds like you are writing a Visual Force page and controller. In your controller, set a public variable true or false, and then add the render= attribute to 2 different page elements (like <apex:outputField> and <apex:outputText>) only 1 will render at a time.

ShahTheTrainerShahTheTrainer

plz check whehter you are looking for this.

 

<apex:page controller="MySampleController">
	<apex:form>
		<apex:inputCheckBox value="{!isChecked}" />
		<apex:outputText value="Eligible for Discount" />
		<apex:commandButton value=""
		<apex:outputField value="{!SampleValue}" />
	</apex:form>
</apex:page>

------  controller logic.

public with sharing class MySampleController
{
	public String  sampleValue { get; set; }      // to assign the value to be displayed on VF page
	public BOOLEAN isChecked   { get; set; }      // if the user checks the checkbox i.e. true
	
	public void doDisplay()
	{
		if(isChecked)                  // if the user checks the checkbox
		{
			sampleValue = Total - discount;// do your calculation here.
		}
		else              // if not checked i.e. false
		sample Value
		{
			sampleValue = directValue.i.e.FormulaFieldValue;
		}
	}
}

 please let me know whether I have understood your requirement, I am ready to solve even if your requirement is something other.

ShahTheTrainerShahTheTrainer
<apex:page controller="MySampleController">
	<apex:form>
		<apex:inputCheckBox value="{!isChecked}" />
		<apex:outputText value="Eligible for Discount" />
		<apex:commandButton value="Submit" action="{!doDisplay}" />
		<apex:outputField value="{!SampleValue}" />
	</apex:form>
</apex:page>

------  controller logic.

public with sharing class MySampleController
{
	public String  sampleValue { get; set; }  
	public BOOLEAN isChecked   { get; set; }  
	
	public void doDisplay()
	{
		if(isChecked)           
		{
			sampleValue = Total - discount;// do your calculation here.
		}
		else             
		{
			sampleValue = directValue.i.e.FormulaFieldValue;
		}
	}
}