0

When I add my WHERE clause on the last query I get the following error:

Invalid bind expression type of Account_Counselor__c does not match domain of foreign key

Part of controller code:

    public Id selectedHubId {get; set;}

    public list<OE_Rollover_Spans__c> getOpenEnrollments(){

        List<Account_Counselor__c> cAccounts = new list<Account_Counselor__c>(
            [Select Id,Account__c FROM Account_Counselor__c WHERE Hub_Name__c = :selectedHubId]);

        List<OE_Rollover_Spans__c> OEs = new list<OE_Rollover_Spans__c>(
        [Select Account__c,Account__r.Name,Name,Type__c,OE_Type__c,Start_Date__c,End_Date__c
                                          FROM OE_Rollover_Spans__c
                                          WHERE Account__c IN :cAccounts]
        );

return OEs;
}

Any ideas?

1

Try this,

    public Id selectedHubId {get; set;}

    public list<OE_Rollover_Spans__c> getOpenEnrollments(){

    List<string> whereList = new List<String>();

List<Account_Counselor__c> cAccounts = new list<Account_Counselor__c>(
                [Select Id,Account__c FROM Account_Counselor__c WHERE Hub_Name__c = :selectedHubId]);
    for(Account_Counselor__c cc:cAccounts ){
    whereList.add(cc.Account__c );
    }

            List<OE_Rollover_Spans__c> OEs = new list<OE_Rollover_Spans__c>(
            [Select Account__c,Account__r.Name,Name,Type__c,OE_Type__c,Start_Date__c,End_Date__c
                                              FROM OE_Rollover_Spans__c
                                              WHERE Account__c IN :whereList]
            );

    return OEs;
    }
2
  • Anurag, Just a quick note. While posting an answer always add problem solution with few words so that user know what he did wrong with his code.
    – Himanshu
    Jun 9 '16 at 20:22
  • sure @Himanshu, I'll keep that in mind for sure. Thank you
    – Anurag
    Jun 9 '16 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.