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
Anshuman ParhiAnshuman Parhi 

When any record from Account object is deleted, its name & deletion date/ time should be saved in this ‘Accounts Delete Log’ object.

Create custom object ‘Accounts Delete Log’ with fields:  Deleted Account Name, Account Deleted Date, Account Deleted Time. When any record from Account object is deleted, its name & deletion date/ time should be saved in this ‘Accounts Delete Log’ object
Best Answer chosen by Anshuman Parhi
Suraj Tripathi 47Suraj Tripathi 47
Hi Anshuman,
Greetings!
trigger AccountDeleteLog on Account (before delete) {
    if(trigger.isBefore && trigger.isDelete){
        List<Accounts_Delete_Log__c> delLogList = new List<Accounts_Delete_Log__c>();
        for(Account acc : Trigger.old)
        {
            Accounts_Delete_Log__c delLog = new Accounts_Delete_Log__c();
            delLog.Name = acc.Name;
            delLog.DeletedTime__c = Date.today();
            delLog.DeletedBy__c = UserInfo.getUserId();    //lookup field with User Object
        delLogList.add(delLog);
        }
        if(!delLogList.isEmpty()) {
            INSERT delLogList;
        }
    }
}
If you find your Solution then mark this as the best answer. 

Thank you!
Regards,
Suraj Tripathi

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Anshuman,

>> https://trailhead.salesforce.com/content/learn/modules/create-a-custom-object-quick-look/create-a-custom-object

For creating a custom object with your needs you can follow the above link and modify it to your needs.

For the trigger prat you can use the below snippet and modify it accordingly:
 
trigger AccountDelTri on Account (before delete) {
if(trigger.isbefore && trigger.isdelete){
list<Accounts_Delete_Log> RecordstoI = list<Accounts_Delete_Log>();
for (Account TempA : Trigger.old)
        {
           Accounts_Delete_Log tempADL= new Accounts_Delete_Log();
tempADL.Deleted=true;
tempADL.AccountName= TempA.Name;
tempADL.DeletedDate= Date.today();
tempADL.DeletedTime = Datetime.now();
RecordstoI.add(tempADL);
        }//end main for
if(RecordstoI.size()>0)
{insert RecordstoI;}
}
}//end trigger

To modify date you can check this link: https://www.salesforcecodecrack.com/2020/04/format-dates-and-time-using-apex-in.html

Please do note this is a sample snippet and you need to modify it accordingly.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Suraj Tripathi 47Suraj Tripathi 47
Hi Anshuman,
Greetings!
trigger AccountDeleteLog on Account (before delete) {
    if(trigger.isBefore && trigger.isDelete){
        List<Accounts_Delete_Log__c> delLogList = new List<Accounts_Delete_Log__c>();
        for(Account acc : Trigger.old)
        {
            Accounts_Delete_Log__c delLog = new Accounts_Delete_Log__c();
            delLog.Name = acc.Name;
            delLog.DeletedTime__c = Date.today();
            delLog.DeletedBy__c = UserInfo.getUserId();    //lookup field with User Object
        delLogList.add(delLog);
        }
        if(!delLogList.isEmpty()) {
            INSERT delLogList;
        }
    }
}
If you find your Solution then mark this as the best answer. 

Thank you!
Regards,
Suraj Tripathi
This was selected as the best answer