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
QinQin 

How to I get the last modified date of a custom object or field defintion

Hi, 

 

I want to get the last modified date of a custom object definition in Apex or via WS.  Schema.DescribeSObjectResult doesn't have a method like getLastModifiedDate.  But this info is clearly available in the custom object definition detail page.  Is there anyway to get this in the Apex code?  Similarly I want to know the last modified date of a custom field definition, and I'm facing the same issue.

 

I also check the meta data API reference and cannot find anyway to get the last modified date of custom object definition.

 

Please point me to the right direction.

 

Thanks,

 

-Qin zhang

Cory CowgillCory Cowgill

In Apex you can get the LastModifiedDate by the name 'LastModifiedDate'. It returns a Date/Time object.

 

Account a = [Select a.LastModifiedById From Account a where id =:inputId];

System.debug('Last Modified Date == ' + a.LastModifiedDate);

 

Are you using the Force.com IDE plugin for development. If you are, you can view all the Schema information by double clicking the salesforce.schema file in the root of the project. It allows you to see all the metadata and API names and is very convienent for finding this type of information as well as building queries.

QinQin

Hi,

 

Thank you for the reply.  Yes. I'm using the IDE.  I think that I didn't state my question clearly;  my question is about meta data API.  I'm not interested in knowing the last modified date of a field of an object instead. Rather, I want to know when somebody added a new custom object definition or custom field definition to the organization.  

 

For example, I can get all the field name of a custom object named nimbustest1__organization__c in the following code:

 

        String objInfo = '';
       
       Schema.DescribeSObjectResult d = Schema.Sobjecttype.nimbustest1__organization__c;
       
         Map<String, Schema.SObjectField> M = d.fields.getMap();
         
         List <Schema.SObjectField> fieldList = M.values();
         
        for(Schema.SObjectField aField: fieldList){
          Schema.DescribefieldResult fieldDes = aField.getDescribe();
          objInfo = objInfo + fieldDes.getName() + ';';
        }
       
       return objInfo;

 

But Schema.DescribefieldResult doesn't have a method called getLastModifiedDate or even getCreationDate.  When I go to Setup -- Create -- Objects -- organization page, the last modified date is listed there.  So I'm wondering if there is another API to get to the same this info...

 

Regards,

 

-Qin

Cory CowgillCory Cowgill

OK. That clarifies that.

 

Check out this link: http://corycowgill.blogspot.com/2011/01/building-dynamic-soql-select-all-query.html

 

That examples hows you how to retrieve Field Metadata about objects, which includes the LastCreatedDate etc.

Cory CowgillCory Cowgill

Oh I see. You want to know when someone changed the Object Definition. I haven't done that, sorry. I'll be intested in the answer though.

Pradeep_NavatarPradeep_Navatar

You can fetch the lastmodified date through SOQL query :

 

Employee__c obj = [select id, lastmodifieddate from Employee__c where lastmodifieddate <= system.now()];

SubashKumarSubashKumar

Dear Qin,

 

Did you get an answer for this. I guess the detail can be retrieved using meta data API. Unfortunately we will not be able to use that in Apex code.

 

Please reply back if you have any answer for this. I want to retrieve the created date.

 

Thanks,

Subash

QinQin

Hi, Pradeep Navatar's answer should work.  I moved on to other projects and haven't looked at force.com for a while.  it's possible that there are API enhancements too.  -Qin

SubashKumarSubashKumar

Qin,

 

Pradeep's solution will fetch just data not meta data. The API does not support getting Last Modified Date and created date. Any way if you ever come across a solution, please post it here.

jhelblingjhelbling

Hi all,

 

Did anybody already find a solution to this one ?

 

Thanks

SatioSatio

I was so excited to find this post, but dissapointed now to see that there is no answer :(

I have the same requirement :( Schema Duplication is my task and to have the salesforce schema in sync with a local RDBMS.

 

Is there ANY workaround atleast?

VHanson1VHanson1

I have the same requirement -- I need to find all recently modified field metadata and send it to our data team so they can update our data pipelines.  Unfortunately it doesn't look like there is a way do find that information.

Liudmila LikhovidLiudmila Likhovid
Hi!  I also need that possibly using SOAP API (I mean not REST). At the moment I found only this https://www.salesforce.com/us/developer/docs/api_rest/Content/sobject_describe_with_ifmodified_header.htm
Liudmila LikhovidLiudmila Likhovid
There are also two ways to do that: listMetadata in Metadata API or query in Tooling api.
Metadata  API:
As described here http://https://www.salesforce.com/us/developer/docs/api_meta/Content/meta_listmetadata.htm
Or the same but 
     query.setType("CustomField");

Tooling API:

QueryResult queryResult = toolingConnection.query("select Id, DeveloperName, LastModifiedDate from CustomField");

or 

QueryResult queryResult = toolingConnection.query("select Id, DeveloperName, LastModifiedDate from CustomObject");

IMPORTANT
When you change  field or add a new custom field "lastModifiedDate" of an Object won't be changed ! You should query CustomField to get date of field modification.
Niranjan GattupalliNiranjan Gattupalli
View Setup Audit Trail:
    The view Setup Audit Trail will track all metadata changes incluing object,fields,layouts,class,page etc..and displays latest 20 changes.
If you want to see last 6 months metadata changes need to download the csv file.
 
User-added image

    Unlike View Setup Audit Trail which displays only latest 20 records ..there is an app AutoRABIT(https://appexchange.salesforce.com/listingDetail?listingId=a0N30000000ptkwEAA )in appexchanage which is based on Salesforce APIs whcih can track all metdata changes based on given date/time,metadata name/type,createdby/modifiedby user etc..

User-added image

Thanks,
Niranjan
Suraj Lal GuptaSuraj Lal Gupta
Qin, 
By any chance, could you figure out how to get lastmodified date on an object?
Basant Kr VermaBasant Kr Verma
Seems like no one marked Liudmila Likhovid's comment as best Answer, that answered solved my problem where I had to fetch the CreatedDate, CreatedBy, LastModifiedDate and LastModifiedBy information and I am able to do that by Tooling API Rest api.

Qin please mark that as best answer to help other peoples. 
Malika Pathak 9Malika Pathak 9

Hi Qin,

if you want to find LastModifiedByDate then use this code for every record,

Please Use this query to find LastModifiedByDate  . this query is best.

[Select id, Name, LastModifiedDate  From Account ];

If you find this helpful mark it as the best answer.

Robert KasprzykRobert Kasprzyk
From this question I get you need 2 queries. One for the Object and one for the Field on the object.

For the object you can use:
  • SELECT LastModifiedDate FROM Account (or whatever you're object is) WHERE Id =:yourId
For the field definition you can use:
  • SELECT Label, QualifiedApiName, DataType, LastModifiedDate FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName  = 'Account' (or whatever you're object is)
Hopefully this helps anyone in the future.