我有两个自定义对象 1. Customer 2.Complaint,它们是相互查找关系。
我有这样的问题,下面的触发器不起作用。我的要求是在插入投诉之前,首先它会检查电子邮件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 ');
}
}
}