ある会社には、カスタム オブジェクト order__C があり、このオブジェクトには、crder_number_c と呼ばれる必須の一意の外部 ID フィールドがあります。 外部 ID フィールドを使用して order_c レコードのリストに新しいレコードを挿入し、既存のレコードを更新するために必要な DML を実行するには、どのステートメントを使用する必要がありますか?
正解:D
To perform DML operations that insert new records and update existing records in a list of Order__c records using the external ID field Order_Number__c, you should use: Option D: upsert orders Order_Number__c; Upsert Statement: The upsert DML operation either inserts or updates records based on whether they already exist. By specifying the external ID field (Order_Number__c), Salesforce will match existing records based on this field. Syntax: upsert orders Order_Number__c; orders is the list of Order__c records. Order_Number__c is the external ID field used for matching. Reference: "The upsert statement matches the sObjects with existing records by comparing values of one field. If you don't specify a field, the upsert statement uses the sObject's ID to match data." - Apex Developer Guide: Upsert Statements Why Other Options Are Incorrect: Option A: merge orders; The merge statement is used to merge up to three records of the same object type, combining them into one. It is not suitable for upserting multiple records. Option B: merge orders Order_Number__c; merge does not accept an external ID field as a parameter. Option C: upsert orders; While this will perform an upsert based on the record IDs, it will not use the external ID field Order_Number__c for matching, which may not find existing records without IDs. Conclusion: Using upsert orders Order_Number__c; correctly instructs Salesforce to insert or update records based on the external ID field.