Salesforce Apex トリガーを使用してルックアップ フィールドを設定したいのですが、エラーが発生し続けます。
System.StringException: Invalid id:
というカスタム オブジェクトがありますJob__c
。アカウントのカスタム選択リストがあります: Acct__c
.
ユーザーは として入力Acct__c
し、トリガーはルックアップ フィールド John Deer
に追加John Deer
する必要があります。Account__c
トリガーは次のとおりです。
trigger UpdateAccounts on Job__c (before insert) {
for (Job__c obj: trigger.new){
obj.Account__c = obj.Acct__c; //Exception is thrown here
}
スローされた例外:
System.StringException: Invalid id:
私は何か違うことを試しました:
List <Job__c> opListInsert = new List<Job__c>();
List <Job__c> opListUpdate = new List<Job__c>();
if(trigger.isInsert){
for(Job__c op:trigger.New){
if(op.Acct__c != Null){
op.Account__c = op.Acct__c;
opListInsert.add(op);
}
}
}
else if(trigger.isUpdate){
for(Job__c op:trigger.New){
if(op.Acct__c != Null && op.Acct__c !=trigger.oldMap.get(op.id).Acct__c){
op.Account__c = op.Acct__c;
opListUpdate.add(op);
}
}
}
そのコードはスローします:
Error:Apex trigger UpdateAccounts caused an unexpected exception, contact your
administrator: UpdateAccounts: execution of BeforeUpdate caused by:
System.StringException: Invalid id:
無効な ID であると表示されるのは、何が間違っているのでしょうか?