为什么SalesForce on before delete触发delete record before processing?

Why does SalesForce on before delete trigger delete record before processing?

我在 Salesforce 中创建了一个触发器:

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

所以步骤是我创建一个帐户 Acct1。 然后我删除了该帐户,但在对 myClass.Details 的调用中,我对 ID 为 Acct1.

的帐户执行了 select

问题是该行已被删除,因此我得到 0 行。 在删除实体之前,Salesforce 是否需要某种设置来等待触发器完成?

我无法为您提供更多详细信息,因为我们没有您的“myClass”代码 class,但查询应该在删除触发器执行之前检索帐户。我为自己创建了一个触发器并设置了一些日志。这是删除一条帐户记录后的结果。

触发代码:

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

因此,我建议问题可能出在执行查询的 class 中,因为记录仍然可用于在删除前触发器中查询。