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
h_rh_r 

カスタムフィールドのID取得

カスタムフィールドのIDの動的な取得に関して質問させていだたきます。

カスタムフィールドのIDに関して、環境毎にIDが変わってしまうため、
オブジェクト+項目名からの動的なカスタムフィールドIDの取得を行いたく考えております。

以下にて、2011年時点では不可とのスレッドがありますが、
https://developer.salesforce.com/forums/ForumsMain?id=906F00000009BObIAM
2014年1月現在、カスタムフィールドIDが取得できるような方法はないでしょうか。

以上、よろしくお願いいたします。
Marty C.Marty C.

b_rさん、こんいちは。

現在、まだカスタムフィールドIDを取得出来ないと思います。それより、どうしてb_rさんはその動的なIDがほしいですか。どんな目的がありますか。

ApexやSOAP APIでIDの必要はありません。カスタムフィールド名だけで、ビジネスオートメーションの多くが可能となります。

h_rh_r
ご回答ありがとうございます。
まだできないのですね。

以前使用したかった用途としては、標準編集画面をVFで上書きし、動的に初期値設定(URLパラメータ)後標準編集画面の呼び出し
今回使用したかった用途としては、VFからの標準ルックアップ検索呼び出し時の、ルックアップ検索条件のパラメータ設定です。
Marty C.Marty C.

b_rさんの用途は本当に面白いです!どの方法でルックアップURLを作成していますか。

以下の画面はb_rさんが述べたルックアップ検索条件ですか。

Account Lookup Search Filters

h_rh_r
Marty C.さん
画面はその画面のことです。

ルックアップ検索条件と言っているのは、
参照関係に付与できるルックアップ検索条件です。
今回やりたいこととしては、Contactの参照項目にAccountで事前に絞り込むルックアップ検索条件を指定し、
そのAccountをVFから動的に指定したかったのです。

以下ソースです。
<HTML>
<input  id="CFContactName" maxlength="255" name="CFContactName" onchange="getElementByIdCS('CFContactName_lkid').value='';" size="20" tabindex="6" type="text" style="position:relative;" />
                    <a href="javascript: myOpenLookup('CFContactName','003');" id="CFContactName_lkwgt" name="CFContactName_lkwgt" onclick="setLastMousePosition(event)" tabindex="6" style="position:relative; top:5px; left:-3px;">
                        <img src="/s.gif" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';"/>
                    </a>
                    <input type="hidden" name="CFContactName_lkid" id="CFContactName_lkid" value="" />
                    <input type="hidden" name="CFContactName_lkold" id="CFContactName_lkold" value="" />

<Javascript>
function myOpenLookup(inFieldName, inObjectPrefix){
        var fieldName = inFieldName
        var url = '';
        url += '/_ui/common/data/LookupPage?lkfm=editPage&lknm=' + inFieldName + '&lktp=' + inObjectPrefix;

        var lookup_object_prefix = "a1x"; //ルックアップ項目があるオブジェクトのPrefix⇒これは取得可能※環境依存
        var lookup_field_id = "00NQ0000001BaPm"; //ルックアップ項目のID⇒取得不可?※環境依存
        var lookup_filter_param_id = accountId; //ルックアップ条件となるレコードのID※動的指定
        url += '&lkent=' + lookup_object_prefix + '&lkfield=' + lookup_field_id + '&dplp=[null,"' + lookup_filter_param_id + '"]';
        openLookup(url,670,'1','&lksrch=' + escapeUTF(getElementByIdCS(inFieldName).value.substring(0, 80)));
    }
Marty C.Marty C.

b_rさん、こんいちは。

残念ですが、動的にフィールドIDを取得の実現可能な方法がないと思います。カスタム設定[1]を使用してどう思いますか。

カスタム設定を使用したら以下のJavaScriptはVfで[2]可能になります。実に動的じゃないが、b_rさんの用途に一番近い代替案だと思います。

var lookup_field_id = "{!$Setup.LookupCustomSetting__c.AccountLookupFieldID__c}";

[1]: カスタム設定 (https://help.salesforce.com/HTViewHelpDoc?id=cs_define.htm&language=ja)
[2]: Vfで (http://developerforcejp.s3.amazonaws.com/developer/docs/pages/salesforce_pages_developers_guide.pdf)