1

I have an existing piece of code that looks for geolocation for existing leads.

 for (Lead l : leads) {
    System.debug(l.Id);
    // Check if Lead was created or Updated for IC_Campaign_Eligible__c in last 24 Hours
    List<LeadHistory> leadHistoryValues = IDtolhist.get(l.id);

    if (!leadHistoryValues.isEmpty()) {
        Double latitude = l.Latitude;
        Double longitude = l.Longitude;
        l.Status = 'ICReady';
        if(l.MG__c == NULL || l.MG__c == ''){
            List<Account> accounts = new List<Account>(
                [SELECT Id, Name, DISTANCE(ShippingAddress, GEOLOCATION(:latitude, :longitude), 'mi' ) Dist,
                    (SELECT ContactId, Contact.Name, Contact.PCP_Counter__c, 
                            Contact.Gender__c 
                      FROM AccountContactRelations 
                      WHERE Contact.Include_in_IC_Campaign__c = TRUE 
                      ORDER BY Contact.PCP_Counter__c ASC NULLS FIRST)
                    FROM Account 
                    WHERE ShippingLatitude != null
                    ORDER BY DISTANCE(ShippingAddress, GEOLOCATION(:latitude, :longitude ),'mi')]);

This was written by someone else and yes - does contain a loop in a loop but...

We are getting an issue with the AccountContactRelation object reference.

This is the error:

Contact.PCP_Counter__c, Contact.Gender__c FROM AccountContactRelations WHERE Contact.Include_in_IC_Campaign__c ^ ERROR at Row:2:Column:145 Didn't understand relationship 'AccountContactRelations' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

This doesn't make sense. The Object is a standard object; I'm not adding __r in this case. Embedded soql queries work so --- but not in this case...

Can anyone give me a hint as to what may be wrong?

Edit: This is not a duplicate of the other post: This class has been working in production for over a year. It's a scheduled batch class and I was turning on the schedule in full sandbox to test a change in another class but the schedule wouldn't take because of issues in this class (which has not been modified since API V41)

4
  • 2
    are you at least V37.0 in this class?
    – cropredy
    Commented Sep 18, 2019 at 22:52
  • Salesforce does some funky things with standard objects from time to time. The child relationship name for AccountContactRelation might be one of those "quirks". I'm not able to access my code right now (that I know queries ACRs as a parent-child subquery), but if it's not AccountContactRelations, try AccountContactRelationships instead.
    – Derek F
    Commented Sep 18, 2019 at 22:56
  • Using api V41 in this class (which will change once I can save this)
    – SeanGorman
    Commented Sep 19, 2019 at 14:03
  • @DerekF This is not a duplicate of the other post: This class has been working in production for over a year. It's a scheduled batch class and I was turning on the schedule in full sandbox to test a change in another class but the schedule wouldn't take because of issues in this class
    – SeanGorman
    Commented Sep 19, 2019 at 14:31

1 Answer 1

3

If you are veryfying this in the new sandbox, then make sure that Allow users to relate a contact to multiple accounts setting is enabled in new sandbox i.e. to use AccountContactRelation, you will have to enable this feature.

You can find this from Setup --> Account Settings --> Account Settings

5
  • I don't know how, or why, but this was the issue - after 2 years of working fine, this checkbox had been unchecked. The sandbox is our full sandbox which was taken from our production environment.
    – SeanGorman
    Commented Sep 19, 2019 at 16:49
  • If it's a newly refreshed sandbox, then you probably might have to enable this feature. There are many such settings which does not get enabled by default, hence projects usually perform post refresh activities to verify if all features are enabled. Commented Sep 20, 2019 at 3:04
  • So - The reason it was turned off is that one of our vendors turned it off to test some code.
    – SeanGorman
    Commented Oct 24, 2019 at 13:52
  • I'd like to mention, as I spin up a Winter '22 scratch org, that I have this feature enabled in my project-scratch-def.json - as in: "features": ["ContactsToMultipleAccounts", ...] (FWIW - this is based off a shape org) and I do not see this table in my Setup > Object listing. Furthermore, a prior scratch org that I spun up yesterday using the same project-scratch-def.json DOES have the AccountContactRelation object
    – bkwdesign
    Commented Sep 8, 2021 at 18:53
  • UPDATE now I see why this is happening
    – bkwdesign
    Commented Sep 8, 2021 at 18:59

Not the answer you're looking for? Browse other questions tagged .