+ Start a Discussion
Santosh SSantosh S 

Assistance for creating New Calendar Event using Trigger

Request Assistance for the following code for updating the Calendar Event Please:

------------------------------------------------------------------------------------------------------

trigger UpdateTEevent on New__c (after insert) {

List <Event> TENewEvents = new List <Event>();

for (New__c TEevent : Trigger.new)
  {
    Event te = new Event();
    te.StartDateTime = TEevent.Start_Process_By__c;
    te.EndDateTime = TEevent.Start_Process_By__c;
    te.Subject = TEevent.AssignEvent__c;
    te.OwnerId = TEevent.Implement__c;
    te.WhatId = TEevent.Name;  // New__c.Name is Auto Number; getting Error on this Line (Error Message below)
      
    TENewEvents.add(te);
 
  }
 
  insert TENewEvents;
}

--------------------------------------------------------------------------------------------------------------------------------

Error: Invalid Data. Review all error messages below to correct your data.
Apex trigger UpdateTEevent caused an unexpected exception, contact your administrator: UpdateTEevent: execution of AfterInsert caused by: System.StringException: Invalid id: COM-00036: Trigger.UpdateTEevent: line 12, column 1

 ----------------------------------------------------

 

Custom Object:  New__c

 

Fields:  Name (Auto Number);  Start_Process_By__c (DateTime); AssigEvent__c ( Text) & Implement__c (Lookup User)

 

Please Help

Best Answer chosen by Admin (Salesforce Developers) 
Madhan Raja MMadhan Raja M

Hi Santhosh,

 

Change TEevent.Name to TEevent.Id

 

----------------------------------

 

trigger UpdateTEevent on New__c (after insert) {

List <Event> TENewEvents = new List <Event>();

for (New__c TEevent : Trigger.new)
  {
    Event te = new Event();
    te.StartDateTime = TEevent.Start_Process_By__c;
    te.EndDateTime = TEevent.Start_Process_By__c;
    te.Subject = TEevent.AssignEvent__c;
    te.OwnerId = TEevent.Implement__c;
    te.WhatId = TEevent.Id;  // New__c.Name is Auto Number; getting Error on this Line (Error Message below)
      
    TENewEvents.add(te);
 
  }
 
  insert TENewEvents;
}

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Madhan Raja M

 

All Answers

Madhan Raja MMadhan Raja M

Hi Santhosh,

 

Change TEevent.Name to TEevent.Id

 

----------------------------------

 

trigger UpdateTEevent on New__c (after insert) {

List <Event> TENewEvents = new List <Event>();

for (New__c TEevent : Trigger.new)
  {
    Event te = new Event();
    te.StartDateTime = TEevent.Start_Process_By__c;
    te.EndDateTime = TEevent.Start_Process_By__c;
    te.Subject = TEevent.AssignEvent__c;
    te.OwnerId = TEevent.Implement__c;
    te.WhatId = TEevent.Id;  // New__c.Name is Auto Number; getting Error on this Line (Error Message below)
      
    TENewEvents.add(te);
 
  }
 
  insert TENewEvents;
}

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Madhan Raja M

 

This was selected as the best answer
SFAdmin5SFAdmin5

change this line 

 

 te.WhatId = TEevent.Name;

 

to this

 

 te.WhatId = TEevent.Id;

Santosh SSantosh S

Thanks & Regards

Santosh SSantosh S

Thanks a lot & Regards