function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
T-007T-007 

Amazing checkbox issue

When I click 'save' button without check the  checkbox(terms and conditions) i.e.., not selected, then error message(not pop-up/dialog window) ApexPages.addMessage(new Appositeness's(ApexPages.Severity.ERROR, 'Please check the Terms and Conditions'));  must come.

 

Note: there is no filed in the object for this. I created in Visual Force page, (value="{!termsCheckBox}" ) action={!save}

I want to know how to write in apex class the functionality in the save button

yvk431yvk431

You have to incorporate <apex:pageMessage/> and then You have to use adderror conditionally based on your checkbox vaues in the save method of yours and return null

 

 

if(chkbox != true){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Message'));
return null;
}

 

 

 

--yvk

 

 

 

T-007T-007

I did exactly like that, but still not working. Can be more specific about check box name and value={!   } 

tukmoltukmol

You can do something like this:

 

supposed you have this VF page:

<apex:page controller="TesterController">
    <apex:pageMessages escape="false"></apex:pageMessages> 
    <apex:form >
        <p>You must agree to these terms and conditions... blah... blah... and blah!</p>
        <!--  the agree check box -->
        <apex:selectCheckboxes value="{! termsCheckBox}" >
            <apex:selectOption itemLabel="I agree" itemValue="1"/>
        </apex:selectCheckboxes>
        <apex:commandButton value="Continue" action="{! save"/>
    </apex:form>
</apex:page>

 then the corresponding controller would be like this:

public with sharing class TesterController {
	public TesterController() {
		this.termsCheckBox = new String[]{};
	}

	public String[] termsCheckBox {
		get; set;
	}	
	
	public PageReference save() {
		
		if (this.termsCheckBox.size()==0) {
			ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please check the Terms and Conditions'));
			return null;		
		}
		
		return new PageReference('http://salesforce.com'); //replace with your landing page
	}
}

 

T-007T-007

Thanks tukmol

I solved the issue  in another way.. with less number of lines. Anyway thank you for being so kind and helpful

DhilibanThangavelDhilibanThangavel

Thanks Tukmol... your post really useful..