我无法为您提供更多详细信息,因为我们没有您的“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
因此,我建议问题可能出在执行查询的类中,因为记录仍然可用于在删除前触发器中进行查询。