1

Context

Hello,

I'm encountering an issue when attempting to use the simpleEmail function via the REST API in Salesforce. The error message returned is as follows:

[
  {
    "actionName": "emailSimple",
    "errors": [
      {
        "statusCode": "UNKNOWN_EXCEPTION",
        "message": "An error occurred. Try again, or contact Salesforce Customer Support and provide this error ID: 1414428604-26203 (1457644238)",
        "fields": []
      }
    ],
    "invocationId": null,
    "isSuccess": false,
    "outputValues": null,
    "sortOrder": -1,
    "version": 1
  }
]

Here is the payload I'm using:

{
    "inputs": [
        {
            "emailSubject": "Test Subject",
            "emailBody": "This is a test email body.",
            "emailAddresses": "[email protected]",
            "logEmailOnSend": true,
            "recipientId": "0019000000DmehKAAR"
        }
    ]
}

Despite following the documentation, I'm not sure why this error is occurring. I've verified that the recipientId and emailAddresses are correct. Additionally, I am passing logEmailOnSend as true.

Questions:

  1. What could be the potential causes for the UNKNOWN_EXCEPTION error in this context?
  2. Are there any specific configurations or permissions that I might be missing?
  3. How can I resolve this error or get more detailed information about the cause? Any help or guidance would be greatly appreciated. Thank you!

(P.S. I hid recipientId with some sample Id, but I used leadId to which I wanted to send an email. I verified that email is indeed sent, when I set logEmailOnSend = False)

5
  • I can try to disable logEmailOnSend and use EmailMessage to log the email in lead's activity as a workaround
    – Nuraly
    Commented Jun 21 at 12:44
  • 1
    As far as I can tell, it should work. I was able to replicate the gack in my own dev org as well. I've reached out to some people who might be able to help. Stay tuned...
    – sfdcfox
    Commented Jun 21 at 14:11
  • @sfdcfox thank you for your effort, knowing that it works on your side makes me hopeful. I will post code snippet for my workaround as a separate answer to the original post, maybe it will give some insight as well
    – Nuraly
    Commented Jun 21 at 14:56
  • 1
    You have enabled Person Accounts, right? Commented Jun 21 at 16:15
  • 3
    I looked up for stacktrace id 1457644238 in our salesforce backend logs and it points to java.lang.NullPointerException. Checking the stacktrace further.... Commented Jun 21 at 17:30

1 Answer 1

1

While this is not a direct solution to the problem, it appears that the error message is not very informative, making debugging difficult. However, I discovered a workaround that might help. Instead of using the logEmailOnSend parameter, you can send an email without it and manually create a task record with the 'TaskSubtype': 'Email' field. Here's how I did it using Python as an example:


@api.post("/sendsimplemail")
def send_mail(subject: str, body: str):
    # Salesforce instance from simple-salesforce module
    sf = get_salesforce_connection()


    url = f"{sf.base_url}/actions/standard/emailSimple"

    payload = {
        "inputs": [
            {
                "emailSubject": subject,
                "emailBody": body,
                "emailAddresses": "[email protected]",
                "recipientId": "0019000000DmehKAAR"
            }
        ]
    }

    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + sf.session_id
    }
    response = requests.post(url, headers=headers, data=json.dumps(payload))

    # Create a new task to log the email manually
    new_task = {
        'WhoId': "0019000000DmehKAAR",
        'Subject': "Email: " + subject,
        'Description': body,
        'ActivityDate': datetime.date.today().isoformat(),
        'Status': 'Completed',
        'Priority': 'Normal',
        'TaskSubtype': 'Email'
    }
    sf_task = sf.Task.create(new_task)

    return sf_task

You must log in to answer this question.

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