Find your content:

Search form

You are here

Where is the documentation for the CreatedBy object?

 
Share

Browsing salesforce topics on message boards I came across this code:

CaseComment comment = [SELECT CreatedById, CreatedBy.UserName FROM CaseComment];

It looks like CreatedBy is a field of CaseComment. However, CreatedBy doesn't appear as a field in the documentation for CaseComment nor is it listed in the documentation as a standard object.

Where is the documentation that covers the CreatedBy object?


Attribution to: Cory Klein

Possible Suggestion/Solution #1

The System Fields documentation covers this (sort of):

http://www.salesforce.com/us/developer/docs/api/Content/system_fields.htm

CreatedBy is the relationship to the User identified by the CreatedById on the record.


Attribution to: Bob Buzzard

Possible Suggestion/Solution #2

There is no CreatedBy object --- the CreatedById reference field, along with LastModifiedById and OwnerId, is (except in rare cases) a reference to the User object. Thus, querying for CreatedBy.UserName on the CaseComment object is requesting the UserName field of the User record who created the CaseComment record.

If you were thrown off by the lack of a __r ending on the CreatedBy field to indicate that it is a reference to another object, you're not alone --- this is a common source of confusion for Force.com developers. Here's a quick reference to help you when dealing with Reference fields:

  • Standard Object reference fields
    • Always end in Id, e.g. CreatedById, ParentId
    • Can point to / reference multiple objects (polymorphism)
    • Fields on related objects can be accessed by removing the Id from the field name, e.g. CreatedBy.Email, Parent.Name
  • Custom Object reference fields
    • Always end in __c, e.g. Survey_Question__c
    • Will always point to a single object, e.g. to Survey_Question__c
    • Fields on related objects can be accessed by replacing the __c with __r on the field name, e.g. Survey_Question__r.Prompt__c

Hope that helps!


Attribution to: zachelrath
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4413

My Block Status

My Block Content