# EmailHeader

The Salesforce user interface allows you to specify whether to send an email when these events occur:

- Create a [Case](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_case.htm)
- Create a [CaseComment](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_casecomment.htm)
- Convert Case email to a [Contact](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contact.htm)
- Send a New [User](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_user.htm) email notification
- Make a [`resetPassword()`](/docs/platform/api/guide/sforce-api-calls-resetpassword.md) call

In API versions 8.0 and later, you can also send an API request that sends email.

A group event is an [Event](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_event.htm) for which `IsGroupEvent` is true. The [EventRelation](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_eventattendee.htm) object tracks the users, leads, or contacts that are invited to a group event. Note the following behaviors for group event email sent through the API:

- Sending a group event invitation to a IUser respects the `triggerUserEmail` option
- Sending a group event invitation to a [Lead](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_lead.htm) or Contact respects the `triggerOtherEmail` option
- Email sent when updating or deleting a group event also respect `triggerUserEmail` and `triggerOtherEmail`, as appropriate

## API Calls

[create()](/docs/platform/api/guide/sforce-api-calls-create.md), [`delete()`](/docs/platform/api/guide/sforce-api-calls-delete.md), [`resetPassword()`](/docs/platform/api/guide/sforce-api-calls-resetpassword.md), [update()](/docs/platform/api/guide/sforce-api-calls-update.md), [upsert()](/docs/platform/api/guide/sforce-api-calls-upsert.md)

## Fields

### `triggerAutoResponseEmail`

**Type:** boolean

**Description:** Indicates whether to trigger auto-response rules (`true`) or not (`false`), for leads and cases. In the Salesforce user interface, this email can be automatically triggered by a number of events, for example creating a case or resetting a user password. If this value is set to `true`, when a Case is created, if there is an email address for the contact specified in [`ContactId`](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_case.htm#i1444499), the email is sent to that address. If not, the email is sent to the address specified in [`SuppliedEmail`](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_case.htm#case_suppliedemail).

### `triggerOtherEmail`

**Type:** boolean

**Description:** Indicates whether to trigger email outside the organization (`true`) or not (`false`). In the Salesforce user interface, this email can be automatically triggered by creating, editing, or deleting a contact for a case.

### `triggerUserEmail`

**Type:** boolean

**Description:** Indicates whether to trigger email that is sent to users in the organization (`true`) or not (`false`). In the Salesforce user interface, this email can be automatically triggered by a number of events; resetting a password, creating a new user, or adding comments to a case.

## Sample Code—Java

This sample shows how to use the `EmailHeader`. It sets the `triggerAutoResponseEmail` email header field to `true`, which triggers an email to be sent when a case is created. Next, it creates a case. This sample assumes an auto-response rule has been set for cases, and an email address is specified in the contact referenced by [`ContactId`](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_case.htm#i1444499).

```codesegment
public void createCaseWithAutoResponse(String contactId) {
  try {
    connection.setEmailHeader(true, false, false);
    Case c = new Case();
    c.setSubject("Sample Subject");
    c.setContactId(contactId);
    SaveResult[] sr = connection.create(new SObject[] { c });
    // Parse sr array to see if case was created successfully.
  } catch (ConnectionException ce) {
    ce.printStackTrace();
  }
}

```
