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
akshay desai 9akshay desai 9 

how to check if lightning field is not null in apex controller i dont want to check this into a vf page

Deepali KulshresthaDeepali Kulshrestha
Hi Akshay,

I've gone through your requirement and you can refer below code to know how to validate in apex controller:VF Page:--->

<apex:pageBlock title="Insert Account"  id="theblock">
         
            <apex:pageblocksection columns="1" id="fields">
                
                <apex:inputField value="{!acc.Name}" id="name" /><br/>
                <apex:inputField value="{!acc.Phone}" id="phone" /><br/>
                
                
</apex:pageblocksection>

Apex Controller--->

public class ConfirmAccountInsertion {
    
    public Account acc{get;set;}

    public void saveRecord()
    {
       
        if((acc.Name!=null || acc.Name!='' ) && (acc.Phone!=null || acc.Phone!='')
           {
             insert acc;
           }
    }
}


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com