+ Start a Discussion
saisaisaisai 

how to access apex ui fields in customcontroller

Here is my method in customController:

 


public PageReference AddRecord()
{
donation.Donation_Date__c=System.today();
donation.Payment_Method__c='Credit';
donation.Payment_Source__c='In_person';
donation.Candidate__c=candidate.Id;
donation.Donation_State__c=ApexPages.currentPage().getParameters().get('state');

}

 

Here is my pageblocksection in my page:

 

<apex:pageblockSection columns="2" Title="Donation Details" >
<apex:inputField value="{!Donation.Contact__c}"/>
Candidate:{!Candidate.Name}
<apex:inputField value="{!Donation.Donation_Amount__c}"/>
<apex:inputField value="{!Donation.Donation_Date__c}"/>
<apex:inputField id="state" value="{!Donation.Donation_State__c}"/>

</apex:pageBlockSection>

 

I would like to access the inputField with id=state in my customcontroller , how to do this?

 

Please help.

 

Thanks

Sai

Deepak Kumar ShyoranDeepak Kumar Shyoran

Hi saisai,

 

If I get your requirement properly then you nees to access the Donation.Donation_State__c in your controller you can perform it in following ways.

 

You just create a public property with get set in your controller like.

 

public String state {get;set;}

 

Now on visual forcepage you need to write a javascript function which call to a apex:action function in following way.

<apex:actionFunction name="stateInitilization" reRender = "none" >

<apex:param name="param1" value="" assignTo ="{!state}" />

<apex:actionfunction />

 

<apex:inputField id="state" value="{!Donation.Donation_State__c}" />

<script>

   var v= "{!Donation.Donation_State__c}"

   stateInitilization(v);

</script>

 

Hopefully by using above technique you will get Donation_State__c value in your controller state varible

 

Don't forget to give Kudos if this post helped you.

Mark my answer as a solution to your question if it solve your problem.

 

 

-----

Choudhary Deepak Shyoran

Salesforce Developer

 

 

sandeep@Salesforcesandeep@Salesforce

There is no need to access this Donation_state__c field by id you can just use it without id. becuase you alreadt binded Donation reference in Class and Page. 

 

Please let me know in case of query we are not getting properly