1

Hi I am building custom web to case functionality,

Here case getting created from Lighting component which is hosted in a force.com site.

As soon as the case submitted from the site, case is created in salesforce.

Here is the code

Case c = new Case ();
c.SuppliedEmail = 'wagarop@imailto.net';
c.ContactId ='0030v00000Mn1AhAAJ';
c.Origin = 'US/CAN';
c.RecordTypeId ='012o0000000ql6MAAQ';
c.Subject = 'Test';
c.Description = 'Some description';


Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerAutoResponseEmail = true;

Database.insert(c,dlo);

When I execute this code in Internal User context the case created in salesforce and Auto response rule files and Acknowledgement email has been sent to the Contact's Email

The problem: When I execute the same code with Site User Context in the sense that same code is being called from lightning component which is hosted in force.com site, case is created in salesforce, but it will not fire the AutoResponse rule.

Below are things I verified in the org,

  1. Permission for accessing the object
  2. Org wide email address is set to all profiles
  3. Give the Send Email permission to site guest user profile.
  4. Used Email template is placed in public folder.

Apart from is there any thing I have to setup ?

I also been to this https://help.salesforce.com/articleView?id=creating_auto-response_rules.htm&type=5 documentation

Can somebody tell me is there any alternative to trigger auto response when case created from Site Guest User?

Thank you,

  • in debug log, do you see the auto-response rules run? – cropredy Oct 26 '19 at 13:59
  • In debug log for Internal user context it shows the Autoresponse rule, But for Site guest user it will not – Sudarshan Oct 26 '19 at 14:11
  • so, if you had only a trivial auto-response rule where if (true=true), the email is not sent? That is, there's nothing in the rules that depend on the running user context? – cropredy Oct 26 '19 at 18:40
  • what if(true=true) I didn't get it – Sudarshan Oct 27 '19 at 9:55
0

You say the email template is contained in a public folder. I seriously doubt the force.com site users have access to this folder. But presumably the trigger should run in the context of the case owner, which I'd hope is not the force.com site user. Are you creating any kind of assignment rule?

I strongly suspect what's at the root of your issue here is that you're not using the declarative functionalities built into Service Cloud for case creation and assignment for cases created from your force.com site. I see you were using the Community Tag in your post which I've edited and change to force.com sites. In either case, you really shouldn't need to be inserting these using a trigger at all. Is there a reason you're not using Web to Case? That would automatically insert these cases for you from either a site or community.

You don't need to give email permissions to your user to send them an auto-response email. They're not the ones who are sending the email, the system is sending it to them. You've also tagged your post for Salesforce1-app. Is there a particular reason for that? What does it have to do with your question? I recommend you change your site to use the web to case form either within a component if you wish or embedded in a standard visualforce page that sites uses. You'll find the documentation here.

| improve this answer | |
  • Thank you for your response, I am not using standard web to case because a lot of business use cases and other customization. So I have created a custom lightning component and embedded in public community page. So I am calling a method to save the case data captured in the form. – Sudarshan Oct 26 '19 at 14:07
  • Salesforce1-app is typo thank you for correcting. And its not standard quick action from the community. – Sudarshan Oct 26 '19 at 14:10
  • If that's the case, you may want to learn more about how to utilize web to case. You can have multiple web to case forms (and fields) as appropriate to your needs. – crmprogdev Oct 26 '19 at 14:10
  • Do you have any reference ? Can you please share it – Sudarshan Oct 26 '19 at 14:12
  • So when you create Community, A site profile is created with Guest User Right ? So in that case with default case created by is site guest owner – Sudarshan Oct 26 '19 at 14:13
0

I have resolved this issue,

The take away, whenever an after insert trigger try to update the same case / lead, with out adding below statement. Database.DMLOptions and EmailHeader.triggerAutoResponseEmail = true, will ends in not firing the auto response rule.

So we have to manually add the EmailHeader.triggerAutoResponseEmail to true one more time while updating the same record in after insert.

or

You can take out the Update logic to some asynchronous action.

| improve this answer | |
  • so you need to UPDATE (using the header) the newly-CREATED record? Using the header on the insert is not sufficient? – cropredy Oct 27 '19 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.