You need to sign in to do that
Don't have an account?
BigThor
Attempt to de-reference a null object
Hello,
I have the next error in VF
Attempt to de-reference a null object
Error is in expression '{!iniQuestionsResponsesLB}' in component <apex:page> in page deal_questions_and_responses_lb
An unexpected error has occurred. Your development organization has been notified.
My class is:
/** * Victor */ @isTest public without sharing class QuestionsResponsesLB { List<Deal_Screening_Question_Response__c> questions; List<Deal_Screening_Questions__c> origiQuestions; List<Deal_Screening_Question_Response__c> conRespuestas; public String sId {get; set;} public Boolean inEdit {get; set;} /* * */ public List<Deal_Screening_Question_Response__c> getQuestions(){ PageReference p = ApexPages.currentPage(); sId = p.getParameters().get('id'); Opportunity myOppo = [SELECT Deal_Category__c FROM Opportunity WHERE Id = :sId]; questions = [SELECT Category__c,Concept__c,Country__c,language__c,Name,Publish__c,Question_Number__c,Question__c,Sub_Category_2__c,Sub_Category__c FROM Deal_Screening_Question_Response__c WHERE Category__c = :myOppo.Deal_Category__c ORDER BY Question_Number__c]; return questions; } /* * */ public void iniQuestionsResponsesLB(){ PageReference p = ApexPages.currentPage(); sId = p.getParameters().get('id'); conRespuestas = [SELECT Category__c,Concept__c,Country__c,language__c,Name,Publish__c,Question_Number__c,Question__c,Sub_Category_2__c,Sub_Category__c FROM Deal_Screening_Question_Response__c WHERE Opportunity__c = :sId]; if(questions.size() > 0){ //Tenemos respuestas por lo que las mostramos inEdit = true; } else{//Caso en el que no tenemos respuestas String cat; String idioma; Opportunity myOppo = [SELECT Deal_Category__c FROM Opportunity WHERE Id = :sId]; origiQuestions = [SELECT Category__c,Concept__c,Country__c,language__c,LB__c,Name,Publish__c,Question_Number__c,Question_Type__c,Question__c,Sub_Category_2__c,Sub_Category__c FROM Deal_Screening_Questions__c WHERE Category__c = :myOppo.Deal_Category__c ORDER BY Question_Number__c]; if(origiQuestions.size() > 0){//Si para esta categoria tenemos preguntas entonces las gruardamos en la tabla preguntas/respuestas //Creamos una lista de preguntas/respuestas List<Deal_Screening_Question_Response__c> forInsert = new List<Deal_Screening_Question_Response__c>(); //Por cada una de las preguntas crearemos su pregunta respuesta for(Deal_Screening_Questions__c q : origiQuestions){ forInsert.add(new Deal_Screening_Question_Response__c(Question_Number__c = q.Question_Number__c,Category__c = q.Category__c,Sub_Category__c = q.Sub_Category__c,Question__c = q.Question__c,Opportunity__c = sId,language__c = q.language__c,Publish__c = q.Publish__c)); if(forInsert.size() > 0){ insert forInsert; } } } else{ inEdit = false; } } } /* * */ public PageReference CloseUp(){ PageReference pr = New PageReference('/'+ sId); pr.setRedirect(true); return pr; } }
My page is
<apex:page controller="QuestionsResponsesLB" tabstyle="Opportunity" action="{!iniQuestionsResponsesLB}" showHeader="true" sidebar="true"> <apex:pageBlock title="Questions"> <apex:form > <apex:pageBlockSection columns="1" rendered="true"> <apex:pageblocktable value="{!Questions}" var="question" id="list"> <apex:column headerValue="Preguntillas"> <apex:outputText value="{!question.Question__c}"/> </apex:column> <apex:column headerValue="Respuestas"> <apex:inputText size="100"/> </apex:column> </apex:pageblocktable> </apex:pageBlockSection> <apex:pageBlockSection > <apex:commandButton value="Cancel" action="{!closeUp}"/> </apex:pageBlockSection> </apex:form> </apex:pageBlock> </apex:page>
When I remove action={!iniQuestionsResponsesLB} the page work well
Whats is happening ? Any idea of the error ?
Thanks for all
One of your Querys in the iniQuestionsResponsesLB method is not returning data and when you reference the results nothing is there and it is throwing an error. You can look in the debug log and see which query it is.
All Answers
One of your Querys in the iniQuestionsResponsesLB method is not returning data and when you reference the results nothing is there and it is throwing an error. You can look in the debug log and see which query it is.
Hi Jake,
thanks for you answerd, I modify the line if(questions.size > 0) by if(questions != null) and functions works
When I have another problem, in the same code, in the line insert forInsert I have this message error
Insert failed. First exception on row 0 with id a0IJ0000001Msg6MAC; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
An unexpected error has occurred. Your development organization has been notified.
In the debug log:
but in the insert I don't specify the Id for each Deal_Screening_Question_Response__c, I look some examples and all don't specify field Id
Sorry for all questions, this is my second class and my first VF page and I'm learning
Thanks for all !!
Hi all,
I found the error, I have the sentence insert in sentence for, the code correct is
Thanks all !!! :)