以下にSOQLがあり、sObjectのIDを含む結果が得られます。私の仮定は、クエリがSObjectのフィールドも返すことでした。たとえば、私のクエリstartDay__c
は、ShigotoShousaiオブジェクトのフィールドのような ""(日付)を取得しようとします。ただし、クエリの結果はsObjectインスタンスのIDにすぎません。
(親:ShigotoShousai
子:) ShigotoAssign
_
sObject[] result = [
SELECT
ShigotoShousai__r.id,
ShigotoShousai__r.startDay__c
FROM ShigotoAssign__c
];
system.debug(result)出力
shigotoAssign_ c:{Id = a06500000067aNjAAI、ShigotoShousai _c = a055000000DlHnOAAV}、shigotoAssign_ c:{Id = a06500000067aNoAAI、ShigotoShousai _c = a055000000DlHnTAAV})
プロパティ""の代わりにShigotoShousai__csObjectのIDを取得しましたstartDay__c
。出力は次のようになると思いました:
shigotoAssign__c:{ShigotoShousai__c=a055000000DlHnOAAV, startDay__c=2010-10-10},
shigotoAssign__c:{ShigotoShousai__c=a055000000DlHnTAAV, startDay__c=2010-10-13})
しかし、クエリ結果はちょうど私にShigotoShousai__csobjectのIDを返しました:(
これで、ID値がSであることがわかりhigotoShousai__c
、そのフィールドにアクセスしたいので、次のようにしました。
ShigotoShousai__c foo = (ShigotoShousai__c)result[0].get('ShigotoShousai__c');
//now I assume I can access to some fields like below
system.debug(foo.workDate);
そして、これは私にエラーを与えます:
System.TypeException: Invalid conversion from runtime
type Id to SOBJECT:shigotoShousai__c
次に、IDを使用してSObject(つまり、ShigotoShousai__c)を参照することはできないと考えました。
しかし、私はそのIDを持っています..どうすればアクセスできますstartDay__c
か?このIDを使用する方法はありますか?