How to get the apex inputfield value in the controller?

286    Asked by ClareMatthews in Salesforce , Asked on Mar 6, 2023
I am trying to store value in an object using:

in the controller I am doing this:

public Expense_Object__c VS {get;set;}
public PageReference saveAndReturn()
{
        system.debug('Value is:'+VS.Total_Amount__c);
}

I am trying to fetch value here but neither data is getting inserted nor I am getting any value?

Answered by David EDWARDS

To get apex inputfield value in controller-


  public Expense_Object__c VS1 {get;set;}//This I was using already
public SaveAndReturnController(ApexPages.StandardController controller)//This 
is new
{
 VS = new Expense_Object__c();
 this.controller = controller;
}
public PageReference saveAndReturn()
{
system.debug('X is:'+VS.Vegetable_Amount__c);
PageReference cancel = new
PageReference(ApexPages.currentPage().getHeaders().get('Referer'));
insert VS;//introduced this insert
//controller.save(); I was using this previously so commented
return cancel;
}


Your Answer

Interviews

Parent Categories