You need to sign in to do that
Don't have an account?

Set initial value of Multiselect list - Attempt to dereference a null object
Hi
On a VF page that produces a pdf report I have a multiselect list of users that i want to default to the logged in user if they have a particular profile, however, i am getting the error "Attempt to dereference a null object" on the following line:
surveyor.add(userinfo.getUserId());
The code im using is below, grateful for any pointers where im going wrong.
VF:
<apex:selectList id="Surveyors" size="1" title="Surveyor" value="{!surveyor}" multiselect="true" style="height:107px"> <apex:selectOptions value="{!Surveyors}"></apex:selectOptions> </apex:selectList>
Apex:
public List<String> surveyor; public List<String> getSurveyor() { List<Profile> profile = [Select id,Name from Profile Where Id=:userinfo.getProfileId() limit 1]; string userProfile = profile[0].Name; if(userProfile == 'Surveyor') { surveyor.add(userinfo.getUserId()); } return surveyor; }
Try this out -
All Answers
Try this out -
Hi,
We can create custom picklist in VF using SelectOption .you need to add value in selectOption list .
VF
<apex:selectList id="Surveyors" size="1" title="Surveyor" value="{!surveyor}" multiselect="true" style="height:107px">
<apex:selectOptions value="{!Surveyors}"></apex:selectOptions>
</apex:selectList>
Controller
public List<String> surveyor{get;set;}
public List<SelectOption> getSurveyors(){
List<SelectOption> options = new List<Selectoption>();
List<Profile> profile = [Select id,Name from Profile Where Id=:userinfo.getProfileId() limit 1];
string userProfile = profile[0].Name;
if(userProfile == 'Surveyor'){
options.add(new SelectOption(userinfo.getUserId(),userinfo.getUserId()));
}
return options;
}
Please let me know if u have any problem on same and if this post helps u plz give kudos by click on star at left.