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

Error to through before save button.



I have created a class called "credit check" and i have a visual force page for this.I want to create a condition under which if the fields are empty and when i try to save it,should through an error for that condition.


As i have written the condition in  class credit check  and i have VF page and connect it to the controller creditcheck.cls.But here i am facing the issue,that the record is saving  and at the top of Save button the error comes up and when i edit it, then it shows me the field which all i have not filled.What should i do to through the error before the record is saved.


I know it can be done by the trigger(before insert, before update).But i want this to be done in the class.


Help me






Is there a reason why you can't use the required attribute on the inputfields themselves?  That would be handled by the platform rather than you having to write custom code.


You can use salesforce class 'errorMsg' to handle this functionality.


Tryout the sample code given below :


            <div class="errorMsg" style="display:none">

            <strong> Error: </strong>You must enter a value



Hope this helps.




yes i am trying to use Required attribute for this but some how when i am clicking save,it is not saving and the error message is " 

ErrorError: Unknown property 'Credit_Check__cStandardController.Oppr'



The condition is this

If "Business Type" = Limited Company/Plc/Charity & New Supplier = Eon & the "Product" not equal to "Bespoke" then the following fields must be completed:


Account Name
Company Registered Number or Charity Number
Date of Incorporation
Company Registered Address
Billing Address


<apex:pageBlockSectionItem labelStyle="width: 300px" dataStyle="width: 200px"> 
                    <apex:outputLabel value="Billing Address" for="CCheck.Billing_Address__c" /> 
                    <apex:inputtextarea id="msgpost" cols="24" rows="4"  value="{!CCheck.Billing_Address__c}" required="{!AND(Oppr.New_Supplier__c == 'Eon' , Oppr.Product_Name__c != 'Bespoke Price')}" /> 





I can't see why that code would cause that save error. When I've hit unknown property errors in the past, it normally means I've misspelled the field name.