Take the 2-minute tour ×
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.

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
add comment

2 Answers 2

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
add comment
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();
i2.text='Sofas';

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

List<items > lst=new List<items >();
lst.add(i1);
lst.add(i2);
lst.add(i3);


ItemWrapper i=new ItemWrapper();
i.text='Furniture';
i.items=lst;

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
add comment

Your Answer

 
discard

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.