• cmoliver
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi there --

I'm setting up a trigger to automatically generate an autoresponse e-mail when a case is opened through our website (which requires a secure login).

I have everything working as I want it, except that I can't seem to access the Case.ThreadID that we use for our e-mail templates from within the trigger. I've searched documentation, but can't find out how to refer to it in SOQL land. We need it for when customers reply to the auto-response - otherwise, a new case is created, which we want to avoid.

Help?


Here's the code:

trigger SendAutoResponse on Case (after insert) {

// Iterate over each sObject
for (Case a : Trigger.new) { }

String CaseId = [Select Id, ParentId, SuppliedName, CaseNumber, UID__c, AID__c, Description FROM Case WHERE Id IN :Trigger.new].Id;
String ContactID = [Select Id, ContactID FROM Case WHERE Id IN :Trigger.new].ContactID;


// Create a new single email message object
// that will send out a single email to the addresses in the To, CC & BCC list.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

// Specify the address used when the recipients reply to the email.
mail.setReplyTo('us@ourdomain.com');
// Specify the name used as the display name.
mail.setSenderDisplayName('Our Support');

// Who do I send the e-mail to?
mail.setTargetObjectId(ContactID);

// Specify the text content of the email.
mail.setTemplateId('00X50000000phlB');
mail.setWhatID(CaseID);

// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

// Saves as an acivity.
mail.setSaveAsActivity(true);

}



Many thanks -
Hi there --

I'm setting up a trigger to automatically generate an autoresponse e-mail when a case is opened through our website (which requires a secure login).

I have everything working as I want it, except that I can't seem to access the Case.ThreadID that we use for our e-mail templates from within the trigger. I've searched documentation, but can't find out how to refer to it in SOQL land. We need it for when customers reply to the auto-response - otherwise, a new case is created, which we want to avoid.

Help?


Here's the code:

trigger SendAutoResponse on Case (after insert) {

// Iterate over each sObject
for (Case a : Trigger.new) { }

String CaseId = [Select Id, ParentId, SuppliedName, CaseNumber, UID__c, AID__c, Description FROM Case WHERE Id IN :Trigger.new].Id;
String ContactID = [Select Id, ContactID FROM Case WHERE Id IN :Trigger.new].ContactID;


// Create a new single email message object
// that will send out a single email to the addresses in the To, CC & BCC list.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

// Specify the address used when the recipients reply to the email.
mail.setReplyTo('us@ourdomain.com');
// Specify the name used as the display name.
mail.setSenderDisplayName('Our Support');

// Who do I send the e-mail to?
mail.setTargetObjectId(ContactID);

// Specify the text content of the email.
mail.setTemplateId('00X50000000phlB');
mail.setWhatID(CaseID);

// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

// Saves as an acivity.
mail.setSaveAsActivity(true);

}



Many thanks -