You need to sign in to do that
Don't have an account?
carmant
Trigger - create Case from Account
Hi,
I am trying to create a trigger that automatically creates a Case when an Account (PersonAccount) is created that meets certain criteria.
I have managed to get the trigger to create the Case, however, struggling to get it to link to Account. The field we normally use to link is the "Contact Name" - a Contact lookup field. Guessing this is because we use PersonAccounts and they are an amalgamation of Accounts & Contacts?
Here is what I have so far:
trigger CreateCase on Account (after insert) { List<Case> newcase = new List<Case>(); Id rtId = [select Id, name from RecordType where name ='My Record Type' and SObjectType='Case' limit 1].Id; for (Account acc: Trigger.New) { if (acc.Custom_Field__c == 'My Criteria') { newcase.add(new Case( RecordTypeId = rtId, Type='My Type', Origin='My Origin', Status='My Status', ) ); insert newcase; } } }
Any help appreciated!
Thanks
Fixed it with -
Thanks for your help.
All Answers
Try this
Thanks for your suggestion.
I tried that before and get a build error -
Fixed it with -
Thanks for your help.