Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
ISBLANK(FieldAPIName)
<apex:page controller="FieldnotEmptycontrl"> <apex:form > <apex:pageBlock > <apex:pageMessages /> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="save" action="{!save}"/> </apex:pageBlockButtons> <apex:pageBlockSection > <apex:inputField value="{!s.First_name__c}" required="true"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
public with sharing class FieldnotEmptycontrl { public customer__c s { get; set; } public FieldnotEmptycontrl (){ s=new customer__c(); } public pagereference save() { if(s.First_name__c !=null) { insert s; pagereference pr=new pagereference ('https://ap1.salesforce.com/'+s.id); return pr; } else { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Account number')); return null; } } }
There are many ways to achieve this. Listing few of them :
1) You can create a validation rule like given below :
2) Mark the field as required while creating the field.
3) Mark the field as required on page layout,
4) Keep a check in before insert / before update trigger.
You can use salesforce standard functionality for above requirement.
use validation rule. following is a example.
Error condition formula - ISBLANK(fieldApiName)
Please check the below sample code.
Visualforce page
Controller
Output:
Hope this helps you!
Best Regards,
Jyothsna