Wednesday, June 18, 2014

Attachments in pageblockTable

1.first u need download image icon and save it in static Resources
======VFPAGE===================
<apex:page showHeader="false" controller="PBTAttachements" standardStylesheets="false">
  <apex:form >
     <apex:pageBlock >
       <apex:pageBlockTable value="{!pbtmethod}" var="p"  border="5" cellpadding="10">
          <apex:column value="{!P.NAME}" headerValue="Names" />
         <apex:repeat value="{!p.Attachments}" var="c" >
           <apex:column headerValue="ashok" >
       
               <apex:commandLink action="{!nextMethod}" value="">
                <apex:image url="https://na15.salesforce.com/resource/1403071470000/Attachment" value="{!C.NAME}" width="30px" height="30px"/>
                  <apex:param name="id" value="{!c.id}" id="id"/>
               </apex:commandLink>
             
           </apex:column>
               
              
            </apex:repeat>
       </apex:pageBlockTable>
     </apex:pageBlock>
  </apex:form>
</apex:page>
========CONTROLLER==========
public with sharing class PBTAttachements {

    public PageReference nextMethod() {
        id id=ApexPages.currentPage().getParameters().get('id');
        PageReference pr=new PageReference('/apex/attachmentspage?id='+id);
        return pr;
    }


    public List<account> pbtmethod {
       get;
       set;
    }
    public Pbtattachements(){
      string soql='select id,name,(select id, name from Attachments),phone from account';
      pbtmethod=Database.Query(soql);
    }
}

==========Scond VFPAGE===========
<apex:page controller="attachmentspage"  showHeader="false"  cache="true">
  <apex:form >
    <apex:pageBlock >
         <apex:image url="/servlet/servlet.FileDownload?file={!att}" width="250px" height="150px"/>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 ===========CONTROLLER=======
public with sharing class attachmentspage {
  public Transient Attachment att{set;get;}
  public attachmentspage(){
    id id=ApexPages.currentPage().getParameters().get('id');
    att=[SELECT Body,BodyLength,ContentType,Id,Name,Description FROM Attachment  where id=:id];
  }
}

No comments:

Post a Comment