1

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

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

所以步骤是我创建一个帐户 Acct1。然后我删除了该帐户,但在调用 myClass.Details 时,我对具有 Acct1 的 ID 的帐户执行了选择。

问题是该行已被删除,因此我得到 0 行。Salesforce 中是否需要某种设置才能等到触发器完成后再删除实体?

4

1 回答 1

0

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

触发代码:

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

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

于 2021-10-05T16:58:33.253 回答