You need to sign in to do that
Don't have an account?
I have an error while click on save button.
Hi there, i have an error while click on save button.
"System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!upload}' in component <apex:commandButton> in page aqthc:booking_funnel_settings: Class.aqthc.FileUploadController.upload: line 31, column 1".
<apex:page controller="FileUploadController">
<apex:sectionHeader title="Visualforce Example" subtitle="File Upload Example"/>
<apex:form enctype="multipart/form-data">
<apex:pageMessages />
<apex:pageBlock title="Upload a File">
<apex:pageBlockButtons >
<apex:commandButton action="{!upload}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection showHeader="false" columns="2" id="block1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="File Name" for="fileName"/>
<apex:inputText value="{!document.name}" id="fileName"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="File" for="file"/>
<apex:inputFile value="{!document.body}" filename="{!document.name}" id="file"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Description" for="description"/>
<apex:inputTextarea value="{!document.description}" id="description"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Keywords" for="keywords"/>
<apex:inputText value="{!document.keywords}" id="keywords"/>
</apex:pageBlockSectionItem>
<form action="/action_page.php">
Select your favorite color:
<input style="margin-left: 1px;" type="color" name="favcolor" value="#ff0000"/>
<input style="margin-left: 30px;" type="submit"/>
</form>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
===============================================================
public with sharing class FileUploadController {
public List<aqthc__Healthcare_Settings__c> objHSList {get;set;}
public Document document {
get {
if (document == null)
document = new Document();
return document;
}
set;
}
public PageReference upload() {
document.AuthorId = UserInfo.getUserId();
document.FolderId = UserInfo.getUserId(); // put it in running user's folder
try {
insert document;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));
return null;
} finally {
document.body = null; // clears the viewstate
document = new Document();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully'));
aqthc__Healthcare_Settings__c objHc = new aqthc__Healthcare_Settings__c();
objHc.Name = document.name;
//objHc.aqthc__Background_Color__c = document ;
//objHc.aqthc__Background_Image_URL__c = document.FolderId;
objHSList.add(objHc);
insert objHSList;
return null;
}
}
Please help!
Thanks
"System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!upload}' in component <apex:commandButton> in page aqthc:booking_funnel_settings: Class.aqthc.FileUploadController.upload: line 31, column 1".
<apex:page controller="FileUploadController">
<apex:sectionHeader title="Visualforce Example" subtitle="File Upload Example"/>
<apex:form enctype="multipart/form-data">
<apex:pageMessages />
<apex:pageBlock title="Upload a File">
<apex:pageBlockButtons >
<apex:commandButton action="{!upload}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection showHeader="false" columns="2" id="block1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="File Name" for="fileName"/>
<apex:inputText value="{!document.name}" id="fileName"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="File" for="file"/>
<apex:inputFile value="{!document.body}" filename="{!document.name}" id="file"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Description" for="description"/>
<apex:inputTextarea value="{!document.description}" id="description"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Keywords" for="keywords"/>
<apex:inputText value="{!document.keywords}" id="keywords"/>
</apex:pageBlockSectionItem>
<form action="/action_page.php">
Select your favorite color:
<input style="margin-left: 1px;" type="color" name="favcolor" value="#ff0000"/>
<input style="margin-left: 30px;" type="submit"/>
</form>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
===============================================================
public with sharing class FileUploadController {
public List<aqthc__Healthcare_Settings__c> objHSList {get;set;}
public Document document {
get {
if (document == null)
document = new Document();
return document;
}
set;
}
public PageReference upload() {
document.AuthorId = UserInfo.getUserId();
document.FolderId = UserInfo.getUserId(); // put it in running user's folder
try {
insert document;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));
return null;
} finally {
document.body = null; // clears the viewstate
document = new Document();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully'));
aqthc__Healthcare_Settings__c objHc = new aqthc__Healthcare_Settings__c();
objHc.Name = document.name;
//objHc.aqthc__Background_Color__c = document ;
//objHc.aqthc__Background_Image_URL__c = document.FolderId;
objHSList.add(objHc);
insert objHSList;
return null;
}
}
Please help!
Thanks
I think you have assigned the userId to the folder.
Instead of UserInfo.getUserId() assign any folderid.
When inserting objHSList record document.name is null.Try to give folderId when inserting document.
objHc.Name = document.name;
public PageReference upload() {
document.name='test';
document.AuthorId = UserInfo.getUserId();
document.FolderId = UserInfo.getUserId(); // put it in running user's folder
}
insert document;
Thanks,
SEKAR RAJ
Thanks for your reply. I will look into this if its is work.
Thanks
try adding this in the Upload function,
objHSList = new List<aqthc__Healthcare_Settings__c>();
Thank You,
Rajesh Adiga P.
Adding this in the Upload function is not working,
objHSList = new List<aqthc__Healthcare_Settings__c>();
Please help .