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
DbjensenDbjensen 

Do I need 2 queries?

Hello - Hoping to get help with this query. When a lead is created and if it has either a Core number or a PC Account Id number, I look for an account with that matching core number or pc Id. 

The problem with this query is, if a lead had a core number but no pc id, the query returns a non matching account because it returns any account that has no pc id. 

Do I need 2 different queries? One that looks for Core Number and another that looks for PC ID?

acctList = [SELECT Id, Core_Number__c, PC_Account_Id__c FROM Account WHERE Core_Number__c = :coreNumberTextList 
                            OR PC_Account_Id__c = :pcAccountIdList LIMIT 1];
Best Answer chosen by Dbjensen
Jitendra Singh ShahiJitendra Singh Shahi
Hi, 

you can try to put queries in conditions or you can try this.
 
acctList = [SELECT Id, Core_Number__c, PC_Account_Id__c FROM Account WHERE (Core_Number__c != '' AND Core_Number__c = :coreNumberTextList ) OR (PC_Account_Id__c != '' AND PC_Account_Id__c = :pcAccountIdList) LIMIT 1];



Let me know if you have any issue and if it solves your problem please choose it as the best answer as it will help other having same problem.

All Answers

Jitendra Singh ShahiJitendra Singh Shahi
Hi, 

you can try to put queries in conditions or you can try this.
 
acctList = [SELECT Id, Core_Number__c, PC_Account_Id__c FROM Account WHERE (Core_Number__c != '' AND Core_Number__c = :coreNumberTextList ) OR (PC_Account_Id__c != '' AND PC_Account_Id__c = :pcAccountIdList) LIMIT 1];



Let me know if you have any issue and if it solves your problem please choose it as the best answer as it will help other having same problem.
This was selected as the best answer
DbjensenDbjensen
Hi Jitendra - This is just what I need. Thanks so much.