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
UjwalaUjwala 

Create new view link in VF

Hi all,  i  want to add "create new view" link in visualforce page. i used <apex:listview> but i want only create new view link. How to code this??
Best Answer chosen by Ujwala
v varaprasadv varaprasad
Hi Ujwala,

Please check once below code : 
Open you list view first use bold one in your code

https://varaprasad5151-dev-ed.my.salesforce.com/ui/list/FilterEditPage?ftype=c&retURL=%2F003&cancelURL=%2F003%2Fo
 
<apex:page standardController="Contact" extensions="UrlClass" recordSetVar="Contacts">
    <apex:form >
        <apex:pageBlock title="Contact Info" >
            <apex:commandLink value="Create new view" action="{!SfdcUrl}"/>            
        </apex:pageBlock> 
    </apex:form>
</apex:page>
 
public class UrlClass {
  
    public UrlClass(ApexPages.StandardSetController controller){
        
    }
    public PageReference SfdcUrl(){
        string instanceurl =  System.URL.getSalesforceBaseURL().toExternalForm();
        system.debug('==instanceurl=='+instanceurl);
        instanceurl = instanceurl +'/ui/list/FilterEditPage?ftype=c&retURL=%2F003&cancelURL=%2F003%2Fo';
        system.debug('==instanceurl=='+instanceurl);
        PageReference pageRef = new PageReference(instanceurl);
        return pageRef;
       
    }
   
}


I hope it helps you.

Please let me know in case of any other assistance.


Thanks
varaprasad


 

All Answers

Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Ujwala,

May I suggest you please check the below link for reference. hope it helps.

Please mark it as best answer if the information is informative.

Thanks
Rahul Kumar
v varaprasadv varaprasad
Hi Ujwala,

Please check once below code : 
Open you list view first use bold one in your code

https://varaprasad5151-dev-ed.my.salesforce.com/ui/list/FilterEditPage?ftype=c&retURL=%2F003&cancelURL=%2F003%2Fo
 
<apex:page standardController="Contact" extensions="UrlClass" recordSetVar="Contacts">
    <apex:form >
        <apex:pageBlock title="Contact Info" >
            <apex:commandLink value="Create new view" action="{!SfdcUrl}"/>            
        </apex:pageBlock> 
    </apex:form>
</apex:page>
 
public class UrlClass {
  
    public UrlClass(ApexPages.StandardSetController controller){
        
    }
    public PageReference SfdcUrl(){
        string instanceurl =  System.URL.getSalesforceBaseURL().toExternalForm();
        system.debug('==instanceurl=='+instanceurl);
        instanceurl = instanceurl +'/ui/list/FilterEditPage?ftype=c&retURL=%2F003&cancelURL=%2F003%2Fo';
        system.debug('==instanceurl=='+instanceurl);
        PageReference pageRef = new PageReference(instanceurl);
        return pageRef;
       
    }
   
}


I hope it helps you.

Please let me know in case of any other assistance.


Thanks
varaprasad


 
This was selected as the best answer
UjwalaUjwala
Thank you so much rahul and varaprasad for your reply.

@rahul, link you described removes "create new view" link from page but i actually want only link on VF

@varaprasad , it worked but not displaying exact page because of instanceurl  it is giving as  ==instanceurl==https://idp-sso-dev-ed--c.ap5.visual.force.com 
instead of
https://idp-sso-dev-ed.my.salesforce.com  

method to get instance url is fetching current url of VF..