LoginSignup
0
0

Apex トリガーのサンプルコード

Last updated at Posted at 2022-08-01

まとめページに戻る

過去の質問でいくつか書いてきたのでまとめておきたいと思います。

具体的なサンプルコード

Apex バッチ

エラー、障害

We tried to insert Opportunity records as part of the challenge check, but the insert failed. Error: thException: OPP_INSERT | System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ClosedOpportunityTrigger: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0 with id 00T2w00001ATNBGEA5; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id] Trigger.ClosedOpportunityTrigger: line 12, column 1: [] Show Less

インサートの場所が違っていた。ループの中で行っていたため

関連資料

Map<Id, Account> mapAccount = new Map<Id, Account>([SELECT Id, Name FROM Account WHERE Id=:Trigger.New[0].AccountId]);

for(Contact cont: Trigger.new){
    if(cont.Id != null && mapAccount.containsKey(cont.AccountId)){
       t.AccountName__c = mapAccount.get(cont.AccountId).Name;
    }
} 
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0