2

EDIT: I am not receiving any error messages, it's just that the records I'm expecting to appear in the list are not showing up.

I need my controller to filter records to show only those where the logged in user Name matches the customer lookup field called Assigned To. Assigned to is a lookup to a Contact Record so it is not a User record.

Below is a snip of my controller. I have included Assignedto__r.Name in my list of fields and and also queried the logged in user name. Below this you will see in my class that I made sure that Assignedto__r.Name is a String so they should be comparable, but I'm not getting the desired results.

Any help as to where I'm going wrong would be appreciated.

public inherited sharing class pmListController {
@testVisible
private static List<String> projectFields = new List<String>{
    'Name',
    'Opportunity_Formula__c',
    'Opportunity__c',
    'Account_PK__c',
    'Status__c',
    'Action_Type__c',
    'Order_Submitted__c',
    'Tentative_Due_Date__c',
    'Confirmed_Due_Date__c',
    'Confirmed_Telexperts_Install_Date_Formul__c',
    'Carrier_Ref__c',
    'Assignedto__r.Name'
};


@AuraEnabled
public static string getAllData(){
    try {
        Id loggedInUserId = UserInfo.getUserId();
        String loggedInUserName = UserInfo.getUserName();
        String query = '';
        List<pmListColumns> rows = new List<pmListColumns>();
        
        query = 'SELECT ' + String.join(projectFields, ',') + ' FROM OrderProject__c  WHERE Assignedto__r.Name = :loggedInUserName AND Status__c NOT IN ( \'Cancelled\', \'Completed\')';
        List<OrderProject__c> pms = Database.query(query);
        for(OrderProject__c pm : pms) {
            rows.add(new pmListColumns(pm));

MY CLASS

public inherited sharing class pmListColumns {
//Common Fields
public Id id {get; set;}
public String name {get; set;}
public String type {get; set;}
public String opportunity {get; set;}
public String PK {get; set;}
public String status {get; set;}

//Project Fields
public String action {get; set;}
public Date carrierOrderSubmitted {get; set;}
public Date requestedCarrierDate {get; set;}
public Date confirmedCarrierDate {get; set;}
public Date confirmedTelexpertsInstallDate {get; set;}
public String carrierRef {get; set;}
public String assignedTo {get; set;}
//public String lastMilestone {get; set;}



public pmListColumns(OrderProject__c pm){
    this.type = 'Project';
    this.name = pm.Name;
    this.id = pm.Id;
    this.opportunity = pm.Opportunity_Formula__c;
    this.PK = pm.Account_PK__c;
    this.status = pm.Status__c;
    this.action = pm.Action_Type__c;
    this.carrierOrderSubmitted = pm.Order_Submitted__c;
    this.requestedCarrierDate = pm.Tentative_Due_Date__c;
    this.confirmedCarrierDate = pm.Confirmed_Due_Date__c;
    this.confirmedTelexpertsInstallDate = pm.Confirmed_Telexperts_Install_Date_Formul__c;
    this.carrierRef = pm.Carrier_Ref__c;
    this.assignedTo = pm.Assignedto__r.Name;
}
2
  • Welcome to Salesforce Stack Exchange. You state that you are "not getting the desired results." It would helpful to those who want to help you if you could please edit your question to include what results you are getting - if it is an error, please include the exact error; if it is not an error but something does happen, include what happens; if nothing discernible happens, include that information. | Have you tried adding any debug statements?
    – Moonpie
    Jun 3 '21 at 15:46
  • @Moonpie thanks for the tip! I've added an edit stating I wasn't receiving any error messages, just that the desired record wasn't showing up. I was calling the wrong field from the User account, like a fool!
    – Heather
    Jun 3 '21 at 17:42
2

UserInfo.getUserName() doesn't get the User's Name. It gets the User's UserName. What you need is UserInfo.getName().

1
  • Thank you! Sad thing is I stared at the Salesforce get user info options a couple of times to validate I had entered it correctly, but never considered I was looking at the wrong thing. This fixed my problem.
    – Heather
    Jun 3 '21 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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