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

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 13
    Replies
Hi all,

Starting today, our lightning sync has disconnected and I can not seem to find a solution to fix it that is not switching to Einstein Activity Capture.

We currently connect using to Outlook using OAuth 2.0. Everything says it is connected until you try to test connection where it says "We can’t connect with your email server using the email address you provided". 

When checking that status on my own connection I see this.
User-added image
I have tried googling around and found a few articles, but none have been that helpful.
Ex. 
https://help.salesforce.com/s/articleView?id=sf.exchange_sync_admin_status_msg.htm&type=5

https://help.salesforce.com/s/articleView?id=000351807&type=1

and
https://techcommunity.microsoft.com/t5/exchange-team-blog/basic-authentication-and-exchange-online-february-2021-update/ba-p/2111904

If we need to switch over to Einstein Activity Capture, we can try that, but I wanted to see if there is anything we can do to get the sync back up and running until then.

Any help would be much appreciated, thank you.
Hi all,

I am quite new to packages and have been having some issues.

My goal is to move over a LWC and some Apex Classes over from a sandbox org to a production org that is not related to the sandbox. I did some googling and am under the impression that a package is the best way to do this since I do not think change sets can be pushed to an outside org. (If this is not the best approach, please let me know)

As I added some of the Apex classes to the package, I noticed that it was adding objects that are not directly referenced in the class. I am querying for accounts and a custom object. Now, the unwanted objects do have a lookup to the custom object that I do want, but logically I don't see why that would mean those need to be added. 

Is there a way to stop that from happening, or maybe there is an easier approach? Any help is much appreciated.

Thanks
Hi all,

We are in the process of changing over most of our staff to platform licenses and I noticed that the app launcher icons are all the same for the profile that we have been working on.

User-added image

In the App Manager, everything looks normal.

User-added image
For our old profile the icons look as they should, but I must be missing something for this new profile.

Any ideas on what might be causing this?

 
Hi all,

I do note quite understand how to query for an attachment.

I have uploaded a .txt file to a custom object and am trying to query for it through apex.
 
Attachment file = [SELECT Id, Body FROM Attachment WHERE ParentId = :recordId Limit 1];

However, everytime I run this code, it gives me this error.
"System.QueryException: List has no rows for assignment to SObject"

I want to be able to read this text document but google has been no help so far.

How do you read a text attachment from a query?
Hello,

I ran into a permission issue with Events.
As a system admin, I am able to query for all Events, but I need to give others users the same permission.
I built a custom scheduling component and it requires the scheduler to query all the events for the person they are trying to schedule.
I have looked in the profile settings but I can't seem to find anything that fixes the issue.
Is there some hidden setting I do not know about?
As a work around, I changed the apex class the public without sharing so it ignores permissions, but I still would like to know if there is a system/profile/user setting somewhere that would give them access.

Thanks in advance!

(Putting this under Apex Code Development since I don't seem to see a Administrative section)
Hi all,

We noticed an annoying problem with Events created from Apex.

User-added image

This event was created by a custom Apex class we use in an LWC for scheduling. Here is the code for that. 

User-added image

The subject for the example event was simply "PAD/TCHA/HSA". The Account name gets added automatically which is wanted, but not that many times.

Is there a reason this is happening? I notice now that I am missing (cacheable=true) since this is returning the Id but would that be the cause of the problem?

Any information on Events would be helpful, I feel like this object has barely any helpful documentation out there.
Hello,

I ran into a weird problem with filtering a report by a lookup field to a user that has a suffix.

I have a record that has a lookup relationship to the user object. Most of our users have a suffix, and when establishing that relationship to a user it does not show the suffix in the record. However, when reporting on that lookup field it does show the suffix. I did not think that was a big deal until we wanted to filter for specific users in that report. When I put a graph on the report and click on one user's category, it says no results! 

Is there a work around to this?
I feel like I am missing something here. My first guess is that it has something to do with the suffix since we recently moved credentials out of the last name and into the suffix field, but maybe I am wrong.
I can provide screenshots if necessary.
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.
Hi all,

Starting today, our lightning sync has disconnected and I can not seem to find a solution to fix it that is not switching to Einstein Activity Capture.

We currently connect using to Outlook using OAuth 2.0. Everything says it is connected until you try to test connection where it says "We can’t connect with your email server using the email address you provided". 

When checking that status on my own connection I see this.
User-added image
I have tried googling around and found a few articles, but none have been that helpful.
Ex. 
https://help.salesforce.com/s/articleView?id=sf.exchange_sync_admin_status_msg.htm&type=5

https://help.salesforce.com/s/articleView?id=000351807&type=1

and
https://techcommunity.microsoft.com/t5/exchange-team-blog/basic-authentication-and-exchange-online-february-2021-update/ba-p/2111904

If we need to switch over to Einstein Activity Capture, we can try that, but I wanted to see if there is anything we can do to get the sync back up and running until then.

Any help would be much appreciated, thank you.
Hi all,

We are in the process of changing over most of our staff to platform licenses and I noticed that the app launcher icons are all the same for the profile that we have been working on.

User-added image

In the App Manager, everything looks normal.

User-added image
For our old profile the icons look as they should, but I must be missing something for this new profile.

Any ideas on what might be causing this?

 
Hi all,

I do note quite understand how to query for an attachment.

I have uploaded a .txt file to a custom object and am trying to query for it through apex.
 
Attachment file = [SELECT Id, Body FROM Attachment WHERE ParentId = :recordId Limit 1];

However, everytime I run this code, it gives me this error.
"System.QueryException: List has no rows for assignment to SObject"

I want to be able to read this text document but google has been no help so far.

How do you read a text attachment from a query?
Hello,

I ran into a permission issue with Events.
As a system admin, I am able to query for all Events, but I need to give others users the same permission.
I built a custom scheduling component and it requires the scheduler to query all the events for the person they are trying to schedule.
I have looked in the profile settings but I can't seem to find anything that fixes the issue.
Is there some hidden setting I do not know about?
As a work around, I changed the apex class the public without sharing so it ignores permissions, but I still would like to know if there is a system/profile/user setting somewhere that would give them access.

Thanks in advance!

(Putting this under Apex Code Development since I don't seem to see a Administrative section)
Hi all,

We noticed an annoying problem with Events created from Apex.

User-added image

This event was created by a custom Apex class we use in an LWC for scheduling. Here is the code for that. 

User-added image

The subject for the example event was simply "PAD/TCHA/HSA". The Account name gets added automatically which is wanted, but not that many times.

Is there a reason this is happening? I notice now that I am missing (cacheable=true) since this is returning the Id but would that be the cause of the problem?

Any information on Events would be helpful, I feel like this object has barely any helpful documentation out there.
Hello,

I ran into a weird problem with filtering a report by a lookup field to a user that has a suffix.

I have a record that has a lookup relationship to the user object. Most of our users have a suffix, and when establishing that relationship to a user it does not show the suffix in the record. However, when reporting on that lookup field it does show the suffix. I did not think that was a big deal until we wanted to filter for specific users in that report. When I put a graph on the report and click on one user's category, it says no results! 

Is there a work around to this?
I feel like I am missing something here. My first guess is that it has something to do with the suffix since we recently moved credentials out of the last name and into the suffix field, but maybe I am wrong.
I can provide screenshots if necessary.
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.