0

I have a class containing this method that creates an email in APEX and sends it out once the method is called.

public static void generateMessagingTemplates( String requestLogId){

        String siteUrlStatic = String.valueOf(System.Label.gos_Site_URL);
        Site negCon = [SELECT id, UrlPathPrefix FROM .....];
        List <Messaging.SingleEmailMessage> allTempates = new List<Messaging.SingleEmailMessage>();

        for (Integration_Request_Log_Item__c eachLogItem : [SELECT Id,...]){

            Messaging.reserveSingleEmailCapacity(3);
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[] {eachLogItem.Email__c}; 
            mail.setToAddresses(toAddresses);
            mail.setSenderDisplayName('Salesforce Support');
            mail.setSubject('Testing ......');
            mail.setBccSender(false);
            mail.setUseSignature(false);
            mail.setPlainTextBody('Something something ...');
            mail.setHtmlBody('<p>Dear (Sir / Madam),<br /><br /></p>');
            allTempates.add(mail);

        }
        //System.debug('allTempates >> '+allTempates );
        Messaging.sendEmail( allTempates );
    }

I have tested it as myself (an Admin in Dev console, execute anonymous) and it works, emails are being sent to the email I specify. Now the problem is with Community users.

I have a test users in our community, with Community User Plus license type. When I login as any of those users into the community and trigger the actions that invoke this class, emails are not being sent. I know for the fact that the class is called out by the community users, because another part of it is creating/updating some records, and that is happening. But email part is not. I also monitored the email log and nothing hit that either.

Any ideas why this might be happening? Is there some permission those community users are missing? Please, any insight will be appreciated.

  • Did you check debug logs for any errors? – RedDevil May 15 at 4:16
  • Nothing in the logs. Also I do not think that logs for Community users show us, and I was not able to set one manually – Art S May 15 at 4:36
  • 1
    logs can be set for community users or else try the other way around , enable logging for the apex class from which you are sending emails and see what happens – RedDevil May 15 at 4:37
  • Check 'Send Email' Permission in General User Permissions section in portal profile. – Dhanik Lal Sahni May 15 at 9:35
  • I figured it out. Was able to create a log for the Community user. There is a hardcoded value in my class that I missed and as a result one if my queries was returning null. – Art S May 15 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.