I have below pageblocksectionitem in VF Page.

 <apex:pageBlockSection showHeader="false" columns="2" id="blockseciframe" >
                <apex:pageBlockSectionItem >

      <apex:outputLabel value="Survey Name"/>
      <apex:inputText value="{!Survey}" id="SurveyName"/>

     <apex:pageBlockSectionItem >

I have simply put getter and setter for the variable Survey in my with sharing class controller.

public String Survey{get;set;}

Unfortunately when I try accessing it from a pagereference method, it prints null in system debug log.

I am having apex form here. Please find the whole of controller snippet here.

public Attachment attachment {
    get {
    if (attachment == null)
    attachment = new Attachment();
    return attachment;

public Survey__c SurveyApproval{
    get {
    if (SurveyApproval == null)
    SurveyApproval = new Survey__c ();
    return SurveyApproval;

public PageReference upload() {

    SurveyApproval.Name = attachment.Name;
   system.debug('Survey@' + Survey);
   system.debug('Description@' + Description);
   system.debug('selectedStatus@' + selectedStatus);
    SurveyApproval.SurveyName__c = Survey;
    attachment.Description = Description;
    SurveyApproval.Approval__c = selectedStatus;

    SurveyApproval.ApprovalBy__c = UserInfo.getUserId();

    system.debug('SurveyApproval@' + SurveyApproval);
    attachment.OwnerId = UserInfo.getUserId();

    attachment.IsPrivate = true;
    attachment.ContentType = 'text/csv';
    List<Survey__c> insertList = new List<Survey__c>();
    system.debug('insertList@' + insertList);

    if(SurveyApproval.Id==null && attachment.body!=null)
    {Database.SaveResult[] srList = Database.insert(insertList);

        for (Database.SaveResult sr : srList)
            ApprovalSurveyId = sr.getId();

    attachment.ParentId = ApprovalSurveyId ;
      system.debug('attachment@' + attachment);
    try {

      insert attachment;
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
      return null;
    } finally {
      attachment = new Attachment(); 

    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
PageReference p = Apexpages.currentPage(); 
        return null; 


Can someone help me please?

  • Can you share your controller code as well? – Mahmood Oct 7 '18 at 10:19
  • Just in a pagereference method system.debugging to access Survey. – Testing_SFDC Oct 7 '18 at 10:39
  • 1
    Do you have a <apex:form> wrapping your inputText? Also in it will be easier to identify the issue if you provide code snippets for the server call (command button / command link etc) and apex action method you are calling. – Ranga Oct 7 '18 at 10:45
  • Yes I have apex form. Please find my updated question. Sorry for late reply. – Testing_SFDC Oct 7 '18 at 12:12
  • @Testing_SFDC thanks for updating the question. Is the command button which you are using to call upload method having a renderer attribute defined? If you could post that as well it’ll be useful – Ranga Oct 7 '18 at 13:39

I think, the command button having attribute immediate=true. That's why you are getting null value in method. Remove this attribute from command button.

This question has been asked already here: apex:InputText value not setting on the controller variable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.