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
Avinash VellalaAvinash Vellala 

How to retrieve Create Date and Modified date of all fields of a custom object using Apex or Api

Hi guys,

I am new to Apex and APIs. I am trying to retrieve Create Date and Modified date of all fields of a custom object. I have already tried the below

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_describe.htm

When I paste the below API request in the browser
https://xxxx.salesforce.com/services/data/v20.0/sobjects/Account/describe/ -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxx"
I get an error saying "This XML file does not appear to have any style information associated with it. The document tree is shown below.
<errorCode>INVALID_SESSION_ID</errorCode>
<message>Session expired or invalid</message>
"
Does this work for custom objects? Can someone point full material for this (how to include additional parameters in the API request etc)

 

Arun_KharbArun_Kharb
Hi Avinash,
1 Ans-
You have to do a API call. It cannot be done by pasting the URL on browser. 
First you have to get the access token then you have to do a callout.
Something like this:
Http h1 = new Http();
HttpRequest req1 = new HttpRequest();
 req1.setHeader('Authorization','Bearer '+YOUR_ACCESS_TOKEN);
 req1.setHeader('Content-Type','application/json');
 req1.setMethod('GET');
 req1.setEndpoint('https://xxxx.salesforce.com/services/data/v37.0/sObjects/Account/describe');
HttpResponse res1 = h1.send(req1);

2 Ans- 
Yes it will work for standard as well as custom objects.

One more URL for you - 
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/sobject_describe_with_ifmodified_header.htm

Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help.
Avinash VellalaAvinash Vellala
Hi Arun,

Thanks for that but where do I run the above code? In the developer console?