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
akaaka 

lookup項目へのID値のset方法?

いかは、画面で入力されたデータを新規に
CustomObject1__c とCustomObject3__c
登録するプロセスですが

CustomObject1__c を登録したのち
CustomObject3__c のlink__cはCustomObject1__cへのlookup項目ですので
 List<CustomObjec・・・
IDを取得後
CustomObject3__c のlink__cへ代入すると

f_new.link__c =  idname;

Illegal assignment from LIST<oac__CustomObject1__c> to Id
というエラーが出ます

解決方法がわかりません

教えてください

public class new_kain {

    CustomObject1__c k_new;
    CustomObject3__c f_new;

    public PageReference save() {
         // Add the account to the database.  
         insert k_new;
       
         List<CustomObject1__c>idname=  [select id  from CustomObject1__c where Name =: k_new.name LIMIT 1 ];

         id.f_new.link__c =  idname;


 

g.engelg.engel

You could get the id from k_new -- it is automatically updated after the insert is executed:

 

       id.f_new.link__c = k_new.id

 

Or, if you need to retain the SOQL query, you would have to reference the element in the list returned by the query:

 

     id.f_new.link__c = idname[0]

 

For good coding style, you would want to handle the possibility that the result set is empty.  In this case, since you ran the query right after the insert, it should be safe.

akaaka

 

g.engelさん ありがとう

 
しかしながら 

id.f_new.link__c = k_new.id

  

  id.f_new.link__c = idname[0]

どちらに、しても

Variable does not exist: id.f_new.link__c

エラーが表示されます

 id.f_new.link__c

修飾子が

idとf_newとなるからだと思います

でも解決法がわかりません

 

akaaka

 f_new.link__c = idname[0].id; 
でOK!!

 

ありがとうございました