You need to sign in to do that
Don't have an account?
Tyler McCarty
Account Type Dropdown search box
Hello, Im getting this error when trying to populate a dropdown box with the account types.
System.NullPointerException: Argument 1 cannot be null Class.AccountTypeController.getAccounts: line 13, column 1
Apparently 'Type' is a reserved word in apex but is also the API name of the Account field, Type. It won't return the field because of this. Any way around this besides changing the API name?
Apex code:
public class AccountTypeController
{
public string Account{get; set;}
public String sortOrder = 'Type';
public List<SelectOption> getAccounts()
{
List<SelectOption> AccountList = new List<SelectOption>();
for(Account act: [SELECT Name, Type, Website, BillingAddress
FROM Account])
AccountList.add(new SelectOption(act.Type, act.Type));
return AccountList;
}
public void sortByType()
{
this.sortOrder = 'Type';
}
}
vf code:
<apex:page controller="AccountTypeController">
<apex:form >
<apex:pageBlock title="Accounts">
<apex:pageBlockSection >
<apex:selectList value="{!Account}" size="1">
<apex:selectOption itemLabel="-Select Account Type-" itemValue="-Select-"/>
<apex:selectOptions value="{!Accounts}"/>
<apex:actionSupport event="onchange" reRender="pb" status="actStatusId"> </apex:actionSupport>
</apex:selectList>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
System.NullPointerException: Argument 1 cannot be null Class.AccountTypeController.getAccounts: line 13, column 1
Apparently 'Type' is a reserved word in apex but is also the API name of the Account field, Type. It won't return the field because of this. Any way around this besides changing the API name?
Apex code:
public class AccountTypeController
{
public string Account{get; set;}
public String sortOrder = 'Type';
public List<SelectOption> getAccounts()
{
List<SelectOption> AccountList = new List<SelectOption>();
for(Account act: [SELECT Name, Type, Website, BillingAddress
FROM Account])
AccountList.add(new SelectOption(act.Type, act.Type));
return AccountList;
}
public void sortByType()
{
this.sortOrder = 'Type';
}
}
vf code:
<apex:page controller="AccountTypeController">
<apex:form >
<apex:pageBlock title="Accounts">
<apex:pageBlockSection >
<apex:selectList value="{!Account}" size="1">
<apex:selectOption itemLabel="-Select Account Type-" itemValue="-Select-"/>
<apex:selectOptions value="{!Accounts}"/>
<apex:actionSupport event="onchange" reRender="pb" status="actStatusId"> </apex:actionSupport>
</apex:selectList>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Try the below code now it works fine:
vf code:
controller code: I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi