简体   繁体   English

接收 sObject 错误:错误消息不会触发,而是收到系统错误

[英]Receiving sObject error: Error message does not fire and receiving a System error instead

Created a Contact Trigger and a ContactTriggerHandler class to produce an error if the Contact is related to a relationship that contains 'Pricing Letters' and any item in the Address or Email Address is blank.创建了一个联系人触发器和一个 ContactTriggerHandler class 以在联系人与包含“定价信函”的关系相关并且地址或 Email 地址中的任何项目为空白时产生错误。 Code compiles but receiving the error below.代码编译但收到以下错误。 Any help is appreciated.任何帮助表示赞赏。

ERROR: Review the errors on this page.错误:查看此页面上的错误。 ContactTrigger: execution of BeforeUpdate caused by: System.FinalException: SObject row does not allow errors Class.ContactTriggerHandler.IsPricingLetter: line 9, column 1 Trigger.ContactTrigger: line 5, column 1 ContactTrigger:执行 BeforeUpdate 引起:System.FinalException:SObject 行不允许错误 Class.ContactTriggerHandler.IsPricingLetter:第 9 行,第 1 列 Trigger.ContactTrigger:第 5 行,第 1 列

TRIGGER扳机

trigger ContactTrigger on Contact (before update) {
    if(trigger.isbefore && trigger.isupdate){
        Contact checkcontact = [SELECT id,Email,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry
                       FROM Contact WHERE id IN  : Trigger.new];
        ContactTriggerHandler.IsPricingLetter(checkcontact);
            }//End If isBefore && isUpdate
   }//End Class

TRIGGER HANDLER触发器处理程序

public class ContactTriggerHandler {
    public static void  IsPricingLetter(Contact con){
          //Get list of relationship records that contain Pricing Letters role on the Contact ID being triggered.
        for(AccountContactRelation c : [SELECT ContactId FROM accountcontactrelation WHERE roles INCLUDES ('Pricing Letters') AND Contactid = :con.Id]){
//If triggering Contact ID is present, check for missing mailing address components or missing email address.
         if(con.MailingStreet==null){
            con.addError('Mailing street on a Pricing Letter Contact cannot be null.'); 
                                }//End If Mailing Street
        if(con.MailingCity==null){
            con.addError('Mailing City on a Pricing Letter Contact cannot be null.');   
                                 }//End If Mailing City
        if(con.MailingPostalCode==null){
            con.addError('Mailing City on a Pricing Letter Contact cannot be null.');    
                                 }//End If Mailing Postal
        if(con.MailingState==null){
            con.addError('Mailing State on a Pricing Letter Contact cannot be null.');
                                 }//End If Mailing State
        if(con.MailingCountry==null){
            con.addError('Mailing Country on a Pricing Letter Contact cannot be null.');   
                                 }//End If Mailing Country
        if(con.Email==null){
            con.addError('Email Address on a Pricing Letter Contact cannot be null.');   
                                 }//End If Mailing Country
                    }//End For Loop
        
    }//End IsPricingLetter Method
     
}//End Class

Don't query.不要查询。 Last time I told you that if you query in a "before update" you'll get state of database before the edit, without values changed by the user.上次我告诉过你,如果你在“更新前”查询,你将在编辑前得到 state 的数据库,用户没有更改值。

You can't just addError on something you queried, potentially totally unrelated to the edit.您不能addError对您查询的内容添加错误,这可能与编辑完全无关。

ContactTriggerHandler.IsPricingLetter(trigger.new[0]);

it's bit dangerous (you check only 1st instead of all, problem if anybody does mass edit from a listview for example) but should be enough and "errorable".这有点危险(你只检查第一个而不是全部,例如,如果有人从列表视图中进行大量编辑,就会出现问题)但应该足够了并且“错误”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Camel-salesforce Sobject错误 - Camel-salesforce Sobject error Salesforce - 错误“DML 需要 SObject 或 SObject 列表类型:帐户” - Salesforce - Error "DML requires SObject or SObject list type: account" Salesforce API-错误:不支持sObject类型“组织” - Salesforce API - Error: sObject type 'Organization' is not supported 在 Apex 中创建自定义 sObject 时出现无效类型错误 - Invalid type error on Creating custom sObject in Apex 列表中没有可分配给SObject Test类错误的行 - List has no rows for assignment to SObject Test class error Apex 编译错误:不支持 sObject 类型“Book__c” - Apex Compile Error: sObject type 'Book__c' is not supported InsertData ampscript function 的接收错误“function 表达式无效” - Receiving error 'The function expression is invalid' for InsertData ampscript function Salesforce社区错误-describeCompactLayout不支持sObject类型“报告” - Salesforce Community Error - sObject type 'Report' is not supported in describeCompactLayout 列表没有行分配给SObject错误,尽管查询返回了行 - List has no rows for assignment to SObject error although query returns rows Salesforce Mobile SDK问题登录“接收远程访问授权错误” - Salesforce Mobile SDK Issue Login “Receiving Remote Access Authorization Error”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM