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
Ashu sharma 38Ashu sharma 38 

Trigger concept


 Object Name                           Field Names
Application                               Name,Pancard ,Phone
BlacKList                                    Name,Pancard,phone
a. When ever we are inserting new Application it has to check pancard no of the new application record is 
in the Blakc list or not .
b.If the pancard of the Appliction is in the blacklist object then update the blackList phone with new application phone no  and throw error
 Object Name                           Field Names
Application                               Name,Pancard ,Phone
BlacKList                                    Name,Pancard,phone
a. When ever we are inserting new Application it has to check pancard no of the new application record is 
in the Blakc list or not .
b.If the pancard of the Appliction is in the blacklist object then update the blackList phone with new application phone no  and throw error
v varaprasadv varaprasad
Hi Nitish,

Please find sample code below  : 
 
trigger checkPanNo on Application__c(before insert){
list<string> panNnos = new list<string>();


for(Application__C ap : trigger.new){
  if(ap.Panno_c != null){
    panNnos.add(ap.Panno_c );
  
  }
}

if(panNnos != null){
   list<BlacKList__c> blks = [select id,name,phone,panno_c from BlacKList__c where panno_c in : panNnos ];

}

if(blks.size() > 0){
    for(BlacKList__c b : blks){
	  for(Application__C ap : trigger.new){
	       if(b.panno_c == ap.panno_c){
		   
		      ap.addError('Panno already exists with following phone number'+b.phone);
		   }
	  
	  }
	
	}


}



}

I have not tested the above code may you will get some syntactical errors.


 Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For Project Support and training: varaprasad4sfdc@gmail.com




 
DMGmefullDMGmefull
Hi Nitish,

Please try the below code and mark as Best Answer.

trigger AppBlack on Application__c(before insert){
list<Decimal> panNnos = new list<Decimal>();
    
for(Application__c ap : trigger.new){
  if(ap.Pancard__c != null){
    panNnos.add(ap.Pancard__c );
  
  }
}

if(panNnos != null){
   list<BlackList__c> ban = [select id,name,Phone__c,Pancard__c from BlackList__c where Pancard__c in : panNnos ];

if(ban.size() > 0){
    for(BlackList__c b : ban){
      for(Application__c ap : trigger.new){
           if(b.Pancard__c == ap.Pancard__c){
           
              ap.addError('Pancard already exists with following phone number'+b.Phone__c);
                   }    
                }  
             }
        }
   }
}

Regards,
Asad Shaikh