You need to sign in to do that
Don't have an account?
Rakesh K 60
Save data with delete/update/create
Hello Experts,
I need a quick confirmation with my code. The requirement is like this.
1. When I delete/create/update an Account.
2. There is this object called track.
3. I want this object to have the Account Name with type.
Thanks
I need a quick confirmation with my code. The requirement is like this.
1. When I delete/create/update an Account.
2. There is this object called track.
3. I want this object to have the Account Name with type.
trigger TrackMethod on Account (before delete) { List<Track__c> tList = new List<Track__c>(); if(Trigger.isBefore) { if(Trigger.isDelete){ for (Account m : [SELECT Id, Name FROM Account where Id IN :Trigger.old]) { Track__c t = new Track__c(); t.Name=m.name; t.action__c='Deleted'; t.type__c='Account'; tList.add(t); } } } else if(Trigger.isAfter) { for(Account m:trigger.New){ Track__c t = new Track__c(); t.Name=m.name; if(Trigger.isInsert){ t.action='Created'; } else if(Trigger.isUpdate){ t.action='Updated'; } t.type__c='Method'; tList.add(t); } } insert tList; }Please let me know if my code is correct.
Thanks
Hi Rakesh,
Looks like there is no relationship (Lookup or Master Detail) between Account and Track SObject. Is there any reason of doing that.
Is the Track SObject is to track multiple other SObject beside Account?
Is Type a picklist values? If Yes, what are the possible values.
When Account get's deleted I see you still retrieving Account Name but account might have gone so still taging the Track with the deleted account doesn't make sense.
I did a little cleanup with the code, but still need to look at the delete part based on my above question
Let me know
Try Below Code
Please Mark it As Best Answer If It Helps
Thank You!