You need to sign in to do that
Don't have an account?
only aggregate expressions use field aliasing (6:39)
Hello,
Hope you guys are doing well in this tough situation.
I'm trying to send welcome email to customers.
I did setup in Classic Email Templates.
public with sharing class WelcomeEmailProcessor {
// public WelcomeEmailProcessor() {
// }
public static void sendMail(List<String> address, String subject, String body) {
EmailTemplate emailTemplate = [Select Id, Subject, Email Body FROM EmailTemplate where name = 'Dreamhouse welcomes e-mail'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(address);
mail.setSubject(subject);
mail.setHtmlBody(body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
I'm getting an error stasting only aggregate expressions use field aliasing on line number 6.
{
"owner": "deploy-errors",
"severity": 8,
"message": "only aggregate expressions use field aliasing (6:39)",
"source": "ApexClass",
"startLineNumber": 6,
"startColumn": 39,
"endLineNumber": 6,
"endColumn": 39
}
Thank you in advance! :-)
Hope you guys are doing well in this tough situation.
I'm trying to send welcome email to customers.
I did setup in Classic Email Templates.
public with sharing class WelcomeEmailProcessor {
// public WelcomeEmailProcessor() {
// }
public static void sendMail(List<String> address, String subject, String body) {
EmailTemplate emailTemplate = [Select Id, Subject, Email Body FROM EmailTemplate where name = 'Dreamhouse welcomes e-mail'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(address);
mail.setSubject(subject);
mail.setHtmlBody(body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
I'm getting an error stasting only aggregate expressions use field aliasing on line number 6.
{
"owner": "deploy-errors",
"severity": 8,
"message": "only aggregate expressions use field aliasing (6:39)",
"source": "ApexClass",
"startLineNumber": 6,
"startColumn": 39,
"endLineNumber": 6,
"endColumn": 39
}
Thank you in advance! :-)
The issue here is with the SOQL. There is a space between Email Body because of which Salesforce thinks that we are trying to give a different label to Email and hence the error
Select Id, Subject,
EmailBody FROM EmailTemplate where name = 'Dreamhouse welcomes e-mail'Try something like
Select Id, Subject,Name, Body FROM EmailTemplate where name = 'Dreamhouse welcomes e-mail'
Related: https://www.sfdcpoint.com/salesforce/only-aggregate-expressions-use-field-aliasing-soql-error/
https://developer.salesforce.com/forums/?id=9062I000000IDrCQAW
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
All Answers
The issue here is with the SOQL. There is a space between Email Body because of which Salesforce thinks that we are trying to give a different label to Email and hence the error
Select Id, Subject,
EmailBody FROM EmailTemplate where name = 'Dreamhouse welcomes e-mail'Try something like
Select Id, Subject,Name, Body FROM EmailTemplate where name = 'Dreamhouse welcomes e-mail'
Related: https://www.sfdcpoint.com/salesforce/only-aggregate-expressions-use-field-aliasing-soql-error/
https://developer.salesforce.com/forums/?id=9062I000000IDrCQAW
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
I'm glad you helped. :-)