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
Mayur TripathiMayur Tripathi 

Hi I am trying to create a trigger on Account object that create a case for particular user (hardcoded userid)everytime a new Account created but nothing is coming in the case here is the code :

trigger DedupeReminder on Account (after update) {
    for (Account acc: Trigger.New){
        Case c      = New Case();
        c.subject   ='Dedupe this Account';
        c.OwnerId   = '0057F000000tnLj';
        c.AccountId = acc.Id;
        insert c;
    }
}
Best Answer chosen by Mayur Tripathi
sfdcMonkey.comsfdcMonkey.com
hi mayur 
use below trigger, it should be on after insert not after update
 
trigger DedupeReminder on Account (after Insert) {
    for (Account acc: Trigger.New){
        Case c      = New Case();
        c.subject   ='Dedupe this Account';
        c.OwnerId   = '0057F000000tnLj';
        c.AccountId = acc.Id;
        insert c;
    }
}
i hope it helps you.
 Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks 
sfdcmonkey.com 
 

All Answers

Dayakar.DDayakar.D
Hi Thirpathi,

You are using after Update in trigger event, so when you create record trigger will not fire, if you add after Insert it will work for you.
 
trigger DedupeReminder on Account (after Insert) {
    for (Account acc: Trigger.New){
        Case c      = New Case();
        c.subject   ='Dedupe this Account';
        c.OwnerId   = '0057F000000tnLj';
        c.AccountId = acc.Id;
        insert c;
    }
}

Best Regards,
Dayakar,D
sfdcMonkey.comsfdcMonkey.com
hi mayur 
use below trigger, it should be on after insert not after update
 
trigger DedupeReminder on Account (after Insert) {
    for (Account acc: Trigger.New){
        Case c      = New Case();
        c.subject   ='Dedupe this Account';
        c.OwnerId   = '0057F000000tnLj';
        c.AccountId = acc.Id;
        insert c;
    }
}
i hope it helps you.
 Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks 
sfdcmonkey.com 
 
This was selected as the best answer
Mayur TripathiMayur Tripathi
Thanks Guys...