0

我有两个自定义对象 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 ');
        }
    }
}
4

1 回答 1

0

这个触发器根本不应该被编译。

你应该看到错误

循环变量必须是 Complaint__c 类型

Trigger.new是一个List<Complaint__c>

所以,有2个错误:

for (Shan__Complaint__c complaint : Trigger.new) {
    customerIds.add(complaint.Shan__customer__c);
...

for (Shan__Complaint__c complaint : Trigger.new) {
    Shan__cust__c customer = customers.get(complaint.Shan__customer__c);
...
于 2015-03-24T10:19:23.820 回答