1

I have created a trigger in Salesforce :

 Trigger myTestDelete_D on Account (before delete) 
 {
   set<ID> ids = Trigger.oldMap.keyset(); 
   myClass.Details('Account','delete',ids); 
 }

So the steps are I create an account Acct1. I then delete the account , but in the call to myClass.Details I perform a select to the account with the id of the Acct1.

The issue is that the row has already been deleted and hence I get 0 rows. Is there some sort of setting that is required in Salesforce to wait until the trigger has completed before the entity is deleted ?

Kylie
  • 95
  • 1
  • 12

1 Answers1

0

I can't give you more details because we don't have the code of your "myClass" class but the query should retrieve the Accounts in the before delete trigger execution. I've created myself a trigger and set up some logs. Here are the results after deleting one Account record.

Trigger Code:

trigger Account on Account(before delete) {
  System.debug(Trigger.oldMap);
  System.debug(Trigger.newMap);

  List<Account> deletedAccounts = [
    SELECT Id, Name
    FROM Account
    WHERE Id IN :Trigger.oldMap.keySet()
  ];

  System.debug(deletedAccounts.size());
}

System.debug(Trigger.oldMap):

{0013O00000kVO2PQAW=Account:{Id=0013O00000kVO2PQAW, IsDeleted=false, MasterRecordId=null, Name=My Account, Type=null, ParentId=null, BillingStreet=null, BillingCity=null, BillingState=null, BillingPostalCode=null, BillingCountry=null, BillingLatitude=null, BillingLongitude=null, BillingGeocodeAccuracy=null, ShippingStreet=null, ShippingCity=null, ShippingState=null, ShippingPostalCode=null, ShippingCountry=null, ShippingLatitude=null, ShippingLongitude=null, ShippingGeocodeAccuracy=null, Phone=null, Fax=null, AccountNumber=null, Website=null, PhotoUrl=null, Sic=null, Industry=null, AnnualRevenue=null, NumberOfEmployees=null, Ownership=null, TickerSymbol=null, Description=null, Rating=null, Site=null, OwnerId=0053O0000044sSdQAI, CreatedDate=2021-10-05 16:47:55, CreatedById=0053O0000044sSdQAI, LastModifiedDate=2021-10-05 16:47:55, LastModifiedById=0053O0000044sSdQAI, SystemModstamp=2021-10-05 16:47:55, LastActivityDate=null, LastViewedDate=null, LastReferencedDate=null, Jigsaw=null, JigsawCompanyId=null, CleanStatus=Pending, AccountSource=null, DunsNumber=null, Tradestyle=null, NaicsCode=null, NaicsDesc=null, YearStarted=null, SicDesc=null, DandbCompanyId=null, OperatingHoursId=null}}

System.debug(Trigger.newMap):

null

System.debug(deletedAccounts.size()):

1

So, I would suggest that the problem is probably in the class that is doing the Query as the records are still available for querying in the before delete trigger.

  • Did you run this from the developer console , I already have the trigger resgistered so do i make the change there and where will the output be displayed .. I havent had to really debug the triggers till now – Kylie Oct 06 '21 at 05:31
  • Hi Kylie, I used the extensions from Visual Studio Code to turn on the logs. Then I went to the org and manually deleted one Account. That action generated the logs that I needed so I downloaded them also by using the Visual Studio Code Salesforce Extensions. If you are not familiar with that, you can just open the Developer Console and, why it's open, you can manually delete an Account. After doing that, in the logs section at the bottom you should be able to see the log that has been generated. – Óscar Gómez Balaguer Oct 06 '21 at 06:07