在 Salesforce 中使用 Apex 创建多联系人事件

Creating a Multi-Contact Event with Apex in Salesforce

我正在尝试使用 Apex 创建多联系人事件。

我已经在临时组织的 activity 设置中启用了 Allow Users to Relate Multiple Contacts to Tasks and Events

我正在按照 these 文档底部的指南和示例进行操作,但是在推送到 scratch org 时我经常遇到错误:

// ...
event.setEventWhoIds(attendeeContactIds);
// ...

Method does not exist or incorrect signature: void setEventWhoIds(List<String>) from the type Event.

我还尝试直接写入字段:

event.EventWhoIds = attendeeContactIds;

有了这个,我得到了错误,该字段不可写。

attendeeContactIds 是表示联系人 ID 的字符串列表。

我可能会遗漏什么? ‍♂️

有点傻,在apex里面是只读的。它是公开的,因此集成可以在一个全有或全无的事务中快速创建事件和本质上相关的列表。另见 https://salesforce.stackexchange.com/questions/238094/eventwhoids-is-not-writeable-in-apex-class-but-working-on-jsforce

试试这样的东西?

Savepoint sp = Database.setSavepoint();

event e = new Event(
    StartDateTime = System.now(),
    EndDateTime = System.now().addHours(1)
);
insert e;

List<EventRelation> invitations = new List<EventRelation>();
for(Contact c : [SELECT Id FROM Contact LIMIT 5]){
    invitations.add(new EventRelation(
        EventId = e.Id,
        RelationId = c.Id,
        IsInvitee = true
    ));
}
insert invitations;

Database.rollback(sp); // unless you really want to send it out