• Moni Jais
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
Anyone done ordering rows by drag and drop using lwc components. If yes can you please help.
I have a problem with nested iteration elements in LWC. It is duplicating a column from a parent row instead of displaying what is needed.

In order to reproduce the problem create a test Lightning App and drop testLWC component on it. When "Test" button is clicked a new row is generated in a table, however, the "Upload" button in column 3 is not supposed to be there.


testLWC.html:
<template>

    <div class="slds-box">
        <lightning-card  title="Test Component" icon-name="standard:file">
            <lightning-button label="Test" onclick={testFunction} slot="actions"></lightning-button>


            <table class="slds-table slds-table_cell-buffer slds-table_header-hidden slds-table_bordered">
                <tbody>
                    <template for:each={sections} for:item="section" for:index="indexParent">
                        <tr key={section.index}>
                            <td>
                                {section.Name}
                            </td>
                            <td>
                                col 2
                            </td>
                            <td>
                                <lightning-button label="Upload" onclick={testFunction} ></lightning-button>
                            </td>
                            <td>
                                col 4
                            </td>
                        </tr>
                        <template for:each={section.rowList} for:item="row" for:index="indexChild">
                            <tr key={row.index}>
                                <td>
                                    {row.Name}
                                </td>
                                <td>
                                    child col 2
                                </td>
                                <td>
                                    child col 4
                                </td>
                                <td>
                                    child col 4
                                </td>
                            </tr>
                        </template>
                    </template>
                </tbody>
            </table>
            
        </lightning-card>
    </div>
</template>

testLWC.js:
import { LightningElement, track } from 'lwc';

export default class TestLWC extends LightningElement {

    @track sections =   [
                        {Name:"Section 1", rowList:[]} //{Name:"Row 1"},{Name:"Row 2"},{Name:"Row 3"}
                        ,{Name:"Section 1", rowList:[]}
                        ]; //{Name:"Row 1"},{Name:"Row 2"},{Name:"Row 3"}]}

    connectedCallback(){
        // default logic
    }

    testFunction(){
        this.sections[0].rowList.push({Name:'Test'});
    }

}
Before Click:
Before ClickAfter Click:
After Click
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