0

I want to pass multiple id into the getParameter method so that i can display multiple record in my excel file currently the id is overidden and it is taking the last id . So how to pass multiple id into getParameter method

Here is the vf page code

<apex:page standardController="Case" contentType="application/vnd.ms-excel#AccountExcel.xls " applyHtmlTag="false" showHeader="flase">
   <apex:pageBlock >
    <apex:pageBlockTable value="{!Case}" var="caseList" >
       <apex:column value="{!caseList.Unit_Number__c}"/>
       <apex:column value="{!caseList.Unit_Type__c}"/>
    </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>

Below is the apex class

global class AuditRequestReportController 
 {

    @Future(callout=true) 
    public static void auditReportCreate(Id id)
    {
        try
        {
        System.debug('Controller parent Id'+id);
        PageReference pagePdf = new PageReference('/apex/AuditRequestReport'); 
        System.debug('Page reference');
      //  pagePdf.getParameters().put('id', id);
        System.debug('parameter passed to vf page');

   List <Case> caseList =   [SELECT CaseNumber,Id, Unit_Number__c, Unit_Type__c from Case where Audit_Request_Name__c =: id];
for(Case cs : caseList)
{
   pagePdf.getParameters().put('id', cs.Id);
}       

        Blob pdfPageBlob;
        System.debug('Test');


        try{

            pdfPageBlob = pagePdf.getContent();

        }catch(VisualforceException e){
            pdfPageBlob = Blob.valueOf('error');
        }
          System.debug('Test2');
        ContentVersion cv = new ContentVersion(); 
        cv.ContentLocation = 'S'; 
        cv.PathOnClient = 'Audit Request Report.xls';
        cv.Origin = 'H'; 
        cv.Title ='Audit Request Report.xls';
        cv.VersionData = pdfPageBlob;
        insert cv; 
        System.debug('Test3');
        ContentVersion content = [select ContentDocumentId from ContentVersion where Id =: cv.Id]; 

        ContentDocumentLink cl = new ContentDocumentLink(LinkedEntityId = id, ContentDocumentId = content.ContentDocumentId, ShareType = 'I'); 
        System.debug('Test4' );
        insert cl;

        }
        catch(Exception e)
        {
            System.debug('Exception -'+e);
        }
    }

}

below is the trigger which is calling apex class method and passing parent record id

trigger AuditCompletedReport on Audit_Project__c (before update) {
     Audit_Project__c auditRefrence = Trigger.New[0];

    if(auditRefrence.Status__c == 'Completed')
    {
        System.debug('Status Completed');
        if( Trigger.oldMap.get( auditRefrence.Id ).Status__c != Trigger.newMap.get( auditRefrence.Id ).Status__c )
        {
             if(HelperClass.firstRun){


                AuditRequestReportController.auditReportCreate(auditRefrence.Id);

             System.debug('audit Reference id = '+auditRefrence.Id);
                HelperClass.firstRun = false;
            }

        }

}
}
1
  • Note that there's a typo - showHeader="flase" should be false. Not sure if that's causing issues or not Jan 6, 2020 at 18:19

2 Answers 2

1

Instead of using a for loop and using pagePdf.getParameters().put('id', cs.Id); to overwrite the id parameter everytime, try building a set of Ids and then add them all together at once, comma separated:

Set<Id> caseIds = new Set<Id>();

for (Case curCase : caseList) {
    caseIds.add(curCase.Id);
}

pagePdf.getParameters().put('ids', String.join(new List<Id>(caseIds),','));

Note that String.join() only works on List type, and using Set will ensure that you only have unique Ids and no duplicates.

1
0

Integer count = 1;

        for(Case cs : caseList)
        {
            pagePdf.getParameters().put('id'+count , cs.Id);
            count ++;
            System.debug('Count'+count );
            System.debug('Id ='+cs.Id);
        }       

I am using above code still not getting the output

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .