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
ferenikferenik 

Java - SendEmail() problem

Hi,
the target is send an email by the salesforce.com api.
This is my code:
Code:
SingleEmailMessage[] messages = new SingleEmailMessage[1];
  messages[0] = new SingleEmailMessage();
  messages[0].setTemplateId(new ID("00XT0000000esdC"));
  messages[0].setBccSender(true);
  messages[0].setEmailPriority(EmailPriority.High);
  messages[0].setReplyTo(replayto);
  messages[0].setSaveAsActivity(saveAsActivity);
  messages[0].setSubject("subject");
  messages[0].setUseSignature(useSignature);
  messages[0].setPlainTextBody("body text");
  String[] toAddresses = new String[] {  "jdoe@salesforce.com" };
  messages[0].setToAddresses(toAddresses);
  messages[0].setSenderDisplayName("Sender Name");
  messages[0].setCharset("UTF8");
  messages[0].setHtmlBody("html body");
  messages[0].setTargetObjectId(new ID("00320000002UJxf"));
  messages[0].setWhatId(new ID("00320000002UJxf"));
 SendEmailResult[] result = sfdcSes.sfdc.sendEmail(messages);

In the result I receive this message: "The email failed to send: When a template is specified the plain text body, html body and subject may not be specified".

But if I dont set the TemplateId I receive this exception: "java.io.IOException: java.io.IOException: Non nillable element 'templateId' is null."

And vice versa if I dont set plain text body, html body and subject but set only TemplateId I receive this exception: "java.io.IOException: java.io.IOException: Non nillable element 'subject' s null."

Please help me!

thanks in advance

francesforce