1

I am trying to essentially re-create a custom object and then make the new copy a child to the original object. What is the quickest way to do this ? I have looked into it on App Exchange but it appears that all of the cloning apps I've seen (iClone ; Astrea Clone) are really just about cloning records in order to maintain their related lists and such. I'm not trying to clone any records. I'm just trying to avoid re-creating the actual object from scratch.

Thank you very much for your help.

3 Answers 3

5

You can try this, but your milage may vary:

  1. Get Apache Ant and the Migration Tool.
  2. Create a package.xml file that retrieves your custom object.
  3. Retrieve your custom object.
  4. Rename the file in src/objects that is the current object.
  5. Modify the file itself to reflect the new name, label, etc.
  6. Modify src/package.xml to reflect the new custom object.
  7. Deploy this new object; all fields will be cloned and the entire object created.
  8. Create the master-detail relationship, tab, etc, using the UI.

This technique is effective when the custom object has more than about 20 fields or so, from a time-consumption perspective.

3
  • Thank you very much sfdcfox. That sounds just like the solution I need. Unfortunately it also sounds beyond my skill set (I've never created a package xml file). That's why I was just wondering if there was an app which can be used for this. I guess I'm asking a little too much here ... ?
    – Zoom_v
    Commented Jul 17, 2013 at 14:43
  • 1
    I'm designing an app that fills that gap, but it doesn't do you any good today. If you had that same question a few months from now, it might be a different story.
    – sfdcfox
    Commented Jul 17, 2013 at 14:53
  • 1
    Oh nice. I would be interested in seeing that when it's complete. In the meantime, I was guided here : learnsf.wordpress.com/2013/01/10/… I'm now going through this method. Thank you for your insight sfdcfox, and good luck with the app.
    – Zoom_v
    Commented Jul 17, 2013 at 15:48
1

Quickest way I found was to use jsforce. My method is basically retrieving the source object's metadata, changing it's name all across, and then creating a new custom object with the changed metadata. Nice & easy, except that it doesn't clone the source object's page layouts (not yet supported by jsforce, it seems).

Here's some code for reference in case this helps anyone:

import { config } from './config.js';
import * as jsforce from 'jsforce';

String.prototype.replaceAll = function (search, replacement) {
    var target = this;
    return target.replace(new RegExp(search, 'g'), replacement);
};

function main() {
    let conn = new jsforce.Connection({
        loginUrl: config.salesForceLoginUrl
    });
    console.log('login with', config.salesForceUser);
    conn.login(config.salesForceUser, config.salesForcePassword + config.salesForceSecurityToken,
        function (err, loginRes) {
            if (err) { return console.error(err); }
            console.log('logged in!');
            getMetadata(conn);
        });
}

function getMetadata(conn) {
    console.log('get meta data');
    var fullNames = ['My_Source_Object__c'];
    conn.metadata.read('CustomObject', fullNames, function (err, meta) {
        if (err) { console.error(err); }
        console.log(meta);
        return;

        let sMeta = JSON.stringify(meta);
        sMeta = sMeta.replaceAll('My_Source_Object', 'My_Target_Object')
        sMeta = sMeta.replaceAll('My Source Object', 'My Target Object')
        conn.metadata.create('CustomObject', JSON.parse(sMeta), function (err, results) {
            if (err) { console.err(err); }
            console.log('new custom object created!');
        });
    });
}

main();
0

If you are not confident with Ant, you could use the Force.com IDE to download the XML definition of the object and copy it to a new object (might be easier to create the object in Salesforce first).

On a different note, the fact that you need to clone an object makes me think there might be something wrong in the way you are designing your schema. Could a field be used to indicate the subtype of the object? That's just my guess though, you might have valid reasons.

1
  • I know what you mean by questioning the schema, and I hate the idea of creating a new duplicate object. However, I think in this case a new object will be needed. I am really just creating what will be a more detailed version of the already existing object. We need to keep a bunch of the fields, page layouts, and validation rules - and then we'll add a bunch of other components afterwards.
    – Zoom_v
    Commented Jul 17, 2013 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .