Edit: Rephrased entire question.


I am writing a Java program to analyze some metadata on Salesforce and also modify some files.

I am trying to read a metadata file of type Profile into Profile object Salesforce provides: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_profile.htm

I was able to do so by the following code: http://paste.ofcode.org/CRZMZsfcwdTmXz4zzCwJqY

When I want to modify the metadata. e.g. add Field Permission etc. and save it into an XML file back again. I am using this code: http://paste.ofcode.org/fZQZaGu3DMjfsHdndwq2WD

However, the output is different than what I downloaded from Salesforce.

Source from Salesforce: http://paste.ofcode.org/tq6S48VyHx7MJFtai5ZqUM

Output from my app: http://paste.ofcode.org/FnRSMfNrsM4CrEQ5e9Nc5Y

Please assist :) Thanks !

  • @sfdcfox Could you please help? :)
    – sfdcdev
    Nov 28 '16 at 16:34

It's been a while since I wrote any Java code, but I think the XML output is appending a default namespace, I cribbed this form stackexchange.com which may be of use:

String nsURI = "http://soap.sforce.com/2006/04/metadata";
XMLOutputFactory outF = XMLOutputFactory.newFactory();
outF.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
XMLStreamWriter out = outF.createXMLStreamWriter(System.out);
  • Hi, thanks for your help. The write method on the profile object expects an XmlOutputStream. I get a compilation error when I provide something else. I am using the XmlOutputStram from the WSC
    – sfdcdev
    Nov 30 '16 at 7:50

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.