• Preethi Natarajan
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 9
    Replies
Hi, I am new to SFDC and i am trying to write a test class .
I am getting system.NullpointerException:Attempt to de-reference a null object. But the Apex class executes successfully.
PFB the details
VF Page:
<apex:page sidebar="false" standardController="CandidateDetails__c" extensions="Thankspageclass" cache="false" expires="0">
<script>
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
    history.pushState(null, null, document.URL);
});
</script>
<apex:pageblock >      
<div align="center" style="background-color:orange;height:500px;padding-top:200px;font-size:large">
<b>
Dear {!lst[0].Name__c}, Thanks for your participation.
</b>
<br></br>
<br></br>
<b>You will be assessed and contacted shortly.</b>
</div>
</apex:pageblock>
</apex:page>
Apex Class:
public class Thankspageclass {
  public String candidateEmail=ApexPages.currentPage().getCookies().get('candidateMail').getValue();
  public List<CandidateDetails__c> lst{get;set;}
  public Thankspageclass(ApexPages.StandardController controller) {
    lst=[SELECT Name__c FROM CandidateDetails__c where Email__c=: candidateEmail];
    }
}
Test Class:
@isTest
public class ThankspageclassTest {
public static testmethod void test1(){
CandidateDetails__c cand = new CandidateDetails__c();
cand.Areas_of_Assessments__c ='sales';
cand.Email__c= 'Banu@gmail.com';
cand.Name__c='Banu';
cand.Number_Of_Questions__c= 5;
cand.Participant_Id__c='INF0009';
cand.Phone__c='9876543210';
insert cand;
PageReference myVfPage = Page.ThanksPage;
 Test.setCurrentPageReference(myVfPage);
 Thankspageclass TP = new Thankspageclass(new ApexPages.StandardController (cand));
 TP.candidateEmail = cand.Email__c;
 }
}
Please let me know where i am going wrong.
Hi, I am new to SFDC and i am trying to write a test class .
I am getting system.NullpointerException:Attempt to de-reference a null object. But the Apex class executes successfully.
PFB the details
VF Page:
<apex:page sidebar="false" standardController="CandidateDetails__c" extensions="Thankspageclass" cache="false" expires="0">
<script>
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
    history.pushState(null, null, document.URL);
});
</script>
<apex:pageblock >      
<div align="center" style="background-color:orange;height:500px;padding-top:200px;font-size:large">
<b>
Dear {!lst[0].Name__c}, Thanks for your participation.
</b>
<br></br>
<br></br>
<b>You will be assessed and contacted shortly.</b>
</div>
</apex:pageblock>
</apex:page>
Apex Class:
public class Thankspageclass {
  public String candidateEmail=ApexPages.currentPage().getCookies().get('candidateMail').getValue();
  public List<CandidateDetails__c> lst{get;set;}
  public Thankspageclass(ApexPages.StandardController controller) {
    lst=[SELECT Name__c FROM CandidateDetails__c where Email__c=: candidateEmail];
    }
}
Test Class:
@isTest
public class ThankspageclassTest {
public static testmethod void test1(){
CandidateDetails__c cand = new CandidateDetails__c();
cand.Areas_of_Assessments__c ='sales';
cand.Email__c= 'Banu@gmail.com';
cand.Name__c='Banu';
cand.Number_Of_Questions__c= 5;
cand.Participant_Id__c='INF0009';
cand.Phone__c='9876543210';
insert cand;
PageReference myVfPage = Page.ThanksPage;
 Test.setCurrentPageReference(myVfPage);
 Thankspageclass TP = new Thankspageclass(new ApexPages.StandardController (cand));
 TP.candidateEmail = cand.Email__c;
 }
}
Please let me know where i am going wrong.