QueryException "No such column 'Name' on entity 'EmailTemplate'" + "Variable does not exist: tmpVar1" — only at API v67, works fine at v44**
Hi all,
I'm hitting a strange `System.QueryException` in one sandbox but not others, and I'd like a sanity check on whether this is a known platform behavior or something in my code.
**The error:**
```
System.QueryException: No such column 'Name' on entity 'EmailTemplate'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
System.QueryException: Variable does not exist: tmpVar1
```
**The query (inside a class method):**
```apex
private static Map<String, Id> getEmailTemplates() {
Map<String, Id> emailTemplateByName = new Map<String, Id>();
for (EmailTemplate emailTemplate : [
SELECT Id, Name
FROM EmailTemplate
WHERE IsActive = TRUE
AND (Name = :IN_EMAIL_TEMPLATE
OR Name = :BG_EMAIL_TEMPLATE
OR Name = :SK_EMAIL_TEMPLATE
OR Name = :PK_EMAIL_TEMPLATE
OR Name = :SS_EMAIL_TEMPLATE
OR Name = :EI_EMAIL_TEMPLATE
OR Name = :HT_EMAIL_TEMPLATE
)
]) {
emailTemplateByName.put(
emailTemplate.Name, emailTemplate.Id);
}
return emailTemplateByName;
}
```
**What I'm seeing:**
- This class is compiled at API v44.0 in our Dev and Production orgs, and the query runs fine there.
- The same class in our UAT sandbox is compiled at API v67.0 (v44 isn't even selectable there anymore — the version picker only goes back to 63), and this exact query throws the error above every time.
- `Name` is obviously a valid standard field on `EmailTemplate`, so the "no such column" message seems misleading — combined with the `tmpVar1` error right after it, it feels like something is going wrong internally when the query tries to evaluate a long chain of `Name = :bindVar OR Name = :bindVar ... conditions on the same field, rather than an actual field-access problem.
**My questions:**
1. Has anyone else run into this specific combination of errors with long OR-chains of bind variables on the same field, and does it ring a bell as a known API-version-related SOQL behavior?
2. I'm planning to rewrite this as `Name IN :templateNames` (a `Set<String>`) instead of the OR-chain — is that a safe, reliable workaround, or is there a better-known fix?
3. Is this worth filing as a Known Issue with Salesforce Support, or is this expected/documented behavior I'm just not aware of?
Any pointers appreciated — thanks!
#Apex #Salesforce Developer
The query worked just fine for me in v67.0 and given the message you are seeing, I suspect that error is originating from somewhere else. I'd recommend a step-by-step debug.