-3

I have a field called "Date" on custom object "TestData__c".

If I create a record today I need to display today date.If I create a record tomorrow I need to display Tomorrow date.How Can I achieve this.

How to make Date field as dynamic

Example

Records like

Name : "Test1" date : "17/08/2019"
Name : "Test2 date" : "18/08/2019"
Nmae : "Test3 date" : "19/08/2019"

Anyone help me on this requirement.

Thanks

1

Try

SELECT MAX(CreatedDate) FROM TestData__c

or similar. Take a look at aggregate functions.

0

You can get the Date from the CreatedDate field by creating a formula field with below formula

DATEVALUE( CreatedDate )

Alternatively, you can also create a Date field and populate it in Before Insert trigger with below code

TestData__c.Date__c = System.Today();

This will help to keep the Date field dynamic.

However, this is not at all required because you can get this information dynamically from CreatedDate field and if you require the data in reports its already avaliable. If you require this data while processing then you can write something like

Date myDate = TestData__c.Date__c.date(); // to return Date in user's timezone

or

Date myDate = TestData__c.Date__c.dateGMT(); // to return Date in GMT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.