You need to sign in to do that
Don't have an account?
Bryan Jimenez
Simple SOQL Query and Test Help
Hi,
I have created a simple Soql Query to Query a list of Properties
That Query Works just fine when I use it. However, When trying to test it for deployment, I cant seem to get my test to work.
This is my test class.
When I run this test, Code Coverage stays at none. Why would this be happening?
Any help is appreciated.
Thank you
I have created a simple Soql Query to Query a list of Properties
public class PropertiesUptown { Public List<McLabs2__Property__c> getPropertiesUptown() { List<McLabs2__Property__c> PropertiesUptown=[Select Name,Primary_Contact_Name__c,McLabs2__Loan_Balance__c,Loan_Origination_Date_v2__c,McLabs2__Loan_Maturity_Date__c From McLabs2__Property__c Where CustomField = Test And CustomField = Test2]; return PropertiesUptown; } }
That Query Works just fine when I use it. However, When trying to test it for deployment, I cant seem to get my test to work.
This is my test class.
@isTest public class PropertiesUptownTest { public static testMethod void TestSOQL() { McLabs2__Property__c prop = new McLabs2__Property__c(); // Add all required field prop.Activity_Notes__c='test'; insert prop; PropertiesUptown testCont = new PropertiesUptown (); List<McLabs2__Property__c> lstProperty = testCont.getPropertiesUptown(); System.assert( lstProperty != null); } }
When I run this test, Code Coverage stays at none. Why would this be happening?
Any help is appreciated.
Thank you
Please try below code Let us know if this will help you
Thanks
Amit Chaudhary
All Answers
Did you insert Customfield values queried as Test,Test2 in test class ?
i did did not use the values as test and test2, I was just giving an example of what I had done. I actually wrote a value in for the test. Should I have used test and test2 as my values?
If it doesn't work, then better u paste ur exact code here instead of giving examples, so we can find what's exact problem.
This is my Query.
and this is my test class.
Thank you for all your help
Your code look good to me. What error you are getting ?
Please execute test class from Salesforce UI.
The Error that I am getting is
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [McLabs2__Property_Address__c]: [McLabs2__Property_Address__c]
Please try below code Let us know if this will help you
Thanks
Amit Chaudhary