• peterppt
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 8
    Replies

 

I want to create a recurring event record and then query the Event and obtain the RecurrenceActivityId.  Once I've done that I can create a single event record and link it to the recurring event record via the RecurrenceActivityID.  How can I obtain the RecurrenceActivityID which is auto generated ?

 

Thanks.

 

We use third part calendaring software which does not handle public events or recurring events in the the way we want.

We have succesfully implemented ( with help from this forum) a trigger that fires on the beforeinsert event and changes the OwnerID of the record.  This sorts our public calendar problems very well.

 

We want to do something similar for recurring events.  The problem is that the software creates events which are not marked as recurring and to my knowledge there is no way to change a normal event to a resurring event.  So our plan is to intercept the event data before the table is updated and add the minimum fields required to make the event recurring - creating a simple as possible recurring pattern.  The key is that when the user goies into edit the record, he has the opportunity to edit the recurrence pattern.

 

When a normal recurring event is created where start date of recurring pattern = end date,  SF seems to create two records - one as a normal event, and the other with the same data but with the recurring data fields completed.  These records are linked with a value in the field RecurrenceActivityID field.  However using the Excel Connector I  can create a recurring event by just using the record with all the recurring data.  And when I go to edit this record, I can change the recurrence pattern and, when the changes are saved events for the whole pattern will be created. Perfect.

 

The problem.... is when I try and replicate this with trigger code the record save fails, either with a specific error message ( e.g. missing field - these errors I  have corrected ) or - worse - just with a fail message.

 

To date my Apex coding expeirence is light so I'm not sure where to go. Is the approach I'm proposing valid ?   I'm a little uneasy that SF seems to  generate two records - I'd try and mimiick this but I can see this making my simple code rather more complex - it then becomes two insert operations and, more problematical, I have to grab the RecurrenceAcivityID value that SF has generated.

 

The current trigger code is below

trigger Peter1 on Event (before insert) {
   if (trigger.isBefore && trigger.isInsert) {
      
      for (Event e : trigger.new) {
          if ( e.public_name__c == 'Hennock' ) {
              e.OwnerId = '023b000000098Dx';
         }
          if ( e.public_name__c == 'Bovey Church Rooms' ) {
              e.OwnerId = '023b000000098Ds';
         }
          if ( e.public_name__c == 'PPT Bovey' ) {
              e.OwnerId = '023b000000098Dn';
         }
        if (e.create_recurring_event__c == True)  {
    
          e.RecurrenceTimeZoneSidKey = 'Europe/London'; 
          e.RecurrenceType = 'RecursWeekly';
          e.IsRecurrence = True; 
          e.RecurrenceDayOfWeekMask = 62; 
          e.RecurrenceStartDateTime = e.StartDateTime;
      
          datetime t = e.StartDateTime;
          e.RecurrenceEndDateOnly = Date.newInstance(t.year(),t.month(),t.day());  
          e.RecurrenceInterval = 1 ;  
          e.RecurrenceDayOfMonth = Null;
          e.RecurrenceInstance = Null;
          e.ActivityDate =  Date.newInstance(t.year(),t.month(),t.day());  
          e.ActivityDateTime = e.StartDateTime;
       }
  
      }
   }
   // All done!
 }

The only other thing I can add  relates to error messages I have had relating to the RecurringInterval field.  These have said this should be Null, but setting this field  = Null, = 0 ( it is a integer field ) or leaving the whole assignment statment out all cause errors.  In the excel connector the update works with the cell left blank.  But I've not ventured into the VBA code to see what value is passed to SF - perhaps I should !

 

So any help anyone can give here will be much appreciated.

 

Thanks

 

Peter

I have (with Forum help !) created a simple Trigger which works beautifully.

 

trigger Peter1 on Event (before insert) {
   if (trigger.isBefore && trigger.isInsert) {
     
      for (Event e : trigger.new) {
          if ( e.public_name__c == 'Hennock' ) {
                e.OwnerId = '023b000000098Dx';
         }
      }
   }
   // All done!
}

 I have ( again with forum help ) got the following test code to run

 

@isTest
public class PeterTest2 {
     static testMethod void Testx () {
         
        Event objEvent = new Event();
        objEvent.Subject = 'Test666';
        objEvent.OwnerId = '005b0000000M1pvAAC';
        objEvent.StartDateTime = datetime.newInstance(2012, 10, 1, 12, 30, 0);
        objEvent.EndDateTime = datetime.newInstance(2012, 10, 1, 13, 30, 0);
        //objEvent.createdbyid = '005b0000000M1pvAAC';
        objEvent.Public_Name__c = 'Hennock';

        try {
    
        insert objEvent;
        } catch (DmlException e) {
        // Process exception here 
    
        }   
         
     } 

     }

But when I run this it gives Test Coverage : None.   I'm puzzled why my test code is not firing the trigger.  The key is the custom field  Public_Name__c =  'Hennock'  and that is an insert value in the test code.  If you create an event with this value through the user interface then the triggrer fires.

 

If anyone can help me solve this then I think I'm ready to deploy !  Thanks.

I have copied some trigger test code:

 

@isTest
 private class EventTester {
 
    static testMethod void myUnitTest() {
         //COMMENT: First, prepare Dummy Account for relating to Event
         Account acct1 = new Account(name='test account1',Type='Customer');
         insert acct1;
 
        //COMMENT: First, prepare Dummy Event
         Event EventToCreate = new Event(WhatId=acct1.Id,Subject='TESTING',StartDateTime=Today());
            insert EventToCreate;
 
//COMMENT: Inserting the event with a start date value should have caused your trigger to fire which means you can move on to the verification steps
 //Cont'd: however, if you have a trigger based on updating or something, be aware that you would perform that action before verification and AFTER
 //Cont'd: inserting your dummy records inside of the test class.
        
//COMMENT:  Verify correct action using System asserts (these make sure your trigger did what it is supposed to)
     //COMMENT:  first, we locate the Event that has been updated (as opposed to the event that was inserted, because the trigger has changed that origianl event
         Event EvtUpd = [select UsableDueDate__c, StartDateTime from Event where id = :EventToCreate.Id];
     //COMMENT:  then we assert that the field we updated equals the field it was updated from
         System.assert(EvtUpd.UsableDueDate__c == EventToCreate.StartDateTime);
     }
 }

 

But when I try and un it I get the above error.

 

Any help much appreciated !  Thanks.

I have the following code  which compiles but gives the following error:

 

Apex trigger Peter1 caused an unexpected exception, contact your administrator:
Peter1: execution of BeforeInsert caused by: System.NullPointerException:
Attempt to de-reference a null object: Trigger.Peter1: line 3, column 1

 

trigger Peter1 on Event (before insert) {

Event myEvent = trigger.old[0];
Event myNewEvent = trigger.new[0];
if (myEvent.IsAllDayEvent = True) {
myNewEvent.Subject = myEvent.Location; 
update myEvent;
}// else nothing

 I've had little experience with SF triggers to date and I'm struggling a bit with trigger.old and trigger.new !   Any help here would be much appreciated.  Thanks.

 

 

I've used the toolkit for several applications to read data - but never to insert or update.  So I'm happy that the connection code and the WSDL are ok.

 

I'm trying to replicate the sample code PHP Toolkit 20.0 Upsert Sample (Enterprise) to insert a new contact record before tying something more adventurous !

 

<?php

define("USERNAME", "XXXXXXX");
define("PASSWORD", "YYYY");
define("SECURITY_TOKEN", "ZZZZZZZZZZZZZZZZZZZZ");



require_once ('soapclient/SforceEnterpriseClient.php');
require_once ('userAuth.php');

try {
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("soapclient/enterprise.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

$sObject = new stdClass();

$sObject->FirstName = 'George';
$sObject->LastName = 'Smith';
$sObject->Phone = '512-555-555';
$sObject->BirthDate = '1927-01-25';
$sObject->Email = 'test@example.com';
	
$createResponse = $this->$mySforceConnection->create(array($sObject),'Contact');
echo "Creating new contact \r\n";
print_r($createResponse);	

} catch(Exception $e) {	
	echo $mySforceConnection->getLastRequest();
	echo $e->faultstring;
	
}

?>

 

The above code fails without any error message - presumably it fails to compile, although it passes my .php editor's checks.  I've changed the line 

 

$createResponse = $this->_$mySforceConnection->create(array($sObject),'Contact');

 

to

 

$createResponse = $this->$mySforceConnection->create(array($sObject),'Contact'); ( i.e removed the leading underscore ) because this gives a code error in my code checker.

 

Can anyone suggest what might be wrong with this code ?

 

Thanks.

Is there a simple way to format a date and time currently displayed as 2012-11-06T23:00:00.000Z  as  dd/mm/yyyy hh:mm ?  I've looked at various php formatting functions but can't find one suitable.  I could do this by string manipulation but hope there is a simpler approach !

 

Thanks

I am using the following code to display records from the Event Table.

<?php

define("USERNAME", "xxxx");
define("PASSWORD", "yyyy");
define("SECURITY_TOKEN", "zzz");



require_once ('soapclient/SforceEnterpriseClient.php');
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("soapclient/enterprise.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);




$query = "SELECT Subject,Description,EndDateTime,StartDateTime,OwnerID,Public_Name__c,Web_Publish__c  from Event WHERE Web_Publish__c = TRUE";
$response = $mySforceConnection->query($query);
?>
<table id="customers">
<tr>
  <th>Subject</th>
  <th>Description</th>
  <th>End</th>
  <th>Start</th>
  <th>Owner</th>
  <th>Location</th>
  <th>Web Publish</th>
  
</tr>

<?php

foreach ($response->records as $record) {
		
echo "<tr>";
echo "<td>".$record->Subject."</td>";
echo "<td>".$record->Description."</td>";
echo "<td>".$record->EndDateTime."</td>";
echo "<td>".$record->StartDateTime."</td>";
echo "<td>".$record->OwnerID."</td>";
echo "<td>".$record->Public_Name__c."</td>";
echo "<td>".$record->Web_Publish__c."</td>";

echo "</tr>";
	

}


?>

 

The results are shown here.  The event fields  subject, description and start and end times display (  times need formatting sensibly !)  but niether of the custom fields or the field ownerid appear.  One of the custom fields (Web_Publish__c) is used to filter the results, so the query recognises the field - but for some reason this fails to display.  Using the Office Toolkit, all of this data correctly appears in Excel or Access. 

 

It seems to me the problem is a php display issue.  I must be doing something silly.

 

Any help much appreciated !  Thanks.

 

I have (with Forum help !) created a simple Trigger which works beautifully.

 

trigger Peter1 on Event (before insert) {
   if (trigger.isBefore && trigger.isInsert) {
     
      for (Event e : trigger.new) {
          if ( e.public_name__c == 'Hennock' ) {
                e.OwnerId = '023b000000098Dx';
         }
      }
   }
   // All done!
}

 I have ( again with forum help ) got the following test code to run

 

@isTest
public class PeterTest2 {
     static testMethod void Testx () {
         
        Event objEvent = new Event();
        objEvent.Subject = 'Test666';
        objEvent.OwnerId = '005b0000000M1pvAAC';
        objEvent.StartDateTime = datetime.newInstance(2012, 10, 1, 12, 30, 0);
        objEvent.EndDateTime = datetime.newInstance(2012, 10, 1, 13, 30, 0);
        //objEvent.createdbyid = '005b0000000M1pvAAC';
        objEvent.Public_Name__c = 'Hennock';

        try {
    
        insert objEvent;
        } catch (DmlException e) {
        // Process exception here 
    
        }   
         
     } 

     }

But when I run this it gives Test Coverage : None.   I'm puzzled why my test code is not firing the trigger.  The key is the custom field  Public_Name__c =  'Hennock'  and that is an insert value in the test code.  If you create an event with this value through the user interface then the triggrer fires.

 

If anyone can help me solve this then I think I'm ready to deploy !  Thanks.

I have copied some trigger test code:

 

@isTest
 private class EventTester {
 
    static testMethod void myUnitTest() {
         //COMMENT: First, prepare Dummy Account for relating to Event
         Account acct1 = new Account(name='test account1',Type='Customer');
         insert acct1;
 
        //COMMENT: First, prepare Dummy Event
         Event EventToCreate = new Event(WhatId=acct1.Id,Subject='TESTING',StartDateTime=Today());
            insert EventToCreate;
 
//COMMENT: Inserting the event with a start date value should have caused your trigger to fire which means you can move on to the verification steps
 //Cont'd: however, if you have a trigger based on updating or something, be aware that you would perform that action before verification and AFTER
 //Cont'd: inserting your dummy records inside of the test class.
        
//COMMENT:  Verify correct action using System asserts (these make sure your trigger did what it is supposed to)
     //COMMENT:  first, we locate the Event that has been updated (as opposed to the event that was inserted, because the trigger has changed that origianl event
         Event EvtUpd = [select UsableDueDate__c, StartDateTime from Event where id = :EventToCreate.Id];
     //COMMENT:  then we assert that the field we updated equals the field it was updated from
         System.assert(EvtUpd.UsableDueDate__c == EventToCreate.StartDateTime);
     }
 }

 

But when I try and un it I get the above error.

 

Any help much appreciated !  Thanks.

I have the following code  which compiles but gives the following error:

 

Apex trigger Peter1 caused an unexpected exception, contact your administrator:
Peter1: execution of BeforeInsert caused by: System.NullPointerException:
Attempt to de-reference a null object: Trigger.Peter1: line 3, column 1

 

trigger Peter1 on Event (before insert) {

Event myEvent = trigger.old[0];
Event myNewEvent = trigger.new[0];
if (myEvent.IsAllDayEvent = True) {
myNewEvent.Subject = myEvent.Location; 
update myEvent;
}// else nothing

 I've had little experience with SF triggers to date and I'm struggling a bit with trigger.old and trigger.new !   Any help here would be much appreciated.  Thanks.

 

 

I've used the toolkit for several applications to read data - but never to insert or update.  So I'm happy that the connection code and the WSDL are ok.

 

I'm trying to replicate the sample code PHP Toolkit 20.0 Upsert Sample (Enterprise) to insert a new contact record before tying something more adventurous !

 

<?php

define("USERNAME", "XXXXXXX");
define("PASSWORD", "YYYY");
define("SECURITY_TOKEN", "ZZZZZZZZZZZZZZZZZZZZ");



require_once ('soapclient/SforceEnterpriseClient.php');
require_once ('userAuth.php');

try {
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("soapclient/enterprise.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

$sObject = new stdClass();

$sObject->FirstName = 'George';
$sObject->LastName = 'Smith';
$sObject->Phone = '512-555-555';
$sObject->BirthDate = '1927-01-25';
$sObject->Email = 'test@example.com';
	
$createResponse = $this->$mySforceConnection->create(array($sObject),'Contact');
echo "Creating new contact \r\n";
print_r($createResponse);	

} catch(Exception $e) {	
	echo $mySforceConnection->getLastRequest();
	echo $e->faultstring;
	
}

?>

 

The above code fails without any error message - presumably it fails to compile, although it passes my .php editor's checks.  I've changed the line 

 

$createResponse = $this->_$mySforceConnection->create(array($sObject),'Contact');

 

to

 

$createResponse = $this->$mySforceConnection->create(array($sObject),'Contact'); ( i.e removed the leading underscore ) because this gives a code error in my code checker.

 

Can anyone suggest what might be wrong with this code ?

 

Thanks.

Is there a simple way to format a date and time currently displayed as 2012-11-06T23:00:00.000Z  as  dd/mm/yyyy hh:mm ?  I've looked at various php formatting functions but can't find one suitable.  I could do this by string manipulation but hope there is a simpler approach !

 

Thanks

I am using the following code to display records from the Event Table.

<?php

define("USERNAME", "xxxx");
define("PASSWORD", "yyyy");
define("SECURITY_TOKEN", "zzz");



require_once ('soapclient/SforceEnterpriseClient.php');
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("soapclient/enterprise.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);




$query = "SELECT Subject,Description,EndDateTime,StartDateTime,OwnerID,Public_Name__c,Web_Publish__c  from Event WHERE Web_Publish__c = TRUE";
$response = $mySforceConnection->query($query);
?>
<table id="customers">
<tr>
  <th>Subject</th>
  <th>Description</th>
  <th>End</th>
  <th>Start</th>
  <th>Owner</th>
  <th>Location</th>
  <th>Web Publish</th>
  
</tr>

<?php

foreach ($response->records as $record) {
		
echo "<tr>";
echo "<td>".$record->Subject."</td>";
echo "<td>".$record->Description."</td>";
echo "<td>".$record->EndDateTime."</td>";
echo "<td>".$record->StartDateTime."</td>";
echo "<td>".$record->OwnerID."</td>";
echo "<td>".$record->Public_Name__c."</td>";
echo "<td>".$record->Web_Publish__c."</td>";

echo "</tr>";
	

}


?>

 

The results are shown here.  The event fields  subject, description and start and end times display (  times need formatting sensibly !)  but niether of the custom fields or the field ownerid appear.  One of the custom fields (Web_Publish__c) is used to filter the results, so the query recognises the field - but for some reason this fails to display.  Using the Office Toolkit, all of this data correctly appears in Excel or Access. 

 

It seems to me the problem is a php display issue.  I must be doing something silly.

 

Any help much appreciated !  Thanks.