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
RameshwarRameshwar 

How to Clone Standard Object and the rules associated with object

Hi,
 
I want to create a clone copy of standard object - Account and all the associated validation rules in S-Control.
Is it possible to clone the standard object using AJAX or any other way in S-Control ?
 
 
Thanks
Rameshwar
Best Answer chosen by Admin (Salesforce Developers) 
werewolfwerewolf
You have to do a describe, generate a query that selects all the fields where the Account Id matches.  Then null out the Id field and do an insert of that same Account object you just got from the query.  That will create a clone, an identical copy of the original account, and it will run through the validation rules of course (as every insert will).

All Answers

werewolfwerewolf
You have to do a describe, generate a query that selects all the fields where the Account Id matches.  Then null out the Id field and do an insert of that same Account object you just got from the query.  That will create a clone, an identical copy of the original account, and it will run through the validation rules of course (as every insert will).
This was selected as the best answer
Steve ChadbournSteve Chadbourn
Can you elaborate on how you generate a query that returns all the fields please. I don't want to hard code a field list in my class.
werewolfwerewolf
Well, the reason Salesforce doesn't support "Select *" is precisely to discourage people from getting more fields than they need.  When you're sending that much data over the internet, it behooves you to try to minimize the set as much as possible.
 
That said, if you really need all the fields in your object, you'll first need to do a call to describeSObjects() for your object.  That will return a DescribeSObjectResult containing an array of Field objects.  From that array you'll want to pull out the names of the fields, and from that you can craft a list of fields for the Select portion of your query (or for the fields portion of the query if you're doing a retrieve or search call instead of query).
NonickNonick
Same here, anybody come up with a solution?