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
Anne MooreAnne Moore 

Test Class Addition

Hello!  I am not a developer!  I wanted to start off with that.  

We have an existing test class.  On the test class that's running, the object has a required field that has a lookup filter.  Below is the current information in the test  class:

//find existing contact from an acccount with the right record type
        Contact testContact = [SELECT id, name FROM Contact c where c.active__c = true and c.accountid in(SELECT id FROM ACCOUNT a where a.recordtypeid = :brokerRecordType) Limit 1  ];

I recently had to add to the lookup filter on this field that the contact record should also only access contacts from the account selected in another lookup field on this object.  Would anyone be willing to offer advice on how can I add this to the test class?  Thanks in advance!!

bob_buzzardbob_buzzard
It should be as simple as adding an AND clause to the query to check the account id matches the other field.  The snippet below assumes you have the selected account value in the other lookup field available in the controller variable 'chosenAccId' :

//find existing contact from an acccount with the right record type
        Contact testContact = [SELECT id, name FROM Contact c where c.active__c = true and c.accountid in(SELECT id FROM ACCOUNT a where a.recordtypeid = :brokerRecordType 
              AND a.id=:chosenAccId) Limit 1  ];

You may not even need the check that the record id matches the brokerRecordType, but its difficult to say for sure without knowing how the rest of your application works.