0

I am working on a visualforce page that displays names of contentdocumentlinks, and as the page is currently, it shows 2 columns: numbers and names of the contentdocuments. I want to add a couple more columns: the size of the contentdocument(or contentversion) and the createddate of the contentdocument (or contentversion). I am not sure how to add those columns. Can anybody assist?

Here are the relevant snippets from my VF page and Controller:

VF PAGE:

<apex:page>
    <apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" />
    <apex:includeScript value="//cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.17.8/js/jquery.tablesorter.min.js" />
    <apex:stylesheet value="//cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.17.8/css/theme.blue.css" />
    <script>
        $j = jQuery.noConflict();
        $j(document).ready(function()
            {
                $j("[id$='accsTable']").tablesorter({theme: 'white', dateFormat : "dd/mm/yyyy"});
            });
    </script>
    <apex:form >
        <apex:outputPanel id="tstpopup">

            <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopup}">
              <b><u>Please select files you wish to delete:</u></b> 
                <br/>
               <apex:pageBlock >
        <!--    <apex:pageBlockButtons >
                <apex:commandButton value="Show Selected Files" action="{!processSelected}" rerender="table2"/>
            </apex:pageBlockButtons> -->
                <apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" id="table" title="All Accounts">
                    <apex:variable value="{!-1}" var="index" />
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                        <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                    </apex:column>
                <!--    <apex:column value="{!accWrap.acc.contentdocument.title}" /> --> 
                    <apex:column >
                        <apex:outputText >
                        <apex:variable value="{!index + 1}" var="index" />
                        {!index}
                        </apex:outputText>
                    </apex:column>
                    <apex:column headerValue="Name" value="{!accWrap.acc.contentdocumentid}" />
                </apex:pageBlockTable>
 <!-- <apex:pageBlockTable value="{!selectedAccounts}" var="c" id="table2" title="Selected Accounts">
                    <apex:column value="{!c.contentdocument.title}" headerValue="Account Name"/>
                    <apex:column value="{!c.contentdocumentid}" headerValue="Billing State"/>
                </apex:pageBlockTable> -->
                </apex:pageBlock>
                 <div align="center"  draggable="false" >
                <apex:commandButton value="Delete selected" action="{!processSelected}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
                </div>
                <br/>
            </apex:outputPanel>
            
            
            
            <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!allSet}"> 
                <b> Files deleted!</b>
                <br/>
                 <div align="center"  draggable="false" >
                <apex:commandButton value="Return" action="{!cancel}"/>
                </div>
            </apex:outputPanel>

     </apex:outputPanel>
    </apex:form>
</apex:page>

CONTROLLER:

public without sharing class FileDeletionPageController {

    public Id referralId { get; set; }
    public Lead ref { get; set; }
    public Id userId {get; set;}
    public static boolean flag = true;
    public string dateOfBirth {get; set;}
    public string expensiveMeds {get; set;}
    public List<ContentDocumentLink> listofattach {get; set;}
    public List<wrapAccount> wrapAccountList {get; set;}
    public List<ContentDocumentlink> selectedAccounts{get;set;}
    public List<ContentDocumentLink> attachmentsFullList {get; set;}
    public boolean allSet {get;set;}
    public boolean showFilesSection {get;set;}
    public boolean authAlreadyRequested {get;set;}
    public FileDeletionPageController(ApexPages.StandardController controller) {
         ref = (Lead) controller.getRecord();
         referralId = ref.Id;
         userId = UserInfo.getUserId();
         Lead ref = [select id,Name,Patient_DOB__c,Insurance_Company_formula__c,PayerPolicy__c, facility__r.name, 
                     Primary_Diagnosis__c,Referral_Account_formula__c
                       
            from lead where id = :ref.id];
         
         dateOfBirth = string.valueof(ref.Patient_DOB__c);
         string year = dateOfBirth.substring(0,4);
         string month = dateOfBirth.substring(5,7);
         string day = dateOfBirth.substring(8,10);
         dateOfBirth = month + '/' + day + '/' + year;
         
         listofattach = [SELECT Id, contentdocument.title,contentdocumentid 
                          FROM ContentDocumentLink 
                          WHERE LinkedEntityId in 
                            (select id from lead where id = : referralId)];
         set<id> contentdocumentids = new set<id>();
         for (contentdocumentlink loa : listofattach){
             contentdocumentids.add(loa.ContentDocumentId);
         }
         List <ContentVersion> contentVersions = new list<contentversion>();
         contentVersions  = [SELECT title, Attach_to_auth_request__c, FileExtension,contentdocumentid 
                              FROM ContentVersion 
                              WHERE ContentDocumentId in :contentdocumentids and 
                                    Attach_to_auth_request__c = true and
                                    islatest !=false];
         set<id> filteredContentDocumentIds = new set<id>();
         for (contentVersion cont : contentVersions){
             filteredContentDocumentIds.add(cont.contentdocumentid);
         }
         attachmentsFullList = [SELECT Id, contentdocument.title,contentdocumentid 
                FROM ContentDocumentLink where LinkedEntityId in 
                       (select id from lead where id = : referralId) and 
                       ContentDocumentId in :filteredContentDocumentIds];
         if (attachmentsFullList.size() > 0){
             showFilesSection = true;
         }
         
         
         if(wrapAccountList == null) {
            wrapAccountList = new List<wrapAccount>();
            for(ContentDocumentLink a: listofattach) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapAccountList.add(new wrapAccount(a));
              //  wrapaccountlist.sort();
            }
        }
    }
}
4
  • You'll need to use edit and include the WrapAccount class. Also , to make it easier on us, use edit and make your VF cleaner by getting rid of the commented out sections and properly indent the tags – cropredy Apr 8 at 19:10
  • Hi cropredy, I was able to figure this out but now I am stuck on the next piece, which is namely how to make those columns sortable. Should I edit my question here or add a new question? – Michael M Apr 8 at 19:27
  • yes, new question for sortable -- which looks like for you a jQuery solution - in your new question, please just post the minimum code needed to understand your issue. – cropredy Apr 8 at 19:29
  • yes- that's what i was attempting with the jQuery solution but it doesn't seem to work.. Ok will do, thanks! – Michael M Apr 8 at 19:31

Your Answer

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

Browse other questions tagged or ask your own question.