+ Start a Discussion

SOQL query on two unrelated objects

We have two objects, one cusotm and and one OOTB and both are not related but they have one field which will have same values.

How can we build a SOQL query for this ? Is this even possible ?

Ajay K DubediAjay K Dubedi
Hi Desai,
Try the following code:
public class TestStringSame {
    public static void check() {
        List<Account> accList = new List<Account>();
        Set<String> uniqueFieldSet = new Set<String>();
        List<OtherObject__c> OtherObjectList = new List<OtherObject__c>();
        accList = [SELECT Id, uniqueField__c FROM Account WHERE uniqueField__c != null LIMIT 10000];
        for(Account a : accList) {
        if(uniqueFieldSet.size() > 0) {
            OtherObjectList = [SELECT Id, uniqueField__c FROM OtherObject__c WHERE uniqueField__c In: uniqueFieldSet LIMIT 10000];
        system.debug('----' + courseList);
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Ajay Dubedi
problem here is count of records from 2nd object is more than 50000.