1

i've searched for info but still can't figure out why this is happening. I'm also at the moment with a case open on salesforce and me&support are trying to figure out what is happening.

As you know salesforce is programmed to send an email notification to the task owner when it is created (only if you have this feature enabled, which it is by default). We've activated all the features that you need to recive the mails (actually the users recieve some times the mails , sometimes not).

The weird thing about this is that the task is created all the times correctly but the emails isn't sent sometimes(which is suposed to be an automated SF process).

This is the code where we create the task (I didn't write it).

public void notifySales (Map<Id,Id> recordUser, Boolean alreadyAssigned){
    Map<Id,Task> auxController = new Map<Id,Task>();
    for(Id iter : recordUser.keySet()){
        if(String.valueOf(recordUser.get(iter)).startsWith('005')){
            if(!auxController.containsKey(recordUser.get(iter))){
                auxController.put(recordUser.get(iter), new Task(OwnerId                   = recordUser.get(iter),
                                                                 ActivityDate              = System.today(),
                                                                 IsReminderset             = true,
                                                                 Type                      = 'Record Assignment',
                                                                 reminderDatetime          = (system.now()).addSeconds(10),
                                                                 Did_you_speak_with_CFO__c = 'No',
                                                                 WhatId                    = (String.valueOf(iter).startsWith('001'))?iter:null,
                                                                 WhoId                     = (String.valueOf(iter).startsWith('00Q'))?iter:null,
                                                                 Subject                   = (alreadyAssigned)?label.InboundSubjectII : label.InboundSubject,
                                                                 Description               = 'Records to review :\r \r https://eu2.salesforce.com/'+String.valueOf(iter)));

            }else{
                auxController.get(recordUser.get(iter)).Description += '\r https://eu2.salesforce.com/'+String.valueOf(iter);
            } 
        }
    }   

    Database.SaveResult[] sRList = Database.insert(auxController.values(), false);
    for(Database.SaveResult sR : sRList){
        if(!sR.isSuccess()){
            for(Database.Error err : sR.getErrors()){
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'A notification failed due to'+err.getMessage()+'.'));
            }   
        }
    }       
} 

Another thing I found is that when the status of the Task is 'Not completed' the mails isn't sent and when it's completed the user recieved the mail.

Why is this happening? How could I solve it?

1 Answer 1

1

Looking at your code, here's a few things I see that might be helpful to you in sorting this out.

auxController.put(recordUser.get(iter), 
      new Task(
        OwnerId = recordUser.get(iter),
        ActivityDate = System.today(),
        IsReminderset = true,
        Type = 'Record Assignment',
        reminderDatetime = (system.now()).addSeconds(10),
        Did_you_speak_with_CFO__c = 'No',
        WhatId = (String.valueOf(iter).startsWith('001'))?iter:null,
        WhoId = (String.valueOf(iter).startsWith('00Q'))?iter:null,
        Subject = (alreadyAssigned)?label.InboundSubjectII : label.InboundSubject,
        Description = 'Records to review :\r \r https://eu2.salesforce.com/'+String.valueOf(iter)));

It appears to me that the code above puts things into a map when a Task is created by a User where the WhatID is for an Account (based on WhatId = (String.valueOf(iter).startsWith('001'))?iter:null,). Reminder is set to True (IsReminderset = true). Oddly, it sets the reminder for 10 seconds from Now() (reminderDatetime = (system.now()).addSeconds(10)). I also noticed that these Tasks are of `Type = Record Assignment'.

From this, an auxController class is called to get the User Record Info needed to create the task. It appears that your system is relying on the reminder that's set for 10 seconds from system.now() to open a pop-up on your user's desktop to immediately notify them of the new Task. It doesn't in any way trigger an email.

That section of code appears to be for creating new Tasks related to account transfers. There's an additional section of code in an else statement that presumably covers Tasks created for all other objects. If it doesn't, that might help explain why the emails aren't being received:

}else{
   auxController.get(recordUser.get(iter)).Description += '\r https://eu2.salesforce.com/'+String.valueOf(iter);

} 

The rest of the code is for the Database Insert of the Task records. If the other Tasks aren't being created with reminders or the notification options set, it would seem that there's nothing in place in your code for this to happen.

There's certainly nothing in the code above that creates an email message related to these Tasks. I'd recommend you look at the auxController class to see if it contains code to create a notification email based on the information that's passed to it from the above class.

To clarify something, the reminder can be set for any date-time and is not the same as the notification you're speaking of. It's intended as a pop-up reminder on the desktop that the task is coming due and requires action. It's most helpful when a task has a due date that's more than a few days out.

2
  • Well since Winter15 i think is enabled by default a function that sends a mail to the owner of an activity when it's created if you have the correct checkboxes marked. That's why i supose they should recive a mail. Anyway the weird thing is that this code has been working for quite a good time and started failing in some situations without obvious reason. Jul 9, 2015 at 15:31
  • 1
    As I said above, this particular class doesn't send any emails. It only appears to fetch User info to add to Tasks being created or to send to the auxController class. It appears to me that the auxController class would the one you need to be taking a closer look at. See this knowledge article on Org Wide Send Notification Email Settings.
    – crmprogdev
    Jul 9, 2015 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .