dackdive's blog

新米webエンジニアによる技術ブログ。JavaScript(React), Salesforce, Python など

[salesforce]SObjectのIDが取得できるタイミング

オブジェクトがレコードとしてDBに登録されるとIDが取得できるようになる。

Account a = new Account(
    name = 'テストアカウント'
);

System.debug(a.id);  // これはnull
insert a;
System.debug(a.id);  // これはID(18桁の文字列)が返る

へー。
新たにSOQL発行してオブジェクトを取得し直さなくてもいいんですね。