You need to sign in to do that
Don't have an account?
Ryan-Haire
Convert CreatedDate to Date
This is probably a very basic question. I'm new to programming and have spend 2 hours on this.
I'm trying to do a cross object field update trigger stamping one object with the CreatedDate of the other object.
The update field on the object I'm trying to update is of type Date.
How do you convert CreatedDate to a Date field?
I'm trying to do a cross object field update trigger stamping one object with the CreatedDate of the other object.
The update field on the object I'm trying to update is of type Date.
trigger UpdateQSOCreatedDate on FRLS_Round__c (after insert) { List<ID> QSOTargetIds = New List<ID>(); for(FRLS_Round__c r : Trigger.new){ if(r.QSO_Target__c!=null){ QSOTargetIds.add(r.QSO_Target__c); } } List<QSO_Target__c> QSOTargetList = [SELECT id, Date_Last_Round_Created__c FROM QSO_Target__c WHERE id in :QSOTargetIds]; for(integer i = 0 ; i < QSOTargetList.size(); i++){ QSOTargetList[i].Date_Last_Round_Created__c = FRLS_Round__c.CreatedDate; } update QSOTargetList; }
How do you convert CreatedDate to a Date field?
Hi, Ryan, here is a list of the Date/time methods for Apex: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_datetime.htm
date()
Returns the Date component of a Datetime in the local time zone of the context user.
Signature
public Date date()
Return Value
Type: Date
Best,
Jason
Date myDate = date.newinstance(CreatedDate.year(), CreatedDate.month(), CreatedDate.day());