function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matt FolgerMatt Folger 

Formula field to grab Owner built-in field

Hi, I'm trying to grab the Owner information for a custom field "Created By" so I can manipulate it to my heart's content.  However, I'm unable to convert the Owner information in a text forumla field, it simply says that the field doesn't exist.  Is it possible to access the Owner default field in any way so I don't have to have users input that data manually?
Best Answer chosen by Matt Folger
Geoffrey J FlynnGeoffrey J Flynn
OK, I'll take another shot at this.

Here is my formula on the Account object:
'Owner is: '& Owner.FirstName & ' and Created by is: '& CreatedBy.FirstName
This will bring back on the Account page:
User-added image
So the formula works, I can get the first name of both the owner and who created the record, in the UI.

Here is my Apex Query
Now if I had to use SOQL to pull it back, things would be slightly different.  I filtered on the exact same ID I'm looking at in the UI.
SELECT CreatedBy.FirstName, Owner.FirstName, Id FROM Account WHERE Id = '001G0000019C9qs'
which returns:
User-added image

This just has to work.  
Hang on, your screenshot there.....that formula editor is to declare a default value of a text field.  Please tell me that hasn't all just been about trying to set a default value

All Answers

Chris ShadeChris Shade
Matt,

I'm not sure I understand.  Is it a custom field or a record on a custom object?  Records do have owners but I don't what you would mean by an owner of a field.

Similarly, are you trying to get information about the Created By user or the owner (those are necessarily the same thing).

Chris
 
Matt FolgerMatt Folger
So on every custom object (this one being Vencorr__c) there are 4 fields by default:

* Created By
* ID
* Last Modified By
* Owner

I'm trying to pull the Owner default field into a Visualforce page, but when it wasn't behaving as expected I looked it up and it appears you can't reference it like a custom field so that brings me to my question.  I'm trying to just grab the Owner with something like "Formula Field = TEXT(Owner)" or whatever, no syntax seems to work, so I can manipulate that for the user's benefit.

I'm noticing now however that the Created By field is a default field, so I'll have to rename my custom field to something else if it is indeed the fact that I can't manipulate any of the default fields in this way.


 
Geoffrey J FlynnGeoffrey J Flynn
My guess is that this is because the owner could also be a Queue, which is probably messing with your query
Matt FolgerMatt Folger
Ok, so I changed it from Owner to CreatedBy, no difference, it's still unable to reference these default fields of this custom object as part of a query string.  Bummer... Is there anyway around this?  Is there any way I can pull that information into a custom field so I can do what I want with it?

Error:No such column 'CreatedBy' on entity 'Vencorr__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
Geoffrey J FlynnGeoffrey J Flynn
Hi Matt,
What about CreatedByID?  Try using workbench to see what comes back.  I just pulled a custom object quickly, and you saying that just triggered my memory.  
User-added image
I think it's because they are different objects so all it really stores is the ID.  Someone much smarter than me can correct this if needed.  OwnerId is there as well

You should then be able to use dot notation to get createdby or owner fields such as name (try OwnerId.LastName if OwnerID works)

Note: if you haven't used Workbench yet, get it!  It's amazing
https://workbench.developerforce.com/
MissedCallMissedCall
Please try the following:

For created by (you can play around with the combinations)
CreatedBy.LastName 
(or)
CreatedBy.FirstName
For owner
 
Owner.FirstName
(or)
Owner.LastName


 
Matt FolgerMatt Folger
Thanks everyone so much for your responses.

So I've tried this in a variety of ways: 
* Tried to setup createdby.lastname and owner.lastname and owner.id and createdby.id, etc. all as either the formula's for a new TEXT forumla field called InquiredBy.  I've also tried setting up this InquiredBy field as a regular TEXT field with a default value of that "formula" (createby.lastname, etc) and they all error out with the attached screenshot error message.  What's the deal?  How can it not know about a default field that every custom object woudl have?  Is the syntax wrong or can you seriously not pull any useful data out of these default fields?

User-added image
MissedCallMissedCall
What is your screenshot? How did you get there?

Example, if i am on account object, create a new text formula field - in the formula editor under --select field type-- account would be selected by default. But in your case i dont see any object, can you explain to me in simple terms what you are looking for?
Geoffrey J FlynnGeoffrey J Flynn
OK, I'll take another shot at this.

Here is my formula on the Account object:
'Owner is: '& Owner.FirstName & ' and Created by is: '& CreatedBy.FirstName
This will bring back on the Account page:
User-added image
So the formula works, I can get the first name of both the owner and who created the record, in the UI.

Here is my Apex Query
Now if I had to use SOQL to pull it back, things would be slightly different.  I filtered on the exact same ID I'm looking at in the UI.
SELECT CreatedBy.FirstName, Owner.FirstName, Id FROM Account WHERE Id = '001G0000019C9qs'
which returns:
User-added image

This just has to work.  
Hang on, your screenshot there.....that formula editor is to declare a default value of a text field.  Please tell me that hasn't all just been about trying to set a default value
This was selected as the best answer
Matt FolgerMatt Folger
I'm in the Vencorr__c custom object, it's the central object for an App I've developed.  I go to create a new field "InquiredBy" (since I can't use Owner or CreatedBy for a SQL query) but if I create the field either as a formula field, or a text field with a default value defined by a formula, then it gives me that error that I posted above.  It would seem that it should know that I'm referencing the same CreatedBy field of the object to which I'm createing the fields in, but it doesn't seem to, or else it can't be referenced in this manner.

Does that answer your question?

 
Matt FolgerMatt Folger
@Geoffrey 

Thanks for that SQL line, I'm going to test that out!

The whole reason to begin with I'm trying to create this InquiredBy field is so I can reference it in a user-built SQL query, and it wasn't working.  In thinking that I couldn't reference Owner or CreatedBy in that way I was trying to map those to a custom field so I could manipulate it however I wanted.  I'll try to use that nomenclacture regarding the SQL query and see if it works!
MissedCallMissedCall
Why are you not able to refer to owner or created fields in your SOQL? See above how Geoffrey has referred to owner/created fields in soql.

You have to create a formula field with text return type, then you can easily refer to the created/owner fields in it. But text field with a default value is not the way to go for your case.
Geoffrey J FlynnGeoffrey J Flynn
We can definitely get you there with formula fields if needed, it's just finding the right sequence.  You have to trust the UI to bring back what you want, not try to input the script yourself.  Don't use Default Value, that won't work.  And custom object vs standard object won't make a difference besides the object name if you use it, otherwise the logic is exactly the same for all objects
Matt FolgerMatt Folger
You guys rock.

Worked like a charm, I entered the ".Lastname" aspect to the CreatedBy and it worked great.

Thanks!  Only problem.... who do I give credit to?

=]
Geoffrey J FlynnGeoffrey J Flynn
Glad it worked Matt!
I'll happily take the credit :) but as long as it goes to someone and the question gets marked as solved so that it can help others I'm happy