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
Ralf WittenbergerRalf Wittenberger 

2 credentials on Trigger to lookup List

Hi, I have used a Trigger from here to add it to my needs, unfortunately, it seems, I can´t use 2 credentials for the Listlookup, or am i just missing something here?

Trigger ContactOnCases on Case (before insert, before update) {
List<String> Contact = new List<String>(); 
for (Case a:Trigger.new)
{
Contact.add(a.SuppliedEmail && a.Customer_Number_C__c);
}
    List <Contact> ContactList = [Select ID from Contact where  Email && Customer_Number__c  in :Contact ];
    for (Integer i = 0; i < Trigger.new.size(); i++)
        
if (Trigger.new[i].SuppliedEmail != null) {

    Trigger.new[i].ContactID = ContactList[i].ID; 
}
else
{
Trigger.new[i].ContactID = null;
}
}
Best Answer chosen by Ralf Wittenberger
ManojjenaManojjena
HI Ralf,

Please try with below code I am sure about your requirment I have just given one solution for your issue .
I may resolve your issue ,Please check with query whether you want the AND /OR condtion between your condtion .
Trigger ContactOnCases on Case (before insert, before update) {
	List<String> ContactEmail = new List<String>();
	List<String> Contactcustnum = new List<String>(); 
	for (Case a:Trigger.new){
		ContactEmail.add(a.SuppliedEmail );
		Contactcustnum.add(a.Customer_Number_C__c);
	}
    List <Contact> ContactList = [Select ID from Contact where  Email IN: ContactEmail OR Customer_Number__c  IN :Contactcustnum ];
    for (Integer i = 0; i < Trigger.new.size(); i++){
        if (Trigger.new[i].SuppliedEmail != null) {
			Trigger.new[i].ContactID = ContactList[i].ID; 
		}else{
			Trigger.new[i].ContactID = null;
		}
	}
}

 

All Answers

ManojjenaManojjena
HI Ralf,

Please try with below code I am sure about your requirment I have just given one solution for your issue .
I may resolve your issue ,Please check with query whether you want the AND /OR condtion between your condtion .
Trigger ContactOnCases on Case (before insert, before update) {
	List<String> ContactEmail = new List<String>();
	List<String> Contactcustnum = new List<String>(); 
	for (Case a:Trigger.new){
		ContactEmail.add(a.SuppliedEmail );
		Contactcustnum.add(a.Customer_Number_C__c);
	}
    List <Contact> ContactList = [Select ID from Contact where  Email IN: ContactEmail OR Customer_Number__c  IN :Contactcustnum ];
    for (Integer i = 0; i < Trigger.new.size(); i++){
        if (Trigger.new[i].SuppliedEmail != null) {
			Trigger.new[i].ContactID = ContactList[i].ID; 
		}else{
			Trigger.new[i].ContactID = null;
		}
	}
}

 
This was selected as the best answer
Ralf WittenbergerRalf Wittenberger
Hi Manoj,

thanks for your early reply. I have used this with a little changing, but it works. Thanks a lot!