+ Start a Discussion
magandrezmagandrez 

Problem automatizing .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

        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.

 

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

 

Thanks!

SammyComesHereSammyComesHere

Try setRedirect(true) and check if it works