public static Boolean isOpportunityExistAndLastModifiedInSpecifiedTime(Id accountId,DateTime SpecifiedTime) {
// 查询Account的IsExpired字段
Account acc = [SELECT Id, IsExpired__c
FROM Account
WHERE Id = :accountId];
// 获取Opportunity中与Account相关的所有Opportunity记录
List<Opportunity> oppList = [SELECT Id, LastModifiedDate
FROM Opportunity
WHERE AccountId = :accountId];
// 如果有Opportunity记录
if (!oppList.isEmpty()) {
// 查找Opportunity中最晚的LastModifiedDate
DateTime latestModifiedDate = oppList[0].LastModifiedDate;
for (Opportunity opp : oppList) {
if (opp.LastModifiedDate > latestModifiedDate) {
latestModifiedDate = opp.LastModifiedDate;
}
}
// 判断最晚的LastModifiedDate是否距离今天超过6个月
DateTime sixMonthsAgo = System.now().addMonths(-6);
if (latestModifiedDate > sixMonthsAgo) {
return true;//LastModifiedDate在6个月内
}
}
return false;
}