I saved an XML template file like the below in a library. Please note the text ApplicationTypeHolder and SubmissionTypeHolder in the file. I modified the original XML file and added those texts there. I have an object A. In detail view of the record of Object A, there is a vf page from where user can click a button generate a new XML file which has the Application Type value and Submission Type value. I replace those texts in apex with the respective object field values. Once the new XML file with data is generated it will be added as an attachment to the record.

            <class />
                <subclass />
                    <us_suggested-tech_center />
                     <us-total_number_of_drawing-sheets />
                     <us-suggested_representative_figure />

This was a simple task, The XML file was 1.5 MB in size. But We only needed to fill a few tags. Now this is getting complex as now we have to replicate the tags based on related items. For ex, if the record has 2 classes associate with that then I need to add two tags, also the heap size is getting bigger. What is the alternative solution to this.


I have seen a few XMLreader and dom.document class examples. XMLreader is used for inserting data into obj while dom.document was used to create a new xml file.

  • Can you factor the XML file into an outer template and an inner "component" that your code can compose to produce a final file? The heap size limit is doubled to 12MB in asynchronous code, which hopefully provides enough headway. – David Reed Mar 12 '18 at 13:23
  • 1
    I tried only the string replacement approach. I can accomplish this requirement using the string replacement method. But is this a good method? How others do this? Can this be done using XMLreader and DOM.document? – Saranya Mar 12 '18 at 13:42
  • 1
    @David Reed, The XML structure is for a PDF form (XFA form). That has different levels of nodes. I have not understand the XML file totally. I fill the pdf file using acrobat, I open it using notepad++ to view how the XML tags modified, try to make my code to do the same but with values from the records. – Saranya Mar 12 '18 at 14:03

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.