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

Help in testing this code



Got this piece of code that needs to be tested, am aware of unit testing to some extent but still a newbie. Can someone help me write/guide simple test class (called by a visual force page) for the code below, greatly appreciated. :)



public class PDFMerger
    public PDFMerger(ApexPages.StandardController controller) {


    private String getXmlString(pb__InventoryItem__c c, User u)
       datetime todayis =;
       String s = '<?xml version="1.0" encoding="UTF-8"?>' +
           '<xfdf xmlns="" xml:space="preserve">' +
           '<f href="https://*****"/>' +
           '<fields>' +
           '<field name="property address"><value>' + c.Unit_No__c + ' ' + c.Project__c + ' '+ c.Area__c + '</value></field>' + 
           '<field name="agent name"><value>' + u.Name + '</value></field>' + 
            '<field name="Date"><value>' + todayis + '</value></field>' +
            '<field name="Property Type"><value>' + c.pb__UnitType__c + '</value></field>' +
            '<field name="Number of Bedrooms"><value>' + c.pb__UnitBedrooms__c + '</value></field>' +
           '</fields><ids original="E348711A455B6041A503958ABEF555F0" modified="D4A9F66D55B86D47A4F3991DD9F07E18"/>' +
       return s;
    public PageReference XFDFInit() 
        pb__InventoryItem__c c = [SELECT Id, Ownerid, Name, pb__UnitType__c, pb__UnitBedrooms__c, Unit_No__c, Project__c, Area__c FROM pb__InventoryItem__c
        WHERE id = :ApexPages.currentPage().getParameters().get('id')];
        User u = [SELECT id, Name FROM User
        WHERE id = :c.Ownerid];
        String xmlContent = getXmlString(c, u);
        Attachment attachment = new Attachment();
        attachment.Body = Blob.valueOf(xmlContent);
        attachment.Name = c.Name + '.XFDF';
        attachment.ParentId = c.Id;
        insert attachment;
        PageReference contactPage = new PageReference('/' +;
        return contactPage;
Best Answer chosen by Admin (Salesforce Developers) 

HI Phantom,


I just ran across your post after having been recently perusing the article Introducing Test Methods. Check it out:


Hope this helps!