0

This is my Controller: Controller Page

And this is my test class: Test Img

and this is the error I'm receiving: Error Msg

  • Please edit your question to provide code and error message inline as text. You can use the {} tool in the editor to format your code. Screenshots are more difficult for mobile users and not accessible to our community members who use screen readers and assistive technology. – David Reed Jan 22 at 14:54
1

Your privClaimID variable will be null because the expression assigned to it returns null so the ClaimData = ... query returns no rows, hence the error.

This Building a Controller Extension documentation may help you with the design of your controller. And in tests, objects such as your testClaim have to be inserted into the database to have an Id value defined.

Note when writing a controller extension, the better way to get the Id value is:

privClaimID = controller.getId();

See StandardController Methods.

  • Thanks @Keith. Since the ClaimData = returns no value, is there a way around this to make my Test pass? And is this the correct DB insert : Claim__c testClaim= [SELECT Date_Of_Loss__c FROM Claim__c]; – ApexNewBie12 Jan 22 at 9:11
  • 1
    That is not an insert. That creates an in-memory object. You need to add insert testClaim; on the following line. Do read the link I provided too. – Keith C Jan 22 at 10:46
1

Your SOQL query does not return any rows while you are trying to assign it to actual sObject. You should set testClaim.Id in yout test class to Page parameters, so in your controller you can get privClaimID from page params.

I also strongly recommend you to post your questions with actual code and not screenshots, it makes answering your question a lot harder.

UPDATE:

PageReference myVfPage = Page.YourVFPAge;
Test.setCurrentPage(myVfPage);
ApexPages.currentPage().getParameters().put('id', testClaim.Id);
  • Thanks @Mariia. do you perhaps have an example of how I: "set testClaim.Id in your test class to Page parameters"? – ApexNewBie12 Jan 22 at 9:14
  • @ApexNewBie12 I have updated the answer, just set your VF page as Test current page and set parameter. – Mariia Illarionova Jan 22 at 9:21
  • thanks a lot. Seems to be working now :) – ApexNewBie12 Jan 22 at 9:57
  • 1
    @ApexNewBie12 If this answer or any other solved your question, please consider accepting it by clicking the green check mark. This marks the question solved and gives you and the answerer a bit of reputation. – David Reed Jan 22 at 14:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.