You need to sign in to do that
Don't have an account?
degmo
Help with SOQL - Match records of Account Object
All,
I have a total of 15 custom fields on the account object that I need to use to compare to account records with each other. A few of the fields are: balance, total_value, property_value. My requirement is that for a given account, I need find existing accounts that match these values. If the value is blank or null, it should be skipped.
I have a total of 15 custom fields on the account object that I need to use to compare to account records with each other. A few of the fields are: balance, total_value, property_value. My requirement is that for a given account, I need find existing accounts that match these values. If the value is blank or null, it should be skipped.
List<Account> matchingAccounts = new List<Account>(); List<Account> vipAccount = [SELECT Id, balance__c, total_value__c, property_value__c, FROM Account WHERE Id = 'xxxxxxxxxxxxx' LIMIT 1) if(!vipAccount.isEmpty()) { Account currentAccount = vipAccount[0]; matchingAccounts = [SELECT Id FROM Account Where balance__c =:currentAccount.balance__c && total_value__c =:currentAccount.total_value__c && property_value__c =:currentAccount.total_value__c]; }Now, if any of the fields in vipAccount are null, I don't want to use them for matching. I only want to match on non-null values. Any thoughts/ideas on how I can achieve that?
You have to individually do a null check on all the fields
Also, Apex does have a method called isBlank in the String class to return true if the specified String is white space, empty (‘’), or null, otherwise, it will return false. So simply we can check like below
I recommend reviewing this blog post to learn more
Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you
All Answers
You have to individually do a null check on all the fields
Also, Apex does have a method called isBlank in the String class to return true if the specified String is white space, empty (‘’), or null, otherwise, it will return false. So simply we can check like below
I recommend reviewing this blog post to learn more
Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you