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
Revati BhavsarRevati Bhavsar 

Variable does not exist error

I have a custom object with API name CustBusinessPro__Applicant__c.Its field is CustBusinessPro__PAN__c.My code to access this field is:
public with sharing class PAN_Check

{

    public CustBusinessPro__Applicant__c applicant{get;set;}

    List <String> panCardList{get;set;}

    String PanFormat{get;set;}

    public PAN_Check()

    {

        applicant = new CustBusinessPro__Applicant__c();

        panCardList = new List<String> ();

        PanFormat = '[A-Z]{5}[0-9]{4}[A-Z]{1}';

    }

     

    public void PanCheck()

    {
        panCardList.add(applicant.CustBusinessPro__PAN__c);
        System.debug('----------------------' + panCardList);
Getting an error that  variable applicant.CustBusinessPro__PAN__c does not exist.Can anyone help?

Thanks in advance!!
Richard Jimenez 9Richard Jimenez 9
Hi Revati,

Do you have the field name correct? CustBusinessPro__PAN__c - with two double underscores between Pro and PAN - is this correct?

Do you get the error when saving the class or when it is running? What line no. is the error on?
Have you pasted in the full class code?

You may also want to check the string is blank (null) before adding to your list.

Thanks,
Richard.
Revati BhavsarRevati Bhavsar
Hi this is my complete code:
public with sharing class PAN_Check

{

    public CustBusinessPro__Applicant__c applicant{get;set;}

    List <String> panCardList{get;set;}

    String PanFormat{get;set;}

    public PAN_Check()

    {

        applicant = new CustBusinessPro__Applicant__c();

        panCardList = new List<String> ();

        PanFormat = '[A-Z]{5}[0-9]{4}[A-Z]{1}';

    }

     

    public void PanCheck()

    {
        panCardList.add(applicant.CustBusinessPro__PAN__c);
        System.debug('----------------------' + panCardList);
        for(String panCard : panCardList)
        {
            pattern MyPattern = pattern.compile(PanFormat);
            matcher MyMatcher = MyPattern.matcher(panCard);

            if(MyMatcher.matches())

            {

                System.debug(panCardList + '---------------Valid');

            }

            else

            {

                System.debug(panCardList + '---------------Invalid');

            }

        }

    }

}
The class is getting saved successfully.When i execute it in the Developer Console i get an error Line: 28, Column: 25
Variable does not exist: applicant.CustBusinessPro__PAN__c.User-added image
Pankaj_GanwaniPankaj_Ganwani
Hi,

Are you logged in with the system admin profile? If not, then check for the field level security for this field in the profile you are logged in with.
Revati BhavsarRevati Bhavsar
Hi,
Yes the field is visible to the System Administrator in the field level security.
Revati BhavsarRevati Bhavsar
Hi,
I am calling the function PanCheck() from the controller class of the VF page in the PageReference Save once the upsert function is executed.
public with sharing class ApplicantController {

PAN_Check p = new PAN_Check();
........................
 public PageReference save() {
           
           
           upsert applicant;
           try{
     p.PanCheck();
}
catch(Exception ex) {   
     system.debug('***Exception***: ' + ex);
}
          
           
           return new PageReference('/' + applicant.Id);
         
        
    }
Pankaj_GanwaniPankaj_Ganwani
Hi,

Just try to use PAN__c instead of using CustBusinessPro__PAN__c.
Revati BhavsarRevati Bhavsar
Hi,
I tried using that too.The class is getting saved but when i execute it as execute highlighted in the Execute Anonymous Window it gives error that variable applicant.PAN__c  does not exist.