Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a treeview in Visualforce Page. User can reorder the tree structure. Order of any level can be changed or the level itself can be changed using javascript. Now I need to have this stored inside the database. Any particular database design to adopt treeview which best suitable for SF? I am planing to store this in Custom setting As this feature is common for entire Org. Is it good to use custom setting for this purpose?

share|improve this question
up vote 6 down vote accepted

If you do not have strong reasons to turn your tree into multiple objects in the database then simply storing its JSON text representation in the database is the simplest approach. Unfortunately custom settings only support text fields up to 255 characters though, so you will need to store the JSON in a "Text Area (Long)" field of some SObject or other, or in a "well known name" Document.

Assuming you have server-side processing needs, Apex has JSON.deserialize (and other methods) to turn the JSON into Apex objects or maps.

share|improve this answer
public class ItemWrapper {

public class Items {
    public String text;

public String text;
public List<Items> items;

Here is the Wrapper Object for the your JSON structure and now one needs to just construct this class as an object and then the JSON can be dynamically generated using as below

items i1=new items();
i1.text='Tables & Chairs';

items i2=new items();

items i3=new items();
i2.text='Occasional Furniture'

List<items > lst=new List<items >();

ItemWrapper i=new ItemWrapper();

String json=JSON.serialize(i);

In nutshell construct your schema in salesforce to generate the necessary structure with child and parent record

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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