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)
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 notAccountContactRelations
, tryAccountContactRelationships
instead.