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?
<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.