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
StephenCraneStephenCrane 

Validation Rule For Visual Force Page Button

Hey there, I got some help for this issue here (https://success.salesforce.com/answers?id=9063A000000tCRxQAM)- but still, don't fully understand how to do this. But I have the below code for a button that grabs parts of the Onboarding record to create another Onboarding record (of a specific record type).
<apex:page standardController="Onboarding__c" > <flow:interview name="Create_Billing_Onboarding" finishLocation="/{!Onboarding__c.Id}"> <apex:param name="AccountID" value="{!Onboarding__c.Account__c}" /> <apex:param name="AccountName" value="{!Onboarding__c.Account__r.Name}" /> <apex:param name="PricingTier" value="{!Onboarding__c.Opportunity__r.Pricing_Tier__c}" /> <apex:param name="OpportunityID" value="{!Onboarding__c.Opportunity__c}" /> <apex:param name="DateOfSale" value="{!Onboarding__c.Opportunity__r.CloseDate}" /> <apex:param name="ChildrenOnSubsidy" value="{!Onboarding__c.Children_on_subsidy__c}" /> <apex:param name="HowDoTheyCurrentlyBill" value="{!Onboarding__c.How_Do_They_Currently_Bill_Parents__c}" /> <apex:param name="HowAreTuitionFeesCalculated" value="{!Onboarding__c.How_are_tuition_fees_calculated__c}" /> <apex:param name="HowFrequentlyAreParentsBilled" value="{!Onboarding__c.How_frequently_are_parents_billed__c}" /> <apex:param name="HowManyChildrenOnSubsidy" value="{!Onboarding__c.How_many_children_on_subsidy__c}" /> <apex:param name="IfNoWhy" value="{!Onboarding__c.If_No_Why__c}" /> <apex:param name="InterestedInInvoicing" value="{!Onboarding__c.Interested_in_invoicing_through_Himama__c}" /> <apex:param name="WillRecordSubsidyOutsideHiMama" value="{!Onboarding__c.Will_they_record_subsidy_outside_Himama__c}" /> <apex:param name="BillingNotes" value="{!Onboarding__c.Billing_Notes__c}" /> </flow:interview> </apex:page>

And then triggers a flow. We want a validation rule that if some of the parts are bull then they get a message/pop up whatever to say it needs to be filled - like a Validation Rule.

I tried adding this piece of code to it and various tinkerings but no such luck.
<apex:pagemessages>
    if ( Onboarding__c.Interested_in_invoicing_through_Himama__c == False) {
       Onboarding__c.Interested_in_invoicing_through_Himama__c.addError( 'You must enter a value');

}
  </apex:pagemessages>

There are about 6 fields that we need to have to be required for clicking this button. Thanks!

 
Dushyant SonwarDushyant Sonwar
Hi Stephen ,

Try with this one ,

You can change the error icon size with 1-3 , 3 being the highest.
<apex:page standardController="Onboarding__c" >

  <apex:outputPanel rendered ="{!NOT(Onboarding__c.Interested_in_invoicing_through_Himama__c)}" >
	<apex:pageMessage summary="You must enter a value" severity="error" strength="3" />
  </apex;outputPanel>
    <apex:outputPanel rendered = "{!Onboarding__c.Interested_in_invoicing_through_Himama__c}" >
		<flow:interview name="Create_Billing_Onboarding" finishLocation="/{!Onboarding__c.Id}">
			<apex:param name="AccountID" value="{!Onboarding__c.Account__c}" />
			<apex:param name="AccountName" value="{!Onboarding__c.Account__r.Name}" />
			<apex:param name="PricingTier" value="{!Onboarding__c.Opportunity__r.Pricing_Tier__c}" />
			<apex:param name="OpportunityID" value="{!Onboarding__c.Opportunity__c}" />
			<apex:param name="DateOfSale" value="{!Onboarding__c.Opportunity__r.CloseDate}" />
			<apex:param name="ChildrenOnSubsidy" value="{!Onboarding__c.Children_on_subsidy__c}" />
			<apex:param name="HowDoTheyCurrentlyBill" value="{!Onboarding__c.How_Do_They_Currently_Bill_Parents__c}" />
			<apex:param name="HowAreTuitionFeesCalculated" value="{!Onboarding__c.How_are_tuition_fees_calculated__c}" />
			<apex:param name="HowFrequentlyAreParentsBilled" value="{!Onboarding__c.How_frequently_are_parents_billed__c}" />
			<apex:param name="HowManyChildrenOnSubsidy" value="{!Onboarding__c.How_many_children_on_subsidy__c}" />
			<apex:param name="IfNoWhy" value="{!Onboarding__c.If_No_Why__c}" />
			<apex:param name="InterestedInInvoicing" value="{!Onboarding__c.Interested_in_invoicing_through_Himama__c}" />
			<apex:param name="WillRecordSubsidyOutsideHiMama" value="{!Onboarding__c.Will_they_record_subsidy_outside_Himama__c}" />

		</flow:interview>
	</apex:outputPanel>
</apex:page>

for checking all the fields , you can use AND() function 

it will look like this AND(boolean field 1 , boolean field 2 , and so on)

Hope this helps!
Dushyant SonwarDushyant Sonwar
There is a typo error . 
Please replace 
</apex;outputPanel>

to
</apex:outputPanel>

​​​​​​​
Dushyant SonwarDushyant Sonwar
Also add lightningstylesheets attribute to true , it will match with lightning UI

<apex:page standardController="Onboarding__c"  lightningstylesheets= "true">
StephenCraneStephenCrane
Hey Dushyant, thanks so much for the help, but there is still some issues.  (Also we're in Classic, but I appreciate the update).  When I had it as NOT I got an error saying it was expecting boolean, but got text. When I changed it to ISNULL, it gave me an error but still created the object through a flow (screenshot attached). Let me know your thoughts, thanks!

User-added image
Dushyant SonwarDushyant Sonwar
<apex:page standardController="Onboarding__c" >

  <apex:outputPanel rendered ="{!NOT(Onboarding__c.Interested_in_invoicing_through_Himama__c ==true)}" >
	<apex:pageMessage summary="You must enter a value" severity="error" strength="3" />
  </apex;outputPanel>
    <apex:outputPanel rendered = "{!Onboarding__c.Interested_in_invoicing_through_Himama__c == true}" >
		<flow:interview name="Create_Billing_Onboarding" finishLocation="/{!Onboarding__c.Id}">
			<apex:param name="AccountID" value="{!Onboarding__c.Account__c}" />
			<apex:param name="AccountName" value="{!Onboarding__c.Account__r.Name}" />
			<apex:param name="PricingTier" value="{!Onboarding__c.Opportunity__r.Pricing_Tier__c}" />
			<apex:param name="OpportunityID" value="{!Onboarding__c.Opportunity__c}" />
			<apex:param name="DateOfSale" value="{!Onboarding__c.Opportunity__r.CloseDate}" />
			<apex:param name="ChildrenOnSubsidy" value="{!Onboarding__c.Children_on_subsidy__c}" />
			<apex:param name="HowDoTheyCurrentlyBill" value="{!Onboarding__c.How_Do_They_Currently_Bill_Parents__c}" />
			<apex:param name="HowAreTuitionFeesCalculated" value="{!Onboarding__c.How_are_tuition_fees_calculated__c}" />
			<apex:param name="HowFrequentlyAreParentsBilled" value="{!Onboarding__c.How_frequently_are_parents_billed__c}" />
			<apex:param name="HowManyChildrenOnSubsidy" value="{!Onboarding__c.How_many_children_on_subsidy__c}" />
			<apex:param name="IfNoWhy" value="{!Onboarding__c.If_No_Why__c}" />
			<apex:param name="InterestedInInvoicing" value="{!Onboarding__c.Interested_in_invoicing_through_Himama__c}" />
			<apex:param name="WillRecordSubsidyOutsideHiMama" value="{!Onboarding__c.Will_they_record_subsidy_outside_Himama__c}" />

		</flow:interview>
	</apex:outputPanel>
</apex:page>
Stephen ,

it means that the field is not boolean but actually is of text type

 if it is text then you have to enclosed in single quotes 
{!Onboarding__c.Interested_in_invoicing_through_Himama__c =='true'}

Hope this helps!