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
magandrezmagandrez 

Problem on .doc creation process

Hi,

 

I have a ready made template for a .doc document that creates .doc documents the way the user wants. Now I they want to create many documents following this template, so I decided to create it using Javascript for VF and then retrieving the list of records they need, loop over those records creating the document that will go attached under a certain record. 

 

The code looks like this:

 

...

I retrieve here the list I need...

...

    //Create the attachment
    Attachment attach = new Attachment();
    attach.IsPrivate = false;
    //location contains the Id of the record where I want to attach de       document.
    attach.ParentId = location;
    attach.Name = 'A name.doc';
    Blob b;
    String body;											 
    
    //Loop over the records passing the Id to the template
    //and generating the final document
    for(Service_Reservation__c serv:services){

    	PageReference document = Page.getServiceOrder;
    	document.getParameters().put('id',serv.Id);

    	//Incremental body of the document.
        //for this I need a String, a Blob cannot be used
        //with arithmetics
   
        document.setRedirect(false);

        body += document.getContent().toString();
    	
    }
    //Turn the string into Blob to be attached under the desired record
    b = Blob.valueOf(body);
    attach.body = b;
    insert attach;    

 

The problem is that, given a list of service reservations...it creates a document attached with just the first document on it. I tried using setRedirect as false, but doesn't work. 

 

Any insights on why I cannot get a document with all the documents well created in the attachment?

 

Thanks!