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
Shekhar AgarwalShekhar Agarwal 

I have created a custom object Student Master and whenever I am inserting a new record in Student Master, it has to check pan card number in another custom object and if it is found then show a warning message on the page that "PA

I have created a custom object Student Master and whenever I am inserting a new record in Student Master, it has to check pan card number in another custom object "Black Listed Candidate" and if it is found then show  a warning message on the page that "PAN card is BlackListed" on Saving the record. This message needs to be shown in VisualForce page and then that page needs to be called in Custom object.
My VFP is getting called but message is not coming. Please help me for this.
Britto Fernandez 2Britto Fernandez 2
Please share your current code.
Shekhar AgarwalShekhar Agarwal
Britto Fernandez2, sharing my current code.
public class BlackListingChecking {
    
    ApexPages.StandardController stdCtrl;

    public BlackListingChecking(ApexPages.StandardController controller) {
        stdCtrl = controller;

    }

    public static list<Black_Listed_Candidate__c> PANList = new list<Black_Listed_Candidate__c>();
    public static list<Black_Listed_Candidate__c> newPhone = new list<Black_Listed_Candidate__c>();
    
    public static void CheckPANCard(List<Student_Master__c> StudentRecord ){
       PANList = [select PAN__c from Black_Listed_Candidate__c ];
       system.debug('Pan List: '+ PANList) ;
        for(Student_Master__c student: StudentRecord){
            for(Black_Listed_Candidate__c PAN : PANList){
                
                if(student.PAN_Card_Number__c == PAN.PAN__c){
                  PAN.Phone__c = student.Phone__c;
                  newPhone.add(PAN);        
            } 
            }  
        }
        if(newPhone.size()>0){
            
            update newPhone; //Updating latest phone number in Black_Listed_Candidate__c Custom Object.
            
            //Updating field Background_Check_Status__c in student Master Custom Object when PAN card is blacklisted.
            for(Student_Master__c studentErrorMsg: StudentRecord){
                studentErrorMsg.Background_Check_Status__c = 'Candidate is blacklisted.We can not Hire!';
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'PAN Card BlackListed! Candidate can not be hired'));
               // studentErrorMsg.addError('PAN Card BlackListed! Candidate can not be hired!!');
            }
        }
 
    }
        public PageReference save()
    {
        PageReference pageRef = ApexPages.CurrentPage();
        if(newPhone.size()>0){
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.WARNING,'PAN Card BlackListed! Candidate can not be hired');
        ApexPages.addMessage(myMsg);
        }      
        stdCtrl.save();
        return null;
    } 
}
----------------------VFP Code--------------------
<apex:page standardController="Student_Master__c" extensions="BlackListingChecking">
<apex:form >
<apex:pageBlock >
<apex:messages />
</apex:pageBlock>
</apex:form>
</apex:page>
 
Shekhar AgarwalShekhar Agarwal
Please help me on this.