LoginSignup
2
1

フローで Salesforce 組織ベース URL を取得する方法

Last updated at Posted at 2022-12-22
  • How to Get Salesforce Org Base URL in Flow

  • フローで Salesforce 組織のベース URL を取得する

  • フローで現在のコミュニティ URL を取得する

  • ネットワーク ID を渡すと、レコードの完全な URL を取得します

最も安全な方法は、呼び出し 可能なApex クラスから URL メソッドであるgetSalesforceBaseUrl()を呼び出すことです。getSalesforceBaseUrl() メソッドは、Salesforce 組織への現在の接続の URL を返します。一方、 toExternalForm ()は現在の URL の文字列表現を返します。

global class GetOrgBaseUrl{
    @InvocableMethod(Label='Get Salesforce base and record url')
    global static List<Results> getBaseUrl(List<sObject> sourceRecords){
        
        List<Results> sfdcURLs=new List<Results>();
        for(sObject obj:sourceRecords){
            Results r=new Results();
            
            r.sfdcBaseURL=URL.getSalesforceBaseUrl().toExternalForm();
            r.sfdcRecordURL=URL.getSalesforceBaseUrl().toExternalForm()+'/'+obj.id;
            
            sfdcURLs.add(r);
        }
        return sfdcURLs;
    }
    
    global class Results{
        
        @InvocableVariable
        global String sfdcBaseURL;
        
        @InvocableVariable
        global String sfdcRecordURL;
    }
}
@isTest
public class GetOrgBaseUrl_Test {
    
    @testSetup
    static void setup() {
        
        // Create a test account
    Account a = new Account(Name='Test Account');
        insert a;    
        }
    
    @isTest
    static void stripHtmlTags() {
        
        // Access the opportunity that was just created.
        Account account = [SELECT Id, Name FROM Account LIMIT 1];

        GetOrgBaseUrl.getBaseUrl(new List<sObject> {account});
    }
}

ちょっと、舐めていると思う。

getSalesforceBaseUrl() メソッドの廃止

API バージョン 59.0 以降は、getSalesforceBaseUrl() メソッドが非推奨になり、使用できなくなります。代わりに、組織の URL を取得する場合は getOrgDomainUrl()、Salesforce インスタンス上のリクエスト全体の URL を取得する場合は getCurrentRequestUrl() を使用します。API バージョン 59.0 以降で非推奨のメソッドを使用しようとすると、コンパイルエラーが発生します。

image.png

これを調べる発端となった質問

LEFT({!$Api.Partner_Server_URL_340}, FIND( '/services', {!$Api.Partner_Server_URL_340})).

私も回答しようと思ってましたが、別の人が

If the flow is launched from the experience site, this formula will get the experience site url instead of the internal url.
フローがエクスペリエンス サイトから起動された場合、この式は内部 URL ではなくエクスペリエンス サイトの URL を取得します

本当か?

I used the formula below in a sandbox with extended domains enabled and it worked fine.

LEFT({!$Api.Enterprise_Server_URL_570} , FIND('/services', {!$Api.Enterprise_Server_URL_570})) & "/lightning/r/Account/"& {!$Record.Id} &"/view"

2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1