You need to sign in to do that
Don't have an account?
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
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.
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
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.
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.
You can fetch the lastmodified date through SOQL query :
Employee__c obj = [select id, lastmodifieddate from Employee__c where lastmodifieddate <= system.now()];
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
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
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.
Hi all,
Did anybody already find a solution to this one ?
Thanks
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?
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.
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.
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.
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..
Thanks,
Niranjan
By any chance, could you figure out how to get lastmodified date on an object?
Qin please mark that as best answer to help other peoples.
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.
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.