Code Monkey home page Code Monkey logo

apex-xml-serialize's Introduction

Apex-XML-Serialize

Utility class for serializing a single or list of sObjects or Apex Classes object to a XML string. The goal is to mimic functionality of the standard JSON.serialize() method.

Usage

To serialize an object into XML string, call the serialize(objectToSerialize, NameOfTopLevel) method by passing it the object or list of objects to serialize and the name of the top-level XML wrapper.

Single Object

// Query for an Account record
Account account = [Select Id, Name From Account Limit 1];

// Call the method to serialize the object
String xmlString = XmlUtility.serialize(account, 'Account');

Returns:

<Account>
    <attributes>
        <type>Account</type>
        <url>/services/data/v35.0/sobjects/Account/00128000002PMvhAAG</url>
    </attributes>
    <Id>00128000002PMvhAAG</Id>
    <Name>Ben Edwards Ltd</Name>
</Account>

Array of Objects

// Query for an Account records
List<Account> accounts = [Select Id, Name From Account];

// Call the method to serialize the object
String xmlString = XmlUtility.serialize(accounts, 'Accounts');

Returns:

<Accounts>
    <Account>
        <attributes>
            <type>Account</type>
            <url>/services/data/v35.0/sobjects/Account/00128000002PMvhAAG</url>
        </attributes>
        <Id>00128000002PMvhAAG</Id>
        <Name>Ben Edwards Ltd</Name>
    </Account>
    <Account>
        <attributes>
            <type>Account</type>
            <url>/services/data/v35.0/sobjects/Account/00128000002PMvhAAH</url>
        </attributes>
        <Id>00128000002PMvhAAH</Id>
        <Name>Ben Enterprises Global Worldwide Ltd</Name>
    </Account>
</Accounts>

apex-xml-serialize's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.