• Watts Jonas
  • NEWBIE
  • 25 Points
  • Member since 2019

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi All,
I am not able to finish this requriment can any on help on this 

my requriment is user should not upload files through Notes &attachments which is in related list of parent object it because user only  attach document at the time  parent record is created so we have created lighting component for uploading the documents but user can upload the document in related lsit we don't wanted allow the users to upload.
can any one give me the suggestion how to achive this requirment/complete .
Or any one done this requriment
but i tried to through trigger through error message on related list page but it is not happening are we can't achive through trigger can any on help
User-added image
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
Hi All,
I am not able to finish this requriment can any on help on this 

my requriment is user should not upload files through Notes &attachments which is in related list of parent object it because user only  attach document at the time  parent record is created so we have created lighting component for uploading the documents but user can upload the document in related lsit we don't wanted allow the users to upload.
can any one give me the suggestion how to achive this requirment/complete .
Or any one done this requriment
but i tried to through trigger through error message on related list page but it is not happening are we can't achive through trigger can any on help
User-added image