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
Érick BSÉrick BS 

Invalid bind expression type of Contract__c does not match domain of foreign key (146:16)

Hi! I am a new developer in Apex... Could someone help me to solve this error? I can´t understand what I have to do.
 
private static List<Task> queryExistingContractsTasks( List<User> entradaDuenos, List<Contract__c> entradaContratos ){
        return [
            SELECT
                WhoId,
                OwnerId
            FROM
                Task
            WHERE
                OwnerId IN :entradaDuenos
            AND WhoId IN :entradaContratos
            AND Subject LIKE '%Contract%'
            AND CreatedDate = TODAY
        ];
    }

 
GauravendraGauravendra
Hi Erick,

I believe the WhoId on task can only point to user and contact.
In your case, you are assigning it to custom object.

Hope this helps!
Érick BSÉrick BS

Hi Gauravendra! First of all, thank your for your message.

I only could solve this problem adding a sub-query and works.The problem was because I did not pass the ID in the list, and this is a required in SOQL in lists, I think so...
 
private static List<Task> queryExistingContractsTasks( List<User> entradaDuenos, List<Contract__c> entradaContratos ){
        Set<Id> setUserIds = new Set<Id>();
        for(User us:entradaDuenos) {
            setUserIds.add(us.id);
        }       
        Set<Id> setContractIds = new Set<Id>();
        for(Contract__c con:entradaContratos) {
            setContractIds.add(con.id);
        }       
        List<Task> queryListContracts = [ 
            SELECT
                WhoId,
                OwnerId
            FROM
                Task
            WHERE
                OwnerId IN :setUserIds
            AND WhoId IN :setContractIds
            AND Subject LIKE '%Contract%'
            AND CreatedDate = TODAY
            ];
        return queryListContracts;
      }