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
swapna muthiyaluswapna muthiyalu 

validate contact and account id

set<string>mEmpId = new set<string>();
set<string>hEmpId = new set<string>();

if (mEmpId .size() == 0 && hEmpId.size() > 0){

list<Contact> mgrHrRecs = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];

} else if(hEmpId.size() == 0 && mEmpId.size() > 0){

list<Contact> mgrHrRecs = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];

}else if (mEmpId.size() > 0 && hEmpId.size() > 0)


{list<contact>listcon = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexm__c = ‘yes’) or (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];} ;

The requirement is i have account say Burlington textiles, i have many contacts and they have empid__c. similar way there are many accounts and related contacts with empid__c. but the empid__c may be same for many contacts. now i want to validate that the reportsto field in contact has the same contact which belongs to the same account,which is not validated in the above code. for example i have jack as contact who belongs to the account burligton, has Peter in the report to field, now i have to validate that peter also belongs to the burlington account.
Pradeep SinghPradeep Singh
Hi, refer below code if your reportsTo field is of Lookup type.
List<contact> validContacts = new List<contact>();
List<contact> InValidContacts = new List<contact>();

for(Contact con : [select id,name,account.name,reportsTo.account.name from contact where accountId != Null AND  reportsTo != Null]{
     if(con.account.name == con.reportsTo.account.name){
          validContacts .add(con);
      }
      else{
            invalidContacts.add(con);
       }
}

 
swapna muthiyaluswapna muthiyalu
Hi Pradeep ,

How to do this by using map of map like account and contact ?