You need to sign in to do that
Don't have an account?
Ola Bamidele
How to write Test Class for Apex Code that displays fields
Hi Everyone,
I have writen a short apex code to be able display a couple of fields from Salesforce however, I now have to write a test class,
So it would be great if someone could please assist me :)
This is my short apex code that I have:
I have writen a short apex code to be able display a couple of fields from Salesforce however, I now have to write a test class,
So it would be great if someone could please assist me :)
This is my short apex code that I have:
public with sharing class AccountController { @AuraEnabled public static List<Account> findAll() { return [SELECT id, name, Location__Latitude__s, Location__Longitude__s, Industry FROM Account WHERE Location__Latitude__s != NULL AND Location__Longitude__s != NULL LIMIT 50]; } }
Let us know if this will help you
All Answers
1) https://trailhead.salesforce.com/modules/apex_testing
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
You write a test class for this the same way that you would any other:
- Set up some data for the Apex to access
- Verify the behaviour with asserts.
Try below sample test class.
Let us know if this will help you
Thanks for your response. However i tried teh code and I keep getting a "Duplicate variable: lstAcc" error.
Do you know what its means? What does ISAcc mean?
Thanks very much!
Let us know if this will help you
I tried the code and its give 100% coverage so thanks! However, I have a question.
I noticed that the Test Class only covers these two lines:
And these lines arent covered:
Is there a reason for this? Are these lines not suppose to be covered? Thanks very much!
Code coverage is 100% means all lines are covered.
Full Select Query will consider as one line only. I hope none of the line is coming in red colour.
No, none of the lines are appearing in red, so its all covered then.
Thanks very much!