• Zander Zumbrunnen
  • NEWBIE
  • 20 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 6
    Replies
Hello all,

So I have a small lwc where I want to enable a button when an input is not empty but I can not seem to get it to disable the button again if the value in the input field is deleted.

Methods I have tried:
event.target.value == undefined
event.target.value == null
event.target.value.length < 1

I imagine this is possible so I must be missing some key information about event.target.value.

Any help or infromation would be very helpful!

Thanks in advance.
Hello, 

I am trying to send an email at the push of a button using LWC and Apex.
This is my current Apex function that sends the email, this is where I'm guessing the problem is.
@AuraEnabled(cacheable=true)
    public static Boolean sendResources(String email, Id accountId) {
        List<Selected_Resource__c> resources = new List<Selected_Resource__c>([SELECT Name, Name__c, Description__c, Phone__c, Street_Address__c, City__c, State__c, Zip__c 
                                                                               FROM Selected_Resource__c 
                                                                               WHERE Account__c = :accountId AND Active__c = True
                                                                               ORDER BY CreatedDate Desc 
                                                                               LIMIT 10]);
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setToAddresses(new String[] {email});
        message.setReplyTo('example@example.com');
        message.setSenderDisplayName('Example');
        message.setSubject('Selected Resources');
        String body = '';
        for (Integer i = 0; i < resources.size(); i++) {
            body = body + '<h2>' + resources[i].Name__c + '</h2><p>' + 'Description: ' + resources[i].Description__c + '</p><p>' + 'Phone: ' + resources[i].Phone__c.substring(0, 3) + '-' + resources[i].Phone__c.substring(3, 6) + '-' + resources[i].Phone__c.substring(6, 10) + '</p><p>' + 'Address: ' + resources[i].Street_Address__c + ', ' + resources[i].City__c + ', ' + resources[i].State__c + ' ' + resources[i].Zip__c +'</p>
</br>';
        }
        message.setHtmlBody(body);
        Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
        Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
        if (results[0].isSuccess())
            return true;
        else
            return false;
    }
I am able to get an email the first time I call this but every time after that it will return true but not actually send the email.

Am I missing something here?
 
Hello,
I am currently creating an Apex class to pass filtered query results to an LWC.
I first query for accounts and then calculate that account's distance away from a certain point and put that number in another list (Couldn't figure out how to put that number into the field Distance__c and have it stay there when returned to my LWC, this might be the main problem). Then I want to sort by the shortest distance. To do this I put Distances in the DirtyMap as a key and the InitialResources as the value. Sort Distances using .sort() and fill in CleanMap with the new Distances as the key and the related accounts as the value. Here is said code.
@AuraEnabled(cacheable=true)
    public static Map<Double,Account> searchResources(String state, String type, Integer distance, Double latitude, Double longitude, String What_type_of_residence_do_you_live_in, String Are_you_having_financial_difficulties, String Can_you_pay_for_utilities, String Can_you_pay_for_housing, String Can_you_pay_for_your_medical_visits, String Can_you_pay_for_your_transportation, String Do_you_eat_at_least_two_meals_a_day, String Can_you_pay_for_food, String Can_you_pay_for_your_medication, String How_do_you_get_to_medical_appointments, String Do_you_feel_safe_at_home, String Police_called_to_home_in_last_90_days) {
        // Initialize distance variables
        Double lat1 = latitude;
        Double lon1 = longitude;
        Double lat2;
        Double lon2;
        Double x;
        Double y;
        Double xx;
        Double yy;
        Double a;
        Double c;
        Double d;

        // Get all resources and create lists and maps for data manipulation
        List<Account> InitialResources = [SELECT Id, Name, Phone, Description, Email__c, Distance__c, Latitude__c, Longitude__c, Food_Bank__c, Financial_Assistance__c, Shelter__c, Case_Management__c, Serves_Meals__c, Senior_Center__c, Housing_Assistance__c, Transportation__c
                                          FROM Account
                                          WHERE RecordTypeId = '0121R000000yZGLQA2' AND BillingState = :state];
        List<Double> Distances = new List<Double>();
        Map<Double,Account> DirtyMap = new Map<Double,Account>();
        Map<Double,Account> CleanMap = new Map<Double,Account>();
        Map<Double,Account> FilteredMap = new Map<Double,Account>();

        // Get distance in miles of each resource and add to Distance__c
        for (Account record : InitialResources){
            lat2 = record.Latitude__c;
            lon2 = record.Longitude__c;
            x = lat1 * 3.141592 / 180;
            y = lat2 * 3.141592 / 180;
            xx = (lat2 - lat1) * 3.141592 / 180;
            yy = (lon2 - lon1) * 3.141592 / 180;
            a = math.sin(xx/2) * math.sin(xx/2) + math.cos(x) * math.cos(y) * math.sin(yy/2) * math.sin(yy/2);
            c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a));
            d = 6371000 * c;
            d = d * 0.00062137;
            Distances.add(d);
        }

        // Sort InitialResources by Distance__c
        for (Integer i = 0; i < InitialResources.size(); i++){
            if (Distances[i] <= distance)
                DirtyMap.put(Distances[i], InitialResources[i]);
        }
        Distances.sort();
        for (Integer i = 0; i < InitialResources.size(); i++){
            CleanMap.put(Distances[i], DirtyMap.get(Distances[i]));
        }

        // Return resources depenging on filters
        if (type == 'Recommended Resources') {
            for (Double key : CleanMap.keySet()) {
                if (CleanMap.get(key).Food_Bank__c && Can_you_pay_for_food == 'No')
                    FilteredMap.put(key, CleanMap.get(key));
            }
            return FilteredMap;
        }
        else
            return CleanMap;
    }
}
The problem area is the underlined part in the last "If" statement.
For some reason when I try accessing that boolean field from the map value it returns this error "Attempt to de-reference a null object".

I don't think I'm doing anything wrong since I have tried a few different things using the map values. I could only get it to work when referencing the initial list which is not in the right order.
(Ex. InitialResouces[i].Food_Bank__c works as intended but CleanMap.get(key).Food_Bank__c does not.)

If that is just a quality of maps then I guess I need a workaround, but I can't seem to think of a way of sorting the account list based on the distance list without using a map.

Hopefully, my problem makes sense. 
Thanks in advance.
 
Hello,

I've been struggling with creating a test class for a custom controller with if statements for a Visualforce page. I have no idea what I'm doing wrong and have looked all over these forums and google for an answer with no luck. If someone could give this a shot and let me know what I am doing wrong that would be amazing.

Here is my controller:
public class SuspectListController {
	public final Account act;
    public SuspectListController(ApexPages.StandardController stdController) {
        this.act = (Account)stdController.getRecord();
    }

    public Id AccountId = ApexPages.currentPage().getParameters().get('id');

    public List<HealthCloudGA__EhrEncounter__c> EHRRecords = [SELECT Name, CreatedDate, HealthCloudGA__HospitalizeDischargeDiagnosis__c
                                                       FROM HealthCloudGA__EhrEncounter__c WHERE HealthCloudGA__Account__c = :AccountId AND CreatedDate = LAST_N_DAYS:365 ORDER BY CreatedDate desc];

    public List<String> RType = new List<String>();
    public List<String> Name = new List<String>();
    public List<String> CDate = new List<String>();
    public List<String> Code = new List<String>();
    public List<String> Description = new List<String>();

    public List<String> getType() {
        for (HealthCloudGA__EhrEncounter__c encounter : EHRRecords) {
             if (!Description.contains(encounter.HealthCloudGA__HospitalizeDischargeDiagnosis__c) && encounter.HealthCloudGA__HospitalizeDischargeDiagnosis__c != null) {
                RType.add('EHR Encounter');
                Name.add(encounter.Name);
                Cdate.add(encounter.CreatedDate.format('MM/dd/yyyy'));
                Code.add('');
                Description.add(encounter.HealthCloudGA__HospitalizeDischargeDiagnosis__c);
            }
        }    
        
        return RType;
    }

    public List<String> getName() {
        return Name;
    }
    
    public List<String> getCDate() {
        return CDate;
    }
    
    public List<String> getCode() {
        return Code;
    }
    
    public List<String> getDescription() {
        return Description;
    }
This controller was created to add field values to a list if they are not on the list already and pass that list to an html table on a Visualforce page (Adding to every list in the first function is a bit funky but it saves from looping through each record in each function). My test class currently passes everything except for the if statement and its contents.

Here is my current test class:
@isTest
private class SuspectListTestClass {
    @testSetup static void testSetup() {
        Account testaccount = new Account();
        testaccount.name = 'Zander Test';
        testaccount.Primary_Insurance__c = 'Test Insurance Company';
        testaccount.Gender__c = 'Male';
        testaccount.County__c = 'Maricopa';
        testaccount.RecordTypeId = '012360000004FEPAA2';
        insert testaccount;
    }

    @isTest static void testEHREncounterPass() {
        Account act = [SELECT Id FROM Account WHERE Name = 'Zander Test' LIMIT 1];
        HealthCloudGA__EhrEncounter__c testencounter1 = new HealthCloudGA__EhrEncounter__c();
        testencounter1.HealthCloudGA__Account__c = act.Id;
        testencounter1.HealthCloudGA__HospitalizeDischargeDiagnosis__c = 'Test';
        insert testencounter1;
        PageReference testpagereference = Page.SuspectList;
        test.setCurrentPage(testpagereference);
        SuspectListController testcontroller = new SuspectListController(new ApexPages.StandardController(act));
        testcontroller.Description.add('');
        String[] record = testcontroller.getType();
        System.assertEquals('EHR Encounter',record[0]);
    }
    
    @isTest static void testEHREncounterFail() {
        Account act = [SELECT Id FROM Account WHERE Name = 'Zander Test' LIMIT 1];
        HealthCloudGA__EhrEncounter__c testencounter2 = new HealthCloudGA__EhrEncounter__c();
        testencounter2.HealthCloudGA__Account__c = act.Id;
        testencounter2.HealthCloudGA__HospitalizeDischargeDiagnosis__c = 'Test';
        insert testencounter2;
        PageReference testpagereference = Page.SuspectList;
        test.setCurrentPage(testpagereference);
        SuspectListController testcontroller = new SuspectListController(new ApexPages.StandardController(act));
        testcontroller.Description.add('Test');
        testcontroller.getType();
    }

    @isTest static void testSuspectListController() {
        Account act = [SELECT Id FROM Account WHERE Name = 'Zander Test' LIMIT 1];
        PageReference testpagereference = Page.SuspectList;
        test.setCurrentPage(testpagereference);
        SuspectListController testcontroller = new SuspectListController(new ApexPages.StandardController(act));
        testcontroller.getName();
        testcontroller.getCDate();
        testcontroller.getCode();
        testcontroller.getDescription();
    }
}
From what I understand you need to have one test where it is meant to pass and one where it is meant to fail. I have made 2 test methods but no matter what I do I can not seem to get one to pass. I get an error from the assertEquals() saying that the index is out of range meaning it did not add "EHR Encounter" to the RType list.

Am I missing something here??
I feel like I have inserted a record that should pass but I guess not.
Please help!

Thanks in advance!

 
Hi,

I'm quite new to Apex and test classes and I'm having some trouble getting decent code coverage (Preferably 100%). I can get everything except a few if statements covered.

Here is my controller:
public class SuspectListController {
	public final Account act;
    public SuspectListController(ApexPages.StandardController stdController) {
        this.act = (Account)stdController.getRecord();
    }

    public Id AccountId = ApexPages.currentPage().getParameters().get('id');

    List<HealthCloudGA__EhrEncounter__c> EHRRecords = [SELECT Name, CreatedDate, HealthCloudGA__HospitalizeDischargeDiagnosis__c FROM HealthCloudGA__EhrEncounter__c WHERE HealthCloudGA__Account__c = :AccountId AND CreatedDate = LAST_N_DAYS:365 ORDER BY CreatedDate desc];

    List<String> RType = new List<String>();
    List<String> Name = new List<String>();
    List<String> CDate = new List<String>();
    List<String> Code = new List<String>();
    List<String> Description = new List<String>();

    public List<String> getType() {
        for (HealthCloudGA__EhrEncounter__c encounter : EHRRecords) {
             if (!Description.contains(encounter.HealthCloudGA__HospitalizeDischargeDiagnosis__c) && encounter.HealthCloudGA__HospitalizeDischargeDiagnosis__c != null) {
                RType.add('EHR Encounter');
                Name.add(encounter.Name);
                Cdate.add(encounter.CreatedDate.format('MM/dd/yyyy'));
                Code.add('');
                Description.add(encounter.HealthCloudGA__HospitalizeDischargeDiagnosis__c);
            }   
        }    
        
        return RType;
    }

Here is my test class:
@isTest
private class SuspectListTestClass {
    static testMethod void testSuspectListController() {
        Account testaccount = new Account();
        testaccount.name = 'Zander Test';
        testaccount.Primary_Insurance__c = 'Test Insurance Company';
        testaccount.Gender__c = 'Male';
        testaccount.County__c = 'Maricopa';
        testaccount.RecordTypeId = '012360000004FEPAA2';
        insert testaccount;

        HealthCloudGA__EhrEncounter__c testencounter1 = new HealthCloudGA__EhrEncounter__c();
        testencounter1.HealthCloudGA__Account__c = testaccount.Id;
        testencounter1.HealthCloudGA__HospitalizeDischargeDiagnosis__c = 'Test';
        insert testencounter1;
        
        HealthCloudGA__EhrEncounter__c testencounter2 = new HealthCloudGA__EhrEncounter__c();
        testencounter2.HealthCloudGA__Account__c = testaccount.Id;
        testencounter2.HealthCloudGA__HospitalizeDischargeDiagnosis__c = 'Test';
        insert testencounter2;
        
        HealthCloudGA__EhrEncounter__c testencounter3 = new HealthCloudGA__EhrEncounter__c();
        testencounter3.HealthCloudGA__Account__c = testaccount.Id;
        testencounter3.HealthCloudGA__HospitalizeDischargeDiagnosis__c = null;
        insert testencounter3;

        test.startTest();
        PageReference testpagereference = Page.SuspectList;
        test.setCurrentPage(testpagereference);
        SuspectListController testcontroller = new SuspectListController(new ApexPages.StandardController(testaccount));
        testcontroller.getType();
        test.stopTest();
    }
}

Like I said earlier the only part that is not passing is the if statement and contents. There is more to this controller and test class but if I can solve this issue I can probably fix the rest.

Also, SuspectList is the name of the Visualforce page I'm trying to reference.

Any information on properly setting up test classes would be much appreciated.

Thanks in advance.
Hi,

I am trying to query a formula field from a custom grandchild object of the Account object but I get this error "Invalid field PHQ9_Score__c for SObject Account".

Account -> Assessment and Care Plan -> PS Assessment

Here is my code.

Controller:
public class Suspect_List_Controller {
    public final Account act;
    public Suspect_List_Controller(ApexPages.StandardController stdController) {
        this.act = (Account)stdController.getRecord();
    }

   public Id AccountId = ApexPages.currentPage().getParameters().get('id');

   public String PHQ9 = '012360000019nOBAAY';
   
   List<PS_Assessments__c> PHQ9Records = [SELECT Name, CreatedDate, PHQ9_Score__c FROM PS_Assessments__c WHERE Patient_Assessment_and_Care_Plan__r.Account__c = :AccountId AND RecordTypeId = :PHQ9 AND PHQ9_Score__c >= 9 AND CreatedDate= LAST_N_DAYS:365 ORDER BY CreatedDate asc];

   public List<PS_Assessments__c> getPHQ9() {
        return PHQ9Records;
    }
}

Visualforce:
<apex:page standardController="Account" extensions="Suspect_List_Controller">
    <apex:pageBlock title="Suspect List">
        <apex:pageBlockSection title="PHQ9's over 9">
            <apex:pageBlockTable value="{!PHQ9}" var="record">
                <apex:column value="{!record.Name}"/>
                <apex:column value="{!record.CreatedDate}"/>
                <apex:column value="{!record.PHQ9_Score__c}"/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

This is only one part of the Visualforce page so using a report or something similar will probably not work.

I am assuming the error is somewhere in the where clause of the query. The PHQ9 score is a formula field on the PS Assessment. The PS assessment has no direct relation to the account but the Assessment and Care Plan does.

Any information on this type of query would be useful.
Hello, 

I am trying to send an email at the push of a button using LWC and Apex.
This is my current Apex function that sends the email, this is where I'm guessing the problem is.
@AuraEnabled(cacheable=true)
    public static Boolean sendResources(String email, Id accountId) {
        List<Selected_Resource__c> resources = new List<Selected_Resource__c>([SELECT Name, Name__c, Description__c, Phone__c, Street_Address__c, City__c, State__c, Zip__c 
                                                                               FROM Selected_Resource__c 
                                                                               WHERE Account__c = :accountId AND Active__c = True
                                                                               ORDER BY CreatedDate Desc 
                                                                               LIMIT 10]);
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setToAddresses(new String[] {email});
        message.setReplyTo('example@example.com');
        message.setSenderDisplayName('Example');
        message.setSubject('Selected Resources');
        String body = '';
        for (Integer i = 0; i < resources.size(); i++) {
            body = body + '<h2>' + resources[i].Name__c + '</h2><p>' + 'Description: ' + resources[i].Description__c + '</p><p>' + 'Phone: ' + resources[i].Phone__c.substring(0, 3) + '-' + resources[i].Phone__c.substring(3, 6) + '-' + resources[i].Phone__c.substring(6, 10) + '</p><p>' + 'Address: ' + resources[i].Street_Address__c + ', ' + resources[i].City__c + ', ' + resources[i].State__c + ' ' + resources[i].Zip__c +'</p>
</br>';
        }
        message.setHtmlBody(body);
        Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
        Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
        if (results[0].isSuccess())
            return true;
        else
            return false;
    }
I am able to get an email the first time I call this but every time after that it will return true but not actually send the email.

Am I missing something here?
 
Hello,

I've been struggling with creating a test class for a custom controller with if statements for a Visualforce page. I have no idea what I'm doing wrong and have looked all over these forums and google for an answer with no luck. If someone could give this a shot and let me know what I am doing wrong that would be amazing.

Here is my controller:
public class SuspectListController {
	public final Account act;
    public SuspectListController(ApexPages.StandardController stdController) {
        this.act = (Account)stdController.getRecord();
    }

    public Id AccountId = ApexPages.currentPage().getParameters().get('id');

    public List<HealthCloudGA__EhrEncounter__c> EHRRecords = [SELECT Name, CreatedDate, HealthCloudGA__HospitalizeDischargeDiagnosis__c
                                                       FROM HealthCloudGA__EhrEncounter__c WHERE HealthCloudGA__Account__c = :AccountId AND CreatedDate = LAST_N_DAYS:365 ORDER BY CreatedDate desc];

    public List<String> RType = new List<String>();
    public List<String> Name = new List<String>();
    public List<String> CDate = new List<String>();
    public List<String> Code = new List<String>();
    public List<String> Description = new List<String>();

    public List<String> getType() {
        for (HealthCloudGA__EhrEncounter__c encounter : EHRRecords) {
             if (!Description.contains(encounter.HealthCloudGA__HospitalizeDischargeDiagnosis__c) && encounter.HealthCloudGA__HospitalizeDischargeDiagnosis__c != null) {
                RType.add('EHR Encounter');
                Name.add(encounter.Name);
                Cdate.add(encounter.CreatedDate.format('MM/dd/yyyy'));
                Code.add('');
                Description.add(encounter.HealthCloudGA__HospitalizeDischargeDiagnosis__c);
            }
        }    
        
        return RType;
    }

    public List<String> getName() {
        return Name;
    }
    
    public List<String> getCDate() {
        return CDate;
    }
    
    public List<String> getCode() {
        return Code;
    }
    
    public List<String> getDescription() {
        return Description;
    }
This controller was created to add field values to a list if they are not on the list already and pass that list to an html table on a Visualforce page (Adding to every list in the first function is a bit funky but it saves from looping through each record in each function). My test class currently passes everything except for the if statement and its contents.

Here is my current test class:
@isTest
private class SuspectListTestClass {
    @testSetup static void testSetup() {
        Account testaccount = new Account();
        testaccount.name = 'Zander Test';
        testaccount.Primary_Insurance__c = 'Test Insurance Company';
        testaccount.Gender__c = 'Male';
        testaccount.County__c = 'Maricopa';
        testaccount.RecordTypeId = '012360000004FEPAA2';
        insert testaccount;
    }

    @isTest static void testEHREncounterPass() {
        Account act = [SELECT Id FROM Account WHERE Name = 'Zander Test' LIMIT 1];
        HealthCloudGA__EhrEncounter__c testencounter1 = new HealthCloudGA__EhrEncounter__c();
        testencounter1.HealthCloudGA__Account__c = act.Id;
        testencounter1.HealthCloudGA__HospitalizeDischargeDiagnosis__c = 'Test';
        insert testencounter1;
        PageReference testpagereference = Page.SuspectList;
        test.setCurrentPage(testpagereference);
        SuspectListController testcontroller = new SuspectListController(new ApexPages.StandardController(act));
        testcontroller.Description.add('');
        String[] record = testcontroller.getType();
        System.assertEquals('EHR Encounter',record[0]);
    }
    
    @isTest static void testEHREncounterFail() {
        Account act = [SELECT Id FROM Account WHERE Name = 'Zander Test' LIMIT 1];
        HealthCloudGA__EhrEncounter__c testencounter2 = new HealthCloudGA__EhrEncounter__c();
        testencounter2.HealthCloudGA__Account__c = act.Id;
        testencounter2.HealthCloudGA__HospitalizeDischargeDiagnosis__c = 'Test';
        insert testencounter2;
        PageReference testpagereference = Page.SuspectList;
        test.setCurrentPage(testpagereference);
        SuspectListController testcontroller = new SuspectListController(new ApexPages.StandardController(act));
        testcontroller.Description.add('Test');
        testcontroller.getType();
    }

    @isTest static void testSuspectListController() {
        Account act = [SELECT Id FROM Account WHERE Name = 'Zander Test' LIMIT 1];
        PageReference testpagereference = Page.SuspectList;
        test.setCurrentPage(testpagereference);
        SuspectListController testcontroller = new SuspectListController(new ApexPages.StandardController(act));
        testcontroller.getName();
        testcontroller.getCDate();
        testcontroller.getCode();
        testcontroller.getDescription();
    }
}
From what I understand you need to have one test where it is meant to pass and one where it is meant to fail. I have made 2 test methods but no matter what I do I can not seem to get one to pass. I get an error from the assertEquals() saying that the index is out of range meaning it did not add "EHR Encounter" to the RType list.

Am I missing something here??
I feel like I have inserted a record that should pass but I guess not.
Please help!

Thanks in advance!

 
Hi,

I'm quite new to Apex and test classes and I'm having some trouble getting decent code coverage (Preferably 100%). I can get everything except a few if statements covered.

Here is my controller:
public class SuspectListController {
	public final Account act;
    public SuspectListController(ApexPages.StandardController stdController) {
        this.act = (Account)stdController.getRecord();
    }

    public Id AccountId = ApexPages.currentPage().getParameters().get('id');

    List<HealthCloudGA__EhrEncounter__c> EHRRecords = [SELECT Name, CreatedDate, HealthCloudGA__HospitalizeDischargeDiagnosis__c FROM HealthCloudGA__EhrEncounter__c WHERE HealthCloudGA__Account__c = :AccountId AND CreatedDate = LAST_N_DAYS:365 ORDER BY CreatedDate desc];

    List<String> RType = new List<String>();
    List<String> Name = new List<String>();
    List<String> CDate = new List<String>();
    List<String> Code = new List<String>();
    List<String> Description = new List<String>();

    public List<String> getType() {
        for (HealthCloudGA__EhrEncounter__c encounter : EHRRecords) {
             if (!Description.contains(encounter.HealthCloudGA__HospitalizeDischargeDiagnosis__c) && encounter.HealthCloudGA__HospitalizeDischargeDiagnosis__c != null) {
                RType.add('EHR Encounter');
                Name.add(encounter.Name);
                Cdate.add(encounter.CreatedDate.format('MM/dd/yyyy'));
                Code.add('');
                Description.add(encounter.HealthCloudGA__HospitalizeDischargeDiagnosis__c);
            }   
        }    
        
        return RType;
    }

Here is my test class:
@isTest
private class SuspectListTestClass {
    static testMethod void testSuspectListController() {
        Account testaccount = new Account();
        testaccount.name = 'Zander Test';
        testaccount.Primary_Insurance__c = 'Test Insurance Company';
        testaccount.Gender__c = 'Male';
        testaccount.County__c = 'Maricopa';
        testaccount.RecordTypeId = '012360000004FEPAA2';
        insert testaccount;

        HealthCloudGA__EhrEncounter__c testencounter1 = new HealthCloudGA__EhrEncounter__c();
        testencounter1.HealthCloudGA__Account__c = testaccount.Id;
        testencounter1.HealthCloudGA__HospitalizeDischargeDiagnosis__c = 'Test';
        insert testencounter1;
        
        HealthCloudGA__EhrEncounter__c testencounter2 = new HealthCloudGA__EhrEncounter__c();
        testencounter2.HealthCloudGA__Account__c = testaccount.Id;
        testencounter2.HealthCloudGA__HospitalizeDischargeDiagnosis__c = 'Test';
        insert testencounter2;
        
        HealthCloudGA__EhrEncounter__c testencounter3 = new HealthCloudGA__EhrEncounter__c();
        testencounter3.HealthCloudGA__Account__c = testaccount.Id;
        testencounter3.HealthCloudGA__HospitalizeDischargeDiagnosis__c = null;
        insert testencounter3;

        test.startTest();
        PageReference testpagereference = Page.SuspectList;
        test.setCurrentPage(testpagereference);
        SuspectListController testcontroller = new SuspectListController(new ApexPages.StandardController(testaccount));
        testcontroller.getType();
        test.stopTest();
    }
}

Like I said earlier the only part that is not passing is the if statement and contents. There is more to this controller and test class but if I can solve this issue I can probably fix the rest.

Also, SuspectList is the name of the Visualforce page I'm trying to reference.

Any information on properly setting up test classes would be much appreciated.

Thanks in advance.
Hi,

I am trying to query a formula field from a custom grandchild object of the Account object but I get this error "Invalid field PHQ9_Score__c for SObject Account".

Account -> Assessment and Care Plan -> PS Assessment

Here is my code.

Controller:
public class Suspect_List_Controller {
    public final Account act;
    public Suspect_List_Controller(ApexPages.StandardController stdController) {
        this.act = (Account)stdController.getRecord();
    }

   public Id AccountId = ApexPages.currentPage().getParameters().get('id');

   public String PHQ9 = '012360000019nOBAAY';
   
   List<PS_Assessments__c> PHQ9Records = [SELECT Name, CreatedDate, PHQ9_Score__c FROM PS_Assessments__c WHERE Patient_Assessment_and_Care_Plan__r.Account__c = :AccountId AND RecordTypeId = :PHQ9 AND PHQ9_Score__c >= 9 AND CreatedDate= LAST_N_DAYS:365 ORDER BY CreatedDate asc];

   public List<PS_Assessments__c> getPHQ9() {
        return PHQ9Records;
    }
}

Visualforce:
<apex:page standardController="Account" extensions="Suspect_List_Controller">
    <apex:pageBlock title="Suspect List">
        <apex:pageBlockSection title="PHQ9's over 9">
            <apex:pageBlockTable value="{!PHQ9}" var="record">
                <apex:column value="{!record.Name}"/>
                <apex:column value="{!record.CreatedDate}"/>
                <apex:column value="{!record.PHQ9_Score__c}"/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

This is only one part of the Visualforce page so using a report or something similar will probably not work.

I am assuming the error is somewhere in the where clause of the query. The PHQ9 score is a formula field on the PS Assessment. The PS assessment has no direct relation to the account but the Assessment and Care Plan does.

Any information on this type of query would be useful.