function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
EtienneCoutantEtienneCoutant 

Send Emails regarding Cases, using Templates, with only WebEmail

Hi

I am using:
PHP toolkit-11_0b
PHP 5.1.6
Salesforce API version 11


I am trying to send Emails via the API, related to cases, using a Template in Salesforce.
When the Salesforce case has a Contact, the following function works well:

/**
* Create an Array of Emails for an Array of Cases
* @param conn Connexion to Salesforce using Partner API
* @param $cases Array of Cases (Custom Class with set and get methods)
*/
function emailMerge($conn,$cases)
{
$results = array();
foreach ($cases as $case){
$singleEmail = new SingleEmailMessage();
$singleEmail->useSignature = false;
$singleEmail->templateId = SALESFORCE_TEMPLATE_ID;
$singleEmail->targetObjectId = $case->getFirstContactId();
if($case->getSuppliedEmail()!= null) $singleEmail->toAddresses = $case->getSuppliedEmail();
$singleEmail->whatId = $case->getId();
array_push($results,$singleEmail);
}
$conn->sendSingleEmail($results);
}


However, when there is no Contact on the case record, I keep getting the error, as it should.

[errors] => stdClass Object
(
[fields] =>
[message] => Only emails to contacts can specify whatId.
[statusCode] => INVALID_ID_FIELD
[targetObjectId] =>
)

I just wonder if it is possible to send an Email (using a template) when the Case has only the WebEmail info, and no Contact. I could do that from the web app, by leaving the 'To' field empty, but no from the API. Any reason why? Any workarounds?