I am getting this error with the code below. I've looked into the other cases on here. In my case I am referring to a relationship name (__r) which I am assuming is pulling correctly. It's a field which is a lookup to User :
Agreement_CSH_to_be_completed_by__r
Here is the code which is giving me problems :
public void doManagedClients() {
addMsg('Starting processing of Managed Clients.');
Integer startSize = CSH_Data.size();
String SOQL = 'Select Id, OwnerId, Owner.UserName, Account__c, RecordTypeId, Name, Agreement_Client_Status_History__c ' +
'From Contract_Terms__c Where ' +
' ( recordtypeid = \''+ ((String)A_N_Rectype).substring(0,15) + '\' ) and ' +
' Agreement_Client_Status_History__c = \'Monthly\' ' +
'order by createddate desc nulls first' ;
system.debug('#####333#### ');
addMsg(DEBUG,'Managed Query is: ' + SOQL + '\n');
for (Contract_Terms__c a: Database.Query(SOQL)) {
if (!a.Agreement_CSH_to_be_completed_by__r.isActive) {
totalInactiveOwners++;
addMsg('Account: ' + a.Name + ', has an inactive owner. Username: ' + a.Agreement_CSH_to_be_completed_by__r.isActive + '.');
} else {
totalManagedCSHs++;
addMsg(DEBUG,'Creating a Managed CSH for Account: ' + a);
CSH_Data.add(new CSH_and_Share_Pair(a, createClientStatusHistory(a)));
needflush(false);
if (error) break;
}
}
needflush(true);
addMsg('End of Managed Clients.');
}
Is it just because I don't have a.Agreement_CSH_to_be_completed_by__r included in the SOQL ? I thought I got different errors for that, so I'm a little confused.
Thank you for your help.