I want to pass checkbox value in parameter so when I am trying to use checkboxval= Boolean.valueOf(Apexpages.currentPage().getParameters().get(checkboxval)); the null pointer exception is firing on this line. While previewing the page it is showing this error

Controller :

public class controllercls {
    public Boolean checkboxval;
    public controllercls(ApexPages.StandardController controller) {
        record = (Opportunity) controller.getRecord();
        checkboxval = Boolean.valueOf(Apexpages.currentPage().getParameters().get('checkboxval')); // here I am getting Argument cannot be null exception

    public PageReference method1() {
        PageReference pr = new PageReference('/apex/otherpage?checkboxval='


VF page:

<apex:page standardController="Opportunity" extensions="controllercls">
    <apex:inputField value="{!Opportunity.checkboxval__c}" />

2 Answers 2


Boolean.valueOf throws NullPointerException when the parameter is null. You need to check for null first:

String checkboxvalParam = ApexPages.currentPage().getParameters().get('checkboxval');
if(checkboxvalParam != null) {
    checkboxval = Boolean.valueOf(checkboxvalParam);

Or, depending on your preference, you might just assign a value based on if it's true (or false, whatever you prefer):

String checkboxvalParam = ApexPages.currentPage().getParameters().get('checkboxval');
checkboxval = checkboxvalParam == 'true';

If you are accepting any values from URL parameter where checkboxval is a key then use within the single quotes

checkboxval = Boolean.valueOf(Apexpages.currentPage().getParameters().get('checkboxval')); 

Without the quote, it is trying to take dynamic value which you have declared as

public Boolean checkboxval;

And, at the time of accessing the value in getParameters, it is null. That's why you are facing NullPointer exception.

  • I added quotes but still it is showing same error
    – Learner
    Jul 26, 2017 at 0:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .