You need to sign in to do that
Don't have an account?
K Srikanth
Create list view from Apex
Hi,
I have a requriment to create list view from VF page.
Is there any way to create listview from apex
I have a requriment to create list view from VF page.
Is there any way to create listview from apex
First you need to create remote site setting with your salesforce URL.
Then you need to create a connection in your class
MetadataService.MetadataPort metadataservice = new MetadataService.MetadataPort();
metadataservice .SessionHeader = new MetadataService.SessionHeader_element();
metadataservice .SessionHeader.sessionId = UserInfo.getSessionId();
MetadataService.ListView listViewObj = new MetadataService.ListView();
listViewObj.fullName = 'Test_View';
llistViewObj.label = 'Test View';
llistViewObj.filterScope = 'Everything';
metadataservice.createMetadata(listViewObj );
You need to fewe modification in above code to create list view
https://www.cloras.com/blog/creating-custom-object-and-custom-fields/
You need to fill out those fields that is required for listView
https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_listview.htm
Note : Private list view cannot be created using metadata API.
All Answers
You can use an apex:enhancedList on your Visualforce page.
Review below links which have working examples.
https://salesforce.stackexchange.com/questions/32067/custom-list-view-to-display-vf-page
http://sfdcsrini.blogspot.com/2015/01/how-to-use-apexlistviews-tag-in.html
Hope above information was helpful.
Please mark as Best Answer so that it can help others in the future.
Thanks,
Vinay Kumar
Thanks for response.
Those are to display listviews on visualfroce page from apex. I need to create new list view from apex.
First you need to create remote site setting with your salesforce URL.
Then you need to create a connection in your class
MetadataService.MetadataPort metadataservice = new MetadataService.MetadataPort();
metadataservice .SessionHeader = new MetadataService.SessionHeader_element();
metadataservice .SessionHeader.sessionId = UserInfo.getSessionId();
MetadataService.ListView listViewObj = new MetadataService.ListView();
listViewObj.fullName = 'Test_View';
llistViewObj.label = 'Test View';
llistViewObj.filterScope = 'Everything';
metadataservice.createMetadata(listViewObj );
You need to fewe modification in above code to create list view
https://www.cloras.com/blog/creating-custom-object-and-custom-fields/
You need to fill out those fields that is required for listView
https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_listview.htm
Note : Private list view cannot be created using metadata API.
Can we put id's as filter in list view?
You need to create a ListViewFilter in which you need to define field, operation and value
example
Id (field)
Equals (operation)
yourid (value)
Below you can check the url for more details
https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_listview.htm
Hope this helps!
Can you help me how to create connection in class to excute above mentioned code.
Thanks.
//this the code that will create connection
https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataService.cls
https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataServiceExamples.cls
This will surely help you.
Can you please share the code. And also how to provide condition to listview.