function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC Developer1SFDC Developer1 

Visualforce page attachment is not opening/downloading

Requirement - I want my image to get download or open after clicking on link and I have 2 additional column in my table which should get updated with name of person who click on the image and time.For the two column to get update I have method in my controller which get called after clicking on the image.
Problem facing - with outputlink I am able to open/download image but it is not passing value to controller hence my two column on my VF page is not updating.
with commandLink, It is passing value to my controller and my columns on vf page is also updating but I am not able to open/download image.
I am able to achieve 50%-50% from each of the functionality. Is there any way to combine both the functionality like downloading image and calling method in the controller.
Outputlink
apex:outputlink target="_BLANK"
value="/servlet/servlet.FileDownload?file={!AttachVar.attachmentID}"  {!AttachVar.attachmentName}

<apex:actionSupport event="oncomplete" action="{!DORESupdateHistory1}">
<apex:param value="{!AttachVar.attachmentID}" name="DORESSelectedId1" assignTo="{!DORESSelectedId1}"/>
</apex:actionSupport>

</apex:outputlink >

with commandLink, It is passing value to my controller and my columns on vf page is also updating but I am not able to open/download image.
<apex:commandLink action="{!DORESupdateHistory1}"
value="{!AttachVar.attachmentName}" >
<apex:param value="{!AttachVar.attachmentID}" name="DORESupdateHistory1" assignTo="{!DORESSelectedId1}"/>
</apex:commandLink>

Controller method

public String DORESSelectedId1{get;set;}

    public PageReference DORESupdateHistory1(){
        system.debug('--DORESSelectedId1---' + DORESSelectedId1);
        system.debug('--DORESSelectedId1---' + SelectedAttachmentId);
        List<Profile> Profile= [Select Name from Profile where Id =:UserInfo.getProfileId() LIMIT 1];
        list<attachment> relatedPaadAttachment = [select ID,parentID,name from attachment where ID=:DORESSelectedId1 limit 1];
        system.debug('--DORESSelectedId1---' + DORESSelectedId1);
        List<PAAD_Application_Attachment__c> ClickedAttachList1 = [Select id,Name,Type__c,CreatedDate,PAAD_Applicant__r.Name,Dores_Viewer_Name__c,Dores_Viewed_Time__c,Dores_Viewing_Status__c from PAAD_Application_Attachment__c where id = :relatedPaadAttachment[0].parentID]; //To get the clicked attachment Id
        if(ClickedAttachList1[0].Dores_Viewing_Status__c == 'Not Viewed'){
            ClickedAttachList1[0].Dores_Viewing_Status__c = 'Viewed';
            ClickedAttachList1[0].Dores_Viewed_Time__c = system.now();
            ClickedAttachList1[0].Dores_Viewer_Name__c = UserInfo.getName();
            update ClickedAttachList1;
            List<PAAD_Application_Attachment__c> viewedattach1= [SELECT Id,Dores_Viewing_Status__c FROM PAAD_Application_Attachment__c where Dores_Viewing_Status__c != 'Viewed' and PAAD_Applicant__c=:app.ID];
            List<PAAD_Application_Attachment__c> attach1 = [SELECT Id FROM PAAD_Application_Attachment__c where PAAD_Applicant__c=:app.ID];
           if(viewedattach1.size() == attach1.size()){
               List<PAAD_Applicant__c> attachcheck1= [SELECT Id,New_Dores_Attachment_Checker__c FROM PAAD_Applicant__c where ID=:app.ID];
               if(attachcheck1[0].New_Dores_Attachment_Checker__c == 'Y') {
                   attachcheck1[0].New_Dores_Attachment_Checker__c = '';
                   update attachcheck1;
               } 
           }
           List<AttachmentWrapper>  dummyWrapperList = new List<AttachmentWrapper>(); 
           for(AttachmentWrapper wrap : DORESAttachmentsWrapperList){
               if(DORESSelectedId1 !=  wrap.attachmentID){
                   dummyWrapperList.add(wrap);
               }else{
                   dummyWrapperList.add(new AttachmentWrapper(ClickedAttachList1[0].Type__c,ClickedAttachList1[0].Member__c,ClickedAttachList1[0].Description_Final__c, relatedPaadAttachment[0].ID,relatedPaadAttachment[0].name, ClickedAttachList1[0].CreatedDate,'Attached', ClickedAttachList1[0].Dores_Viewed_Time__c, ClickedAttachList1[0].Dores_Viewer_Name__c, ClickedAttachList1[0].Dores_Viewing_Status__c));    
               }
           }
           DORESAttachmentsWrapperList.clear();
           DORESAttachmentsWrapperList.addAll(dummyWrapperList);
        }  
        return null;
    }