19626
2023-07-17 254ea442ff0e0a7a97e9f481e9f127a782cba840
force-app/main/default/classes/BidAnnounceIframeController.cls
@@ -8,17 +8,24 @@
    
    public void init() {
        Bid_Announcement__c bid = [select Id, Web_URL__c, Web_URL_ModifiedDate__c from Bid_Announcement__c where Id = :recordId];
        List<Attachment> attList = [select Id, LastModifiedDate from Attachment where ParentId = :recordId order by LastModifiedDate desc limit 1];
        Attachment att = null;
        if (attList.size() > 0) {
            att = attList[0];
        // List<Attachment> attList = [select Id, LastModifiedDate from Attachment where ParentId = :recordId order by LastModifiedDate desc limit 1];
        List<ContentDocumentLink> links = [select ContentDocumentId from ContentDocumentLink where LinkedEntityId =: recordId];
        List<Id> idList = new List<Id>();
        for (ContentDocumentLink link : links) {
            idList.add(link.ContentDocumentId);
        }
        List<ContentDocument> docList = [select Id,ContentModifiedDate from ContentDocument where Id in: idList order by ContentModifiedDate desc limit 1];
        // Attachment att = null;
        ContentDocument doc = null;
        if (docList.size() > 0) {
            doc = docList[0];
        }
        
        if (bid.Web_URL__c != null) {
            // 中标通知书URL更新时间 と 最新Attachmentの時間と比較、新しいものを適用
            if (att != null) {
                if (bid.Web_URL_ModifiedDate__c < att.LastModifiedDate) {
                    iframe = '/servlet/servlet.FileDownload?file=' + att.Id;
            if (doc != null) {
                if (bid.Web_URL_ModifiedDate__c < doc.ContentModifiedDate) {
                    iframe = '/lightning/r/ContentDocument/' + doc.Id + '/view';
                } else {
                    iframe = bid.Web_URL__c;
                }
@@ -29,8 +36,8 @@
            }
        } else {
            // Attachmentを適用
            if (att != null) {
                iframe = '/servlet/servlet.FileDownload?file=' + att.Id;
            if (doc != null) {
                iframe = '/lightning/r/ContentDocument/' + doc.Id + '/view';
            }
        }
    }