0

I am trying to form dynamic package.xml in my code.So i want a sample template as attachment under a object.I tried as below.It's not working .

Code:-

String str='<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <contentToreplace></contentToreplace>
    <version>37.0</version>
</Package>';

Attachment att = new Attachment();                    

att.Description = 'ANT Component';

att.Body = Blob.valueOf();
att.ParentId = 'a4D4B0000001Vxu';
insert att;

I will replace this by the values i formed

Please help me

1

You missed to pass str as parameter of Blob.valueOf method att.Body = Blob.valueOf(str); and Name of attchment

The following code works:

String str='<?xml version="1.0" encoding="UTF-8"?>'
    +'<Package xmlns="http://soap.sforce.com/2006/04/metadata">'
        +'<contentToreplace></contentToreplace>'
        +'<version>37.0</version>'
    +'</Package>';

Attachment att = new Attachment();                    

att.Description = 'ANT Component';
att.Name = 'Ant';
att.Body = Blob.valueOf(str);
att.ParentId = '00Q0v0000019RaD'; // related record id
insert att;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.