• Joel R
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
Hi All,

I have an issue with using the convertTimezone and DAY_ONLY together for a SOQL query. According to the following documentation, convertTimezone should first convert datetime to local time zone before performing aggregates:  https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_convert_time_zone.htm

For my test, I am running the following aggregate query for two records:
SELECT DAY_ONLY(convertTimezone(createddate)), COUNT(id), MIN(id), MAX(id), MIN(createdDate), MAX(createdDate) 
FROM CustomObject__c
WHERE Id IN ('a0Q7F00000iUUNCUA4', 'a0Q7F00000iUUOPUA4')
GROUP BY DAY_ONLY(convertTimezone(createddate))

This returns an aggregate result set. Both records were created on the same day:
  1. a0Q7F00000iUUNCUA4 created at 2021-07-18T11:38:47.000+0000 (UTC)
  2. a0Q7F00000iUUOPUA4 created at 2021-07-18T13:30:31.000+0000 (UTC)
My user profile is set +10 timezone so in local time both these records are still created on the same day:
  1. a0Q7F00000iUUNCUA4 created at 2021-07-18T21:38:47.000+0000 (UTC)
  2. a0Q7F00000iUUOPUA4 created at 2021-07-18T23:30:31.000+0000 (UTC)
However, the Aggregate SOQL query shows the DAY_ONLY value for the one of the records (a0Q7F00000iUUOPUA4) as 2021-07-19
day_only(createddate) | count(id) | min(id)            | min(createdDate)             | max(createdDate) 
2021-07-18            | 1         | a0Q7F00000iUUNCUA4 | 2021-07-18T11:38:47.000+0000 | 2021-07-18T11:38:47.000+0000 
2021-07-19            | 1         | a0Q7F00000iUUOPUA4 | 2021-07-18T13:30:31.000+0000 | 2021-07-18T13:30:31.000+0000


I don't believe that record a0Q7F00000iUUOPUA4 should be grouped into the 2021-07-19, since it was created on 2021-07-18, both in UTC and +10 Time zone.

I would like to know if anyone else has seen this behaviour, and if there are any known workarounds (or maybe it's a bug).

The only other thing i can think to mention is that my timezone is +10, but the Local is English (Ireland), so reporting weeks start on a Monday.
Perhaps for some crazy reason convertTimezone considers the Local when calculating timezone :).


Thanks.

Hi Everyone,

I've spent quite a while trying to resolve my issue with no success so reaching out to the "brains trust".

I want to be able to update the Event's related contact (i.e. WhoId) to be an Invitee for the event when a custom "Send Invite to Contact" checkbox field is checked.

I have created an Event trigger (after insert, after update), so that when a new Event is created or an existing record is updated and the new field is true, the trigger looks for the related EventRelation records for the Event, for the WhoId (EventRelation.RelationId), and set the IsAttendee field to TRUE.

Below is the snippet of code in the Trigger:
List <EventRelation> ers = [
            SELECT Id, EventId, RelationId, IsParent, IsInvitee, Status
            FROM EventRelation
            WHERE EventId IN : evtsForCalInvites.keySet()
];
// event Id / contact id, EventRelation
Map <string, EventRelation> ersMap = new Map <string, EventRelation>();
for (EventRelation er : ers)
{
    ersMap.put((string)er.EventId + (string)er.RelationId, er);
}

List <EventRelation> ersToUpsert = new List <EventRelation> ();
for (Event evt : evtsForCalInvites.values())
{
    EventRelation er = new EventRelation();            
    if (ersMap.containsKey((string)evt.Id + (string)evt.WhoId))
    {                
        System.debug('Existing EventRelation record found');
        er = ersMap.get((string)evt.Id + (string)evt.WhoId);
    }
    else
    {
        System.debug('Creating new EventRelation record');
        er.EventId = evt.Id;
        er.RelationId = evt.WhoId;
    }            
    er.IsInvitee = true;
    ersToUpsert.add(er);
}
upsert ersToUpsert;

I created a Test case that performs the following:
  1. Create Contact
  2. Create Event with Contact as WhoId and set Send_Calendar_Invite_to_Contact__c = true to the code in the trigger fires.
By the time the after trigger has fired, the EventRelation records are already created, and so the EventRelation record will always be updated.

When the upsert occurs, I get the following error message from Salesforce "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, When isInvitee is false, the invitee attributes Status, Response, and Responded Date may not be modified: []"

This is a very strange error message, which I haven't seen on the Internet before. Would someone be able to help?

Many thanks.
  • January 26, 2020
  • Like
  • 0
Hello fellow SF Developers,

We are experiencing an issue where an Email Alert using a Visualforce Email Template does not work from either a workflow or Process Builder process when the user executing is a Site user.

The Site user definitely has the necessary object permissions needed for the Visualforce Email template, and the Email Template does not call on any Apex controller.

If I remove any dynamic merging code, the error doesn’t occur. The following VF Email Template works just fine:
<messaging:emailTemplate subject="Test" relatedToType="pba__Request__c">
<messaging:htmlEmailBody >
<html><body>Test</body></html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>



But as soon as I add any reference to a merge field to the template (e.g. "{!relatedTo.Id}", the error occurs:
<messaging:emailTemplate subject="{!relatedTo.Id}" relatedToType="pba__Request__c">
<messaging:htmlEmailBody >
<html><body>Test</body></html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

When a Process Builder calls the Email Alert, I get an error saying "Error Occurred: java.lang.NullPointerException"

Has anyone experienced this before, or can suggest things to troubleshoot and find the root cause?
  • August 14, 2019
  • Like
  • 0
Hi Everyone,

I've spent quite a while trying to resolve my issue with no success so reaching out to the "brains trust".

I want to be able to update the Event's related contact (i.e. WhoId) to be an Invitee for the event when a custom "Send Invite to Contact" checkbox field is checked.

I have created an Event trigger (after insert, after update), so that when a new Event is created or an existing record is updated and the new field is true, the trigger looks for the related EventRelation records for the Event, for the WhoId (EventRelation.RelationId), and set the IsAttendee field to TRUE.

Below is the snippet of code in the Trigger:
List <EventRelation> ers = [
            SELECT Id, EventId, RelationId, IsParent, IsInvitee, Status
            FROM EventRelation
            WHERE EventId IN : evtsForCalInvites.keySet()
];
// event Id / contact id, EventRelation
Map <string, EventRelation> ersMap = new Map <string, EventRelation>();
for (EventRelation er : ers)
{
    ersMap.put((string)er.EventId + (string)er.RelationId, er);
}

List <EventRelation> ersToUpsert = new List <EventRelation> ();
for (Event evt : evtsForCalInvites.values())
{
    EventRelation er = new EventRelation();            
    if (ersMap.containsKey((string)evt.Id + (string)evt.WhoId))
    {                
        System.debug('Existing EventRelation record found');
        er = ersMap.get((string)evt.Id + (string)evt.WhoId);
    }
    else
    {
        System.debug('Creating new EventRelation record');
        er.EventId = evt.Id;
        er.RelationId = evt.WhoId;
    }            
    er.IsInvitee = true;
    ersToUpsert.add(er);
}
upsert ersToUpsert;

I created a Test case that performs the following:
  1. Create Contact
  2. Create Event with Contact as WhoId and set Send_Calendar_Invite_to_Contact__c = true to the code in the trigger fires.
By the time the after trigger has fired, the EventRelation records are already created, and so the EventRelation record will always be updated.

When the upsert occurs, I get the following error message from Salesforce "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, When isInvitee is false, the invitee attributes Status, Response, and Responded Date may not be modified: []"

This is a very strange error message, which I haven't seen on the Internet before. Would someone be able to help?

Many thanks.
  • January 26, 2020
  • Like
  • 0
Hello fellow SF Developers,

We are experiencing an issue where an Email Alert using a Visualforce Email Template does not work from either a workflow or Process Builder process when the user executing is a Site user.

The Site user definitely has the necessary object permissions needed for the Visualforce Email template, and the Email Template does not call on any Apex controller.

If I remove any dynamic merging code, the error doesn’t occur. The following VF Email Template works just fine:
<messaging:emailTemplate subject="Test" relatedToType="pba__Request__c">
<messaging:htmlEmailBody >
<html><body>Test</body></html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>



But as soon as I add any reference to a merge field to the template (e.g. "{!relatedTo.Id}", the error occurs:
<messaging:emailTemplate subject="{!relatedTo.Id}" relatedToType="pba__Request__c">
<messaging:htmlEmailBody >
<html><body>Test</body></html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

When a Process Builder calls the Email Alert, I get an error saying "Error Occurred: java.lang.NullPointerException"

Has anyone experienced this before, or can suggest things to troubleshoot and find the root cause?
  • August 14, 2019
  • Like
  • 0