+ Start a Discussion
Vasavi VajinepalliVasavi Vajinepalli 

Fetching object's fields in a visualforce dynamically from custom settings

Hi,

I've custom objects and fields. I've created custom settings for these objects and fields. Is there any way to fetch these object's fields into a visualforce page dynamically(Not to hardcode the object name)? 
Please give me some examples as am new to salesforce :)
Best Answer chosen by Vasavi Vajinepalli
Jai ChaturvediJai Chaturvedi
Create a method with return type PageReference and call this method from the page reference method. Finally call page reference method from your vf page. Basically when we call method from vf page we should have method return type PageReference.

All Answers

Jai ChaturvediJai Chaturvedi
Hi,

You have to use apex for fetching teh values from custom setting and fill List<SelectOption> with those values. Then use this List<SelectOption> in page.
 
public List<SelectOption> fetchCustomSettingValues(){
	List<SelectOption> options = new List<SelectOption>();
	//Custom Setting API Name
	List<CUSTOMSETTINGAPINAME__C> testMap = CUSTOMSETTINGAPINAME__C.getall().values();
	for(CUSTOMSETTINGAPINAME__C s : testMap ){
		options.add(new SelectOption(s.Name, s.Name));
	}
	options.sort();
	if(!options.isEmpty()){
		options.add(0, new SelectOption('None', '--None--')); 
	}else{
		options.add(new SelectOption('None', '--None--')); 
	}
	return options ;
	}

I hope this will help you.
Vasavi VajinepalliVasavi Vajinepalli
Hi Jai,

I tried to do the above process by calling a method in VF page when change event occurs. And am returning the list but am getting below error

"Return type of an Apex action method must be a PageReference. Found: core.apexpages.el.adapters.ApexListELAdapter "

Can you please help me in returning list to VF page from controller.

thanks,
vasavi 
Jai ChaturvediJai Chaturvedi
Create a method with return type PageReference and call this method from the page reference method. Finally call page reference method from your vf page. Basically when we call method from vf page we should have method return type PageReference.
This was selected as the best answer
Vasavi VajinepalliVasavi Vajinepalli
Thanks Jai.. it worked!!!
Jai ChaturvediJai Chaturvedi
Can you please mark that as solution. Thanks Jai