试图取消引用空对象:Salesforce

问题描述 投票:1回答:2

我正在尝试将数据提交到服务器,在该服务器上将其选中并存储在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;
}

我认为很好...

请帮助,因为我似乎没有发现任何问题谢谢。我希望提供的代码足够。

apex-code
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一切,他们采用了他们所执行的所有方法以及一个更强大的后端。

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

祝你好运!


0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.