0

When I try to manually query using:

SELECT Account.Name, Name FROM Contact

I am getting the Account Name

When I put it inside an apex class

    String likeParam = '%' + searchParam+'%';
    String Query = 'SELECT Account.Name, Name FROM Contact Where Name Like : likeParam LIMIT 10';
    List<sObject> sObjectList = Database.query(Query);
    return sObjectList;

I am getting the record id instead of the name.

Any ideas? I think it's connected with Database.Query

Apex is controlling the Lightning Component that I created.

Result from query: enter image description here

Result from lightning component: enter image description here

Thank you!

6
  • Is this part of a test class? One explanation for this result would be that you have inserted a test account without a name, Salesforce will then automatically fill the field with the account id, and that may be how you now get this result.
    – Kasper
    Dec 9 '19 at 2:32
  • Please show us the actual code that is being used to display the data.
    – David Reed
    Dec 9 '19 at 2:38
  • Thank you both for the response I updated my post to add more context. Dec 9 '19 at 2:39
  • 2
    003 is the key prefix for Contact, not Account. There is something completely different wrong in your Lightning component code.
    – David Reed
    Dec 9 '19 at 2:40
  • Thanks for the info, I'll look at my component. Now I know that the query is not the source of the problem Dec 9 '19 at 2:43
1

003 is the key prefix for a Contact Id, not an Account Id. This indicates that the issue lies, as you mentioned in comments, that the problem lies in Lightning component code or markup, rather than in the SOQL/Apex layer.

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.