【问题标题】:How to create custom error page in salesforce如何在 Salesforce 中创建自定义错误页面
【发布时间】:2019-11-05 10:48:17
【问题描述】:

如果 Salesforce 站点发生任何错误,它会显示带有类名的行号(请参阅下图),我们不想向用户显示。

相反,我想显示自定义页面,其中类名、行号等详细信息将保存在对象中或通过电子邮件发送给开发人员。

出于安全原因,我们希望对用户隐藏详细信息。即使我没有在站点->“错误页面”中找到任何选项来为顶点错误添加自定义页面。

【问题讨论】:

    标签: salesforce apex visualforce


    【解决方案1】:

    您可以为您认为可能发生异常的代码设置一个 try catch 块。 为了使用类名和行号获取错误日志的堆栈跟踪,我们有一个名为getStackTraceString() 的方法。此方法将错误的堆栈跟踪作为字符串返回。

    例子:

    try {
        Merchandise__c m = [
               SELECT Name
                    , Total_Inventory__c
                 FROM Merchandise__c
                LIMIT 1
        ];       
        Double inventory = m.Total_Inventory__c;
    } catch(Exception e) {
        System.debug('Exception type caught: ' + e.getTypeName());    
        System.debug('Message: ' + e.getMessage());    
        System.debug('Cause: ' + e.getCause());    // returns null
        System.debug('Line number: ' + e.getLineNumber());    
        System.debug('Stack trace: ' + e.getStackTraceString());    
    }
    

    请参考this链接查看其他有助于追踪错误的异常方法

    如果您需要更多帮助,请告诉我。谢谢:)

    【讨论】:

      猜你喜欢
      • 2017-10-03
      • 1970-01-01
      • 1970-01-01
      • 2015-07-25
      • 2014-02-22
      • 2013-02-13
      • 1970-01-01
      • 2021-02-07
      • 2014-11-10
      相关资源
      最近更新 更多