• Frazier
  • NEWBIE
  • 5 Points
  • Member since 2016
  • Software Engineer
  • Greenway Health

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
I could use some assistance. We have a SalesForce customer portal and in a number of my orgs, the reset password email is not being sent to the users, either via the Forgot Password link or the Admin Reset Password button in User tab. The Forgot Username email works as expected though. The Forgot Password flow works fine in some of my other orgs and as far as I can tell, all settings are identical.

I have verified in Setup -> Email Administration -> Deliverability that Access Level is set to 'All email'.
In Setup -> Email Administration -> Test Deliverability, I have verified that I receive all 48 test emails.
In Setup -> Communication Templates -> Email Templates -> Forgot Password, I have tried the 'Send Test and Verify Merge Fields' and received the test email.
The Email Log File shows that all forgot password emails are being delivered and received (although they never actually make it to the inbox).

I am not sure if there is an issue with Site.forgotPassword() or if somehow the Forgot Password email template is not mapped properly to the Forgot Password workflow. I do know that the orgs that are having issues have the same managed package as the orgs that are working.  
Not sure where to go from here?

Any help is appreciated.
I could use some assistance. We have a SalesForce customer portal and in a number of my orgs, the reset password email is not being sent to the users, either via the Forgot Password link or the Admin Reset Password button in User tab. The Forgot Username email works as expected though. The Forgot Password flow works fine in some of my other orgs and as far as I can tell, all settings are identical.

I have verified in Setup -> Email Administration -> Deliverability that Access Level is set to 'All email'.
In Setup -> Email Administration -> Test Deliverability, I have verified that I receive all 48 test emails.
In Setup -> Communication Templates -> Email Templates -> Forgot Password, I have tried the 'Send Test and Verify Merge Fields' and received the test email.
The Email Log File shows that all forgot password emails are being delivered and received (although they never actually make it to the inbox).

I am not sure if there is an issue with Site.forgotPassword() or if somehow the Forgot Password email template is not mapped properly to the Forgot Password workflow. I do know that the orgs that are having issues have the same managed package as the orgs that are working.  
Not sure where to go from here?

Any help is appreciated.
I could use some assistance. We have a SalesForce customer portal and in a number of my orgs, the reset password email is not being sent to the users, either via the Forgot Password link or the Admin Reset Password button in User tab. The Forgot Username email works as expected though. The Forgot Password flow works fine in some of my other orgs and as far as I can tell, all settings are identical.

I have verified in Setup -> Email Administration -> Deliverability that Access Level is set to 'All email'.
In Setup -> Email Administration -> Test Deliverability, I have verified that I receive all 48 test emails.
In Setup -> Communication Templates -> Email Templates -> Forgot Password, I have tried the 'Send Test and Verify Merge Fields' and received the test email.
The Email Log File shows that all forgot password emails are being delivered and received (although they never actually make it to the inbox).

I am not sure if there is an issue with Site.forgotPassword() or if somehow the Forgot Password email template is not mapped properly to the Forgot Password workflow. I do know that the orgs that are having issues have the same managed package as the orgs that are working.  
Not sure where to go from here?

Any help is appreciated.

I am trying to send an email in batches when someone adds a comment to a case or someone is added as a case member. The code has simply been mofified for the content of the email. Within the sandbox the emails process correctly but when I deployed to production i got an error. First error: Attemp to de-reference a null object. Any help would be appreciated as I am new to Apex Code.

 

global class CaseEmailBatch implements Database.Batchable<sObject>
{
  global Database.QueryLocator start(Database.BatchableContext BC)
  {
    
    DateTime runDate = System.Now().addMinutes(-30);
    return Database.getQueryLocator('SELECT CreatedById,CreatedDate,Id,LastModifiedById,LastModifiedDate,MemberId,ParentId,SystemModstamp,TeamRoleId,TeamTemplateMemberId FROM CaseTeamMember WHERE CreatedDate >: runDate  ');
  }
  
  
  global void execute(Database.BatchableContext BC,List<sObject> scope)
  {
      List<Messaging.Singleemailmessage> emails = new List<Messaging.Singleemailmessage>();
         Set<ID> caseIds = new Set<ID>(); 
         for(Sobject so: scope){
           CaseTeamMember ctm = (CaseTeamMember)so; 
           String caseId = String.valueOf(so.get('ParentId'));
           caseIds.add(caseId);
           
         }
         
         List<User> users = new List<User>(); 
         users = [select id, email, name FROM User]; 
         
         Map<Id, User> uIdUserMap = new Map<Id, User>(); 
         for(User u: users)
           uIdUserMap.put(u.id, u);
         
         
         List<Case> cases = [select id, CaseNumber, Subject, Description, Account.name, Contact.name, Contact.email, Contact.phone, Origin, CreatedDate, Owner.name, Owner.email FROM Case WHERE id in:caseIds];
         Map<Id, Case> caseMap = new Map<Id, Case>(); 
         for(Case c: cases){
           caseMap.put(c.id, c);
         }
           
      for(Sobject so: scope){
         CaseTeamMember ctm = (CaseTeamMember)so; 
         Case c = caseMap.get(ctm.ParentId);
          
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
          mail.setTargetObjectId(ctm.memberId);
          mail.setSubject('You have been added as a Case Member :' + c.CaseNumber);
          String description; 
          if(c.Description.length() > 500){
            description = c.Description.substring(0,500);
          }
          else{
            description = c.Description;
          }
          
          mail.setPlainTextBody('Case Number: ' + c.CaseNumber + '\n' + 'Subject: ' + c.Subject + '\n' + 'Description: ' + c.Description + '\n' + '\n' + 'Account Name: ' + c.Account.Name + '\n' + 'Contact Name: ' + c.Contact.Name + '\n' + 'Contact Email: ' + c.Contact.email + '\n' + 'Contact Phone: ' + c.Contact.phone + '\n' + 'Case Origin: ' + c.Origin + '\n' + 'Date/Time Opened: ' + c.CreatedDate + '\n' + 'Owner Name: ' + c.Owner.Name + '\n' + 'Owner Email: ' + c.Owner.email + '\n' + '\n' + 'Click here to access the case directly: ' + 'https://ssl.salesforce.com/' + c.Id + '\n');
          mail.setSaveAsActivity(false);
          User u = uIdUserMap.get(ctm.CreatedById);
          mail.setReplyTo(u.email);
          mail.setSenderDisplayName(u.name);
          emails.add(mail);
      }
      
      
      List<CaseComment> cms = new List<CaseComment>();
        DateTime runDate = System.Now().addMinutes(-30);
      cms = [SELECT CommentBody, CreatedById,CreatedDate,Id,IsDeleted,IsPublished,LastModifiedById,LastModifiedDate,ParentId, Parent.CaseNumber, Parent.Description, Parent.Subject, Parent.Account.name, Parent.Contact.name, Parent.Contact.email, Parent.Contact.phone, Parent.Origin, Parent.CreatedDate, Parent.Owner.name, Parent.Owner.email, Parent.Id FROM CaseComment  WHERE CreatedDate >: runDate]; 
      Set<ID> parentIds = new Set<ID>(); 
      Map<Id, CaseComment> caseCommentMap = new Map<Id, CaseComment>(); 
      for(CaseComment cm: cms){
        caseCommentMap.put(cm.ParentId, cm);
        parentIds.add(cm.ParentId); 
        
      }
      
      List<CaseTeamMember> commentMembers = new List<CaseTeamMember>(); 
      commentMembers = [SELECT CreatedById,CreatedDate,Id,LastModifiedById,LastModifiedDate,MemberId,ParentId,SystemModstamp,TeamRoleId,TeamTemplateMemberId FROM CaseTeamMember WHERE ParentId in: parentIds]; 
      
      for(CaseTeamMember ctm: commentMembers){
        CaseComment cm = casecommentMap.get(ctm.ParentId); 
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
          mail.setTargetObjectId(ctm.memberId);
          mail.setSubject('A new comment has been added to Case :' + cm.Parent.CaseNumber);
          String description; 
          if(cm.Parent.Description.length() > 500){
            description = cm.Parent.Description.substring(0,500);
          }
          else{
            description = cm.Parent.Description;
          }
          
          
          mail.setPlainTextBody('Case Number: ' + cm.Parent.CaseNumber + '\n' + 'Subject: ' + cm.Parent.Subject + '\n' + 'Description: ' + cm.Parent.Description + '\n' + '\n' + 'Last Comment: ' + cm.CommentBody + '\n' + '\n' + 'Account Name: ' + cm.Parent.Account.Name + '\n' + 'Contact Name: ' + cm.Parent.Contact.Name + '\n' + 'Contact Email: ' + cm.Parent.Contact.email + '\n' + 'Contact Phone: ' + cm.Parent.Contact.phone + '\n' + 'Case Origin: ' + cm.Parent.Origin + '\n' + 'Date/Time Opened: ' + cm.Parent.CreatedDate + '\n' + 'Owner Name: ' + cm.Parent.Owner.Name + '\n' + 'Owner Email: ' + cm.Parent.Owner.email + '\n' + '\n' + 'Click here to access the case directly: ' + 'https://ssl.salesforce.com/' + cm.Parent.Id);
          mail.setSaveAsActivity(false);
          User u = uIdUserMap.get(cm.CreatedById);
          mail.setReplyTo(u.email);
          mail.setSenderDisplayName(u.name);
        
          emails.add(mail);
        
        
      }
      
      Messaging.sendEmail(emails);
      
      
      
      
  
  }
  
  global void finish(Database.BatchableContext BC)
  {
    
  }
  
}