2 つのカスタム オブジェクト 1. 顧客 2. 苦情があり、それらは相互に参照関係にあります。
以下のトリガーが機能しないなどの問題があります。私の要件は、苦情を挿入する前に、まず電子メール ID と連絡先番号を確認してから、苦情を登録することです。
trigger Demo on Complaint__c (before insert) {
Set<Id> customerIds = new Set<Id>();
for (Shan__Complaint__c complaint : Trigger.new) {
customerIds.add(complaint.Shan__customer__c);
}
Map<String, Shan__cust__c> customers =
new Map<String, Shan__cust__c>([SELECT Shan__cust_contact__c, Shan__cust_email__c
FROM Shan__cust__c WHERE id IN: customerIds]);
for (Shan__Complaint__c complaint : Trigger.new) {
Shan__cust__c customer = customers.get(complaint.Shan__customer__c);
if (customer == null || complaint.Shan__E_mail__c == customer.Shan__cust_email__c
&& complaint.Shan__Phone_Number__c == customer.Shan__cust_contact__c) {
complaint.adderror('Your phone and Email does not exists in out database ');
}
}
}