Salesforce - Copy DateTime value from Event to Date field on related Opportunity

Tag: datetime , triggers , salesforce , apex Author: kukukafeidou Date: 2014-04-07

I have a simple trigger to copy the StartDateTime from a calendar event into a field called "Service Start Date" on the related Opportunity any time a calendar event is created or changed.

I'm stuck on converted the StartDateTime to a regular Date field, which is on the opportunity.

trigger EventServiceStartDateforOpp on Event (after insert, after update) {
List<Opportunity> opps = new List<Opportunity>{};

if (trigger.isInsert)
{
for (Event t : trigger.new)
{
if (t.OwnerId == '02340000000WATv')
{opps.add(new Opportunity(Id=t.WhatId, Service_Start_Date__c=t.StartDateTime));
}}}}

Other Answer1

date d = Date.newInstance(tiempo.year(),tiempo.month(),tiempo.day());