1

我正在尝试将数据提交到服务器,并在服务器中挑选并存储在 salesforce 中。我得到的错误是服务器上的“尝试取消引用空对象”。所以我想知道问题是什么......下面是示例代码:

public static List<String> processAgentVisitSurvey(ProcessSurveySubmission.SurveySubmission submission, Map<String, Submission_Answer__c> answers, Person__c person) {

    // Load the TDR
    TDR__c tdr = loadTdr(person);

    if (tdr == null) {

        //Send an email saying that an unregistered person is trying to act a TDR

        // Send back the error message
        return new String[] { '0', 'User with handset Id ' + submission.imei + ' is not a TDR', 'SUPRESSMSG' };
    }

这是错误消息的来源。

有一个类重定向到此方法:

private static List<String> additionalProcessing(
        SurveySubmission surveySubmission,
        Survey__c survey,
        Person__c interviewer,
        Id intervieweeId
) {
    List<String> returnValues = new List<String>();

    Map<String, Submission_Answer__c> answers = parseSubmissionToMap(surveySubmission);

    // Find the name of the method that this survey hooks into to do its post processing
    try {
        if (survey.Post_Processing_Method__c.equalsIgnoreCase('None')) {
            returnValues.add('0');
            returnValues.add('There is no post processing method specified for this survey');
            returnValues.add('SUPRESSMSG');
        }
        else if (survey.Post_Processing_Method__c.equals('CKW_Registration')) {
            return CkwRegistration.processCkwRegistration(answers, interviewer);
        }
        else if (survey.Post_Processing_Method__c.equals('CKW_Baseline')) {
            return CkwRegistration.processCkwBaseline(answers, interviewer);
        }
        else if (survey.Post_Processing_Method__c.equals('CKW_Staff_Update')) {
            return CkwRegistration.processCkwUpdate(answers, interviewer);
        }
        else if (survey.Post_Processing_Method__c.equals('Subcounty_Registration')) {
            return CkwRegistration.processSubcounties(answers, interviewer);
        }
        else if (survey.Post_Processing_Method__c.equals('TDR_AGENT_VISIT')) {
            return TdrHelpers.processAgentVisitSurvey(surveySubmission, answers, interviewer);
        }
        else if (survey.Post_Processing_Method__c.equals('UDOM_RAIN_GUAGE')) {
            return UDoMSurveyProcessing.processDailyRainGauge(surveySubmission, answers, interviewer);
        }
        else if (survey.Post_Processing_Method__c.equals('UDOM_RAIN_GUAGE_REG')) {
            return UDoMSurveyProcessing.registerRainGauge(surveySubmission, answers, interviewer);
        }
        else if (survey.Post_Processing_Method__c.equals('MTN_CHANNELS')) {
            return MtnChannelsHelpers.processChannelsFFPSSurvey(surveySubmission, answers, interviewer);
        }
        else if (survey.Post_Processing_Method__c.equals('FHI_GROUP_REGISTRATION')) {
        return FHISurveysHelpers.processGroupRegistration(surveySubmission, answers, interviewer, survey.Survey_Name__c);
        }
        else if (survey.Post_Processing_Method__c.equals('FHI_HOUSEHOLD_REGISTRATION')) {
           return FHISurveysHelpers.processHouseholdRegistration(surveySubmission, answers, interviewer, survey.Survey_Name__c);
        }
//           else if (survey.Post_Processing_Method__c.equals('Colombia_Farmer_Registration')) {
//               return ColombiaFarmerRegistrationPostProcessor.processSubmission(surveySubmission, answers, interviewer);
//           }
        else if (survey.Post_Processing_Method__c.equals('FIELD_OFFICER_SUPPORT')) {
            return FieldOfficeHelpers.processFoSurvey(surveySubmission, answers, interviewer);
        }
//           else if (survey.Post_Processing_Method__c.equals('DATA_VALIDATOR_SPOT_CHECK')) {
//               return DataValidatorHelpers.processSpotCheck(surveySubmission, answers, interviewer);
//          }
//            else if (survey.Post_Processing_Method__c.equals('DATA_VALIDATOR_BACK_CHECK')) {
//                return DataValidatorHelpers.processBackCheck(surveySubmission, answers, interviewer);
//            }
        else if (survey.Post_Processing_Method__c.equals('EQUIPMENT_TRACKING')) {
            return EquipmentTrackingHelpers.processFieldOfficerSubmission(surveySubmission, answers, interviewer);
        }
    }
    catch (Exception e) {
        returnValues.add('0');
        returnValues.add(e.getMessage());
        returnValues.add('An error occured. Please contact support');
    }
    return returnValues;
}

我认为这很好......

请帮助因为我似乎没有看到任何问题 谢谢。我希望提供的代码就足够了。

4

2 回答 2

0

通常,当我遇到该错误时,我的第一反应是查找任何查询。在 APEX 中,当您将空值(预期与否)返回到单个项目中时,例如Person__c person = [query that returns objects};会引发该错误。

解决方案是确保数据返回到具体的 SObject 中,例如...

List<Person__c> persons = [Here is a query or method call];

然后,您将使用persons.size() 这服从 salesforce 的 Bulkify Everything 方法以及更强大的后端来检查列表。

抱歉,我无法提供更多支持,没有行号或调试日志的代码示例中的错误不是很明显。

祝你好运!

于 2014-12-21T22:06:02.807 回答
0

请注意:如果您尝试引用类的未实例化属性,也会出现此错误。

示例:如果您声明一个类的 List 属性,但从未实例化它,然后尝试添加到该列表,您将收到此错误。

于 2015-07-06T05:09:46.260 回答