Monday, March 23, 2015

Useful Visualforce Actions for any object

You may have come across a case where you need to create custom links in a Visualforce page to create, view edit any object or a link to open a object list page. Also, When you click on Cancel button from Create, View or edit pages it will automatically taken you back to the Originated page.

Here are the quick snippets for the same.

Create an Object: 

You can replace Contact with any other object.

<!-- Create New Contact Action -->
<apex:outputLink value="{!URLFOR($Action.Contact.NewContact)}">
Create a New Contact
</apex:outputLink>

<!-- Create New Contact Action -->
<apex:outputLink value="{!URLFOR($Action.CustomObject__c.NewCustomObject__c)}">
Create a New Custom Object
</apex:outputLink>

View an Object: 

<apex:outputLink value="{!URLFOR($Action.Contact.View, '003G0000016qPH5')}">
    Contact1
</apex:outputLink>

<apex:outputLink value="{!URLFOR($Action.CustomObject__c.View, 'a00900000016iUl')}">
CustomObject__c Record
</apex:outputLink>

Edit an Object: 

<apex:outputLink value="{!URLFOR($Action.Contact.Edit, '003G0000016qPH5')}">
    Edit Contact1
</apex:outputLink>

<apex:outputLink value="{!URLFOR($Action.CustomObject__c.Edit, 'a00900000016iUl')}">
CustomObject__c Record
</apex:outputLink>

Go to Object List Page: 

<!-- For Standard Object like Contact -->
<apex:outputLink value="{!URLFOR($Action.Contact.List,  $ObjectType.Contact)}">
Contact List
</apex:outputLink>

<!-- For Custom Object -->
<apex:outputLink value="{!URLFOR($Action.CustomObject__c.List,  $ObjectType.CustomObject__c)}">
CustomObject__c List
</apex:outputLink>

No comments:

Post a Comment