0

I have created a public site to create Lead records. It seems as though the site's profile has access to the composite Name field but not the FirstName or LastName fields. Eg:

//This doesn't Work
Lead l = [SELECT Name FROM Lead LIMIT 1];
this.firstName = l.FirstName;

//This works
Lead l = [SELECT Name FROM Lead LIMIT 1];
this.name = l.Name;

The profile for this site has read and edit access for leads, it also has access to the Name field. I do not see any options for granting access to FirstName, but as it's a composite field that is to be expected. Any advice as to a good workaround or a fix for this?

1 Answer 1

1

Name is a special type of "formula field." If you want FirstName and LastName, you must explicitly query for them:

Lead l = [SELECT FirstName, LastName FROM Lead LIMIT 1];
System.debug(l.FirstName+' '+l.LastName);

This is true for all compound fields of this nature. If you don't query the individual parts, you don't get the individual parts.

2
  • Thank you! I can't believe I didn't try that. Rookie mistake.
    – Jordan Lee
    Nov 14, 2018 at 23:56
  • 1
    @JordanLee Yeah, it's not immediately obvious unless you've worked with databases before. That's why we're here, to help people get up to speed. Feel free to browse our questions and tags, too, we have all kinds of great information here.
    – sfdcfox
    Nov 15, 2018 at 0:03

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.