Showing posts with label OutputLink. Show all posts
Showing posts with label OutputLink. Show all posts

Wednesday, January 25, 2017

Different ways of navigation

Different ways of navigation


1. Use of <apex:outputLink> to navigate to a record detail page [applicable to Classic & Lightning]

1
2
3
<apex:outputLink value="{!URLFOR($Action.Contact.View, c.Id)}">
 {!c.LastName}
 </apex:outputLink>

2. <apex:commandLink/> as button to navigate to Contact Detail page without the use of controller method [applicable to Salesforce classic]:

1
2
3
4
<apex:commandLink action="{!URLFOR($Action.Contact.View, c.Id)}" 
value="Goto DetailPage" 
target="_blank" styleClass="btn" 
style="padding: 4px; text-decoration: none;"/>

3. Navigation with the use of `<apex:commandButton/>` through Controller method [applicable to Classic & Lightning]:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<apex:commandButton value="Goto DetailPage" action="{!gotoContactDetailPage}" 
    reRender="form">
    <apex:param name="contactid" value="{!c.Id}" assignTo="{!contactId}"/>
</apex:commandButton>


public PageReference gotoContactDetailPage()
{
    return (new ApexPages.StandardController (new Contact(Id=contactId))).view();
}

4. a. Use of formula field to open a visualforce page in Console and standard view page in Standard or Custom App. [applicable to Classic]

1
2
3
4
5
HYPERLINK("javascript:if(typeof(srcUp)=='function') {srcSelf('/apex/VisualforcePage?id=" & Id & "');} "+ 
" else {window.location.href='/" & Id & "'}" 
,Name 
, "_Parent" 
)

4.b. Use of formula field to open either User or Queue in Console and Standard View Page in Standard or Custom App.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
IF(BEGINS(Case_Owner_Id__c,'005'),
 HYPERLINK("javascript:if(typeof(srcUp)=='function') {srcUp('/" & Case_Owner_Id__c & "');} "+ 
 " else {window.open('/" & Case_Owner_Id__c & "')}" 
 ,Case_Owner_Name__c 
 , "_blank" 
 ),
 HYPERLINK("javascript:if(typeof(srcUp)=='function') {srcUp('/setup/own/groupdetail.jsp?id=" & Case_Owner_Id__c & "&isdtp=vw');} "+ 
 " else {window.open('/setup/own/groupdetail.jsp?id=" & Case_Owner_Id__c & "&isdtp=vw')}" 
 ,Case_Owner_Name__c 
 , "_blank" 
 )
)

5 .a. Take the value from the input field and pass that value as a parameter to Salesforce report. [applicable for Classic]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<apex:page>
    <apex:form>
            <apex:inputText id="theTextInput"/>
            <a href="javascript:window.open('https://cs21.salesforce.com/00Oq0000000YUvUEAW?pv0=' 
            + document.getElementById('{!$Component.theTextInput}').value 
            + '&pv1=2018-01-01');">
            click me
            </a>
    </apex:form>
</apex:page>

5. b.  Take the value from input field and pass that as a parameter to Salesforce report. [applicable to Lightning (Spring'17 feature)]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<apex:page>
    <apex:form>
            <apex:inputText id="theTextInput"/>
            <a href="javascript:window.open('https://na1.salesforce.com/one/one.app#/sObject/00OR0000000PCHYMA4/view'
            + '?t=1479844235107&fv0=New%20Business' 
            + document.getElementById('{!$Component.theTextInput}').value 
            + '&fv1=2018-01-01');">
            click me
            </a>
    </apex:form>
</apex:page>

6. Custom button to open a visualforce page in console and standard view page in Standard or Custom App. [applicable to Classic]

1
2
3
4
5
6
7
8
{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")} 
{!REQUIRESCRIPT("/support/console/28.0/integration.js")} 
var url = '/apex/VisualforcePage'; 
if (sforce.console.isInConsole()) { 
navigateToUrl(url + '?inline=1'); 
} else { 
window.open(url,'_self'); 
}

Note that: if  inline=1 is not specified, page will not be part of console.
7. Formula field open link to record details page or visualforce page [applicable to Classic & Lightning]

1
2
HYPERLINK( '/' + Id , Name, '_blank')
HYPERLINK( '/apex/visualforcePage', Name, '_blank')

8. Display screen without header and sidebar (Applicable for Console and Classic mode) calling from  custom button of Record Details page.


{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")} 
{!REQUIRESCRIPT("/support/console/28.0/integration.js")} 

var pageUrl = '{!URLFOR($Action.Activity.LogCall)}'; 
var parameters = '?title=Call&who_id={!Lead.Id}'; 
var link = pageUrl + parameters; 
if (sforce.console.isInConsole()) 
{ 
 srcUp(pageUrl); 
} else { 
 window.open(pageUrl + '&isdtp=mn' ,'_self'); 
}

9. Navigate to Standard Page or Visualforce page based on the recordtype. Create a formula Text field and use the following code.



 HYPERLINK(
   IF( RecordType.DeveloperName = 'Accounting', '/'+ Id , '/apex/yourVisualforcePage?id=' + Id
   ) 
    ,Name 
    , "_Parent" 
    )