当前位置:网站首页>Salesforce uses hyperlink formula field to implement custom jump

Salesforce uses hyperlink formula field to implement custom jump

2022-06-24 01:24:00 repick

a. A number of projects are completed

Digital content :

HYPERLINK("https://www.baidu.com/", "baidu1")

b.DB Search in , See what the stored data looks like

According to the search results 【target="_blank"】, Will jump to a new Tab.

Search results :

<a href="https://www.baidu.com/" target="_blank">baidu1</a>

c. detailed Page in , Drag the custom item in , To test

The result is as expected , Will open a new Tab.

※ Jump from the screen , Parameters can be specified

HYPERLINK("https://www.baidu.com/", "baidu1", '_self')

HYPERLINK("https://www.baidu.com/", "baidu3", '_top')

2. Practical application example

The above method helps us realize page Jump , In actual project applications , The jump logic is relatively complex , In this case , We can consider writing logic processing in the background ApexClass in .

a. First, to test , You need to create two custom numeric items for jump , Then prepare two parameters , Used for background judgment .

stay Opportunity detailed Page Configure two items on , Including items 1 Used to jump to 【https://bing.com/】 page ,

project 2 Used to jump to 【https://cn.bing.com/translator?mkt=zh-CN】.

project 1 Digital content :

HYPERLINK("/apex/MyLinkForVF?recordId="+Id+"&linkId=linkId001", "GoTo Bing")

project 2 Digital content :

HYPERLINK("/apex/MyLinkForVF?recordId="+Id+"&linkId=linkId002", "GoTo Bing translator")

b. establish VFPage With the corresponding ApexClass, Used for logical judgment

MyLinkForVF.page

<apex:page controller="MyLinkForVFController" action="{!navigationToLink}">
<!-- Begin Default Content REMOVE THIS -->
<h1>Congratulations</h1>
This is your new Page
<!-- End Default Content REMOVE THIS -->
</apex:page>

MyLinkForVFController

public with sharing class MyLinkForVFController {
    public Id recordId {get; set; }
    public String linkId {get; set; }
    public String resultURL { get; set; }
    public Boolean isMobile { get; set; }

    public MyLinkForVFController() {
        String recordId = ApexPages.currentPage().getParameters().get('recordId');
        String linkId = ApexPages.currentPage().getParameters().get('linkId');

        String header= ApexPages.currentPage().getHeaders().get('User-Agent');
        String apiName;
        String recordIdPrefix = recordId.substring(0, 3);
        Map<String,Schema.SObjectType> globalDescribeMap = Schema.getGlobalDescribe();
        for(String objectN : globalDescribeMap.keySet()) {
            Schema.DescribeSObjectResult result = globalDescribeMap.get(objectN).getDescribe();
            String prefix = result.getKeyPrefix();
            if(String.isNotBlank(prefix) && prefix.equalsIgnorecase(recordIdPrefix)) {
                apiName = result.getName();
            }
        }
        if (header.toLowerCase().contains('iphone')) {
            isMobile = true;
        } else {
            isMobile = false;
            if ('Opportunity'.equalsIgnoreCase(apiName)) {
                if ('linkId001'.equalsIgnoreCase(linkId)) {
                    resultURL = 'https://bing.com/';

                } else if ('linkId002'.equalsIgnoreCase(linkId)) {
                    resultURL = 'https://cn.bing.com/translator?mkt=zh-CN';

                }
            } else if ('Account'.equalsIgnoreCase(apiName)) {
                resultURL = 'https://www.baidu.com/';
            }
        }
    }
    public PageReference navigationToLink() {
        if(isMobile) {
            Pagereference pageRef;
            //pageRef = Page.xxxx;
            pageRef.getParameters().put('errorMessage', 'Mobile Access Error');
            pageRef.setRedirect(true);
            return pageRef;
        } else {
            PageReference pageRef = new PageReference(resultURL);
            pageRef.setRedirect(true);
            return pageRef;
        }

    }
}

Effect display :

原网站

版权声明
本文为[repick]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/11/20211118173422834b.html