2

Trying to display an image from attachment in Salesforce, on the First-time loading the image is not displayed but a blank image thumbnail is displayed when on inspect could find the Link with ID- if the link opened manually in a Tab or when the file is opened from the record, then the image is displaying in VisualForce page perfectly all the time till the session is logged out in Salesforce. if session logged out the same repeats

<apex:commandLink styleClass="slds-truncate" action="{!displaySignature}" 
          style="font-weight: bold;" reRender="eSignPanel">Show Signature
     <apex:param name="recId" value="{!resultPanelObj['Id']}"/>
 </apex:commandLink>

  <apex:outputPanel rendered="{!resultPanelObj['Id'] == displaySignFromRecId && displaySignFromRecId != 'null'}">
      <apex:image url="{!URLFOR($Action.Attachment.Download, eSignAttMap[resultPanelObj['Id']])}" width="25%" height="25%" 
               rendered="{!eSignAttMap[resultPanelObj['Id']] != 'null'}"/>
  </apex:outputPanel>

PS- Link am getting is working fine When on inspecting and copying the URL then opening it manually am getting the attachment and upon opening in browsers other than chrome it is working perfectly for the very first time itself but In chrome it doesn't open for the first Time - does it have to do with cookies or cache something

https://c.na73.content.force.com/servlet/servlet.FileDownload?retURL=https%3A%2F%2Fc.na73.visual.force.com%2Fapex%2FDemoPAge&file=00P1I000003PljjLKJ&_CONFIRMATIONTOKEN=VmpFPSxNakF4T4Kwd05DEFlNbFF3TlRveU9Ub3hOaTQxTmpUJQw2Wk9vbVF1ZXCiVV9SMGg5MURYZzh2LFlUQmhOamht&common.udd.actions.ActionsUtilORIG_URI=%2Fservlet%2Fservlet.FileDownload

This is the link found when on inspecting the image URL which works fine

  • What does the URL for the attachment look like? Is it for the same domain that the Visualforce page is using? – Daniel Ballinger Apr 18 '18 at 21:16
  • @DanielBallinger Link am getting is working fine When on inspect and copy the URL then open it manually am getting the attachment and upon opening in browsers other than chrome its working perfectly- does it have to do with cookies or cache something – SFDC Apr 19 '18 at 4:57
  • @DanielBallinger As I have told you upon opening the link manually then from the moment the attachment link displays the image in Visualforce, It was like I have to give a push for the very first time of the session after that all the attachment works well until the session is logged OFF. – SFDC Apr 19 '18 at 5:05
  • @DanielBallinger Please refer the question for further details and the Image URL – SFDC Apr 19 '18 at 5:37
  • 1
    Do you have mydomain enabled? I suspect you are missing a required session type and/or the corresponding cookie. When you open it directly in the browser the required cookie is set and subsequent requests succeed. You will likely need to use the Chrome dev network tools to compare the succeeding and failing requests. – Daniel Ballinger Apr 19 '18 at 20:05
0

Someone had asked a similar question on salesforce SE a while ago. Please have a look at his post: Displaying attachments on visual force page

<apex:repeat value="{!Case.Attachments}" var="att">
    <apex:panelgrid>
        <apex:image styleClass="vitality-check-img" url="{!URLFOR($Action.Attachment.Download, att)}" rendered="true"/>
    </apex:panelgrid>
</apex:repeat>
  • thanks for your time, URL is working good but the thing is attachment - the image is not displayed for the very first time – SFDC Apr 19 '18 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.