I have 2 queries in my code and result of 1st is used in 2nd query as below:
External_System_Mapping__c LeadProgram = [ SELECT Salesforce_Value__c FROM External_System_Mapping__c WHERE Mapping_Type__c = 'Program' AND External_System_Value__c =:application_program ]; List<Lead> matchingLeadsListWIProgram = [ Select Id, Status from Lead where isConverted = false and ((Program__c =: LeadProgram.Salesforce_Value__c) and ( (Email != null AND Email = :application_email) OR (MobilePhone != null AND MobilePhone = :application_mobile) OR (Email != null AND Email=:spjat_email) OR (MobilePhone != null AND MobilePhone =:spjat_mobile) )) ];
But sometimes 1st query is returning null and I get this error:
List index out of bounds: 0
Any suggestions to avoid this error?