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
John Neilan 2John Neilan 2 

Create Custom Object Record Upon Case Creation

Hello,

I am having trouble wrapping my head around something.  We are setting up a Web-To-Case integration where a Case will be created when an internal system receives an alert.  The Case will have an internal identifier field that is also populated on the Case record.  All that is fine, however, if multiple alerts occur for Cases with the same internal identifier, I need to create the case via web-to-case, search for any open cases with that internal identifier, add a new custom object record linked to the existing case, and then delete the new case.  The end result would be 1 open case per identifier, with potentially multiple custom object records.  Can anyone suggest how I can do this with a trigger or some other method?
PavanKPavanK
Hi John,

Thanks forr your post.

There are several way to achieve this requirement with small tweak

1) If you can make this identifier field unique then new case wll not get created, because of run-time error saying record is already present with same identifier. But with this approach you won't be able to create custom object record.

2) You can create process builder on every case creation which will call flow
            Flow will consist
                     -> Lookup to see if there is any existing record with same identifier
                     --> Desision if same identifier is present
                     --> Create custom object record
                     --> Delete case
Example: https://automationchampion.com/tag/launch-flow-from-process-builder/
               https://developingflow.com/2015/07/11/launch-a-flow-using-lightning-process-builder/
                https://judisohn.com/2015/04/06/using-salesforce-process-builder-flow-with-opportunity-contact-roles/

3) Create trigger.

Please let me know, if any more information is required.

Please mark this answer as best if reply helped to resolve your quesy.
John Neilan 2John Neilan 2
PavanK -- Thanks so much for the options.  I will try the Flow option first as that might work.  Do you know if it's possible to check the web-to-case record before it enters SFDC to see if another Case already exists with the same ID, and then rather than creating a case, updating a record, and deleting the case, instead it would find the existing case append the new custom object record and simply not create the new case at all?
Hargobind_SinghHargobind_Singh
John -- you should be able to write an 'Affer' trigger to run your logic and delete the case. However, you might not be able to delete using trigger.new and might have to run a query. Here is a post that explains that:

http://salesforce.stackexchange.com/questions/42124/deleting-records-in-an-after-trigger
Rakesh51Rakesh51
You could also do using the Process Builder