1

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>

     <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;
    }
    set;
}

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

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>();
    insertList.add(SurveyApproval);
    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(); 
        p.setRedirect(false);
        return null; 

}

Can someone help me please?

5
  • Can you share your controller code as well? Commented Oct 7, 2018 at 10:19
  • Just in a pagereference method system.debugging to access Survey. Commented Oct 7, 2018 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. Commented Oct 7, 2018 at 10:45
  • Yes I have apex form. Please find my updated question. Sorry for late reply. Commented Oct 7, 2018 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 Commented Oct 7, 2018 at 13:39

1 Answer 1

1

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.