+ Start a Discussion
Raj_SRaj_S 

Retrieve CreatedBy Field using Query.

Hi, I am trying to retrieve Created By field using Query shown below

"select CreatedBy from Account where id = 'XXXXXXXXXX'"

But it's giving me the following error

INVALID_FIELD:
select CreatedBy from Account where id
       ^
ERROR at Row:1:Column:8
No such column 'CreatedBy' on entity 'Account'. 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.


Can you please help me in this.


           Thanks!


Raj S
SuperfellSuperfell
There is no CreatedBy field, its CreatedById, use one of the many schema explorer tools to validate field names/check queries etc.
Raj_SRaj_S
Thanks for the reply but there is Created By Field in my Accounts section and  which is not a custom field.


Which give you the information about Account Owner, Date and time of Account Creation. As shown below

Created By Raj S, 10/10/2008 1:55 PM

Actually i want to retrieve this field.


     

Raj S
Raj_SRaj_S
Hi Simon,
           I am sure that you got that Created By Field, which is a Unique(show time at which account created) Auto generated field. Actually I am retrieving that field value by using html parsing and using that field value to retrieve Account id (Unique) by using Query. When i am using it in Query like

        "select id from Account where CreatedBy = 'XYZ'";

It's giving me error. Actually it is not recognizing CreatedBy field.

So can you please help me in using this field in Query string, I mean CreatedBy not CreatedById.

               Thanks and you have a great day!



Raj S
SuperfellSuperfell
There is no createdby field, there's a createdBy relationship (based on the createdById field i mentioned before).
select id from account where createdBy.Name = 'XYZ';

of course if you have 2 users with the same name, this might not give the results you want, so you probably really do want to use createdById.

Again, I'd highly recommend you use one of the schema/query tools to examine the schema as presented by the API.
Raj_SRaj_S
Thanks for your reply!

Actually in my application i am allowing user to login to salesforce Account and click on his customer name which will open his customer Information. After that i will retrieve Account Name, Account Number and CreatedBy(I want time at which that acount is created) of customer by using HTML parsing and then I will fire the query like

 select id from Account where Name = "XYZ" AccountNumber = "---" createdBy.CreatedDate = 10/10/2008 9:26 AM;

So that i can retrieve id(which is unique) example : 0018000000MHtu4AAH

Now i can use this Unique id to update customer Account field any many more...

** I can't get CreatedByid by using HTML parsing since it is not visible in Account. 

 I am getting error : At Query

error : MALFORMED_QUERY:
where createdBy.CreatedDate = 10/10/2008 9:26 AM
                                ^
ERROR at Row:1:Column:56
unexpected token: /

        
                                      I hope you understand my situation.



Raj S
SuperfellSuperfell
Please, please, please, go install a schema viewer tool. You can work this out youself in < 1 min. the field is called CreatedDate
Raj_SRaj_S
Thanks for the Reply Simon.

Yes i gone through the schema, which you can see from my previous message that i was using the same

createdby.CreatedDate but then also i was getting an error which i specified in my previous message.


             Thanks again for your time and patience.





Raj S

SuperfellSuperfell
Why don't you just use the Id in the list to start with, instead of trying to map back to id from 3 iffy values.

Your dateTime literal value is not correctly formatted, it needs to be in the xsd format, please see the API docs.


finally, you want createdDate, not createdBy.CreatedDate, createdDate is the date the account record was created, createdBy.CreatedDate is the date the user record of the user that created the account was created.

Message Edited by SimonF on 10-15-2008 10:55 AM
Raj_SRaj_S
Thanks so much! :)
narsavagepnarsavagep

In "Developer Console" query, with "Tooling API" checked:

SELECT Id, DeveloperName, Length, CreatedBy.Name, CreatedDate, TableEnumOrId, InlineHelpText, Description 
FROM CustomField 
WHERE TableEnumOrId = 'Opportunity'