addMembersWithPlans(membersWithPlansInputRepresentation, censusId)
API Version
68.0
Requires Chatter
No
Signature
public static ConnectApi.MembersWithPlansRepresentation addMembersWithPlans(ConnectApi.MembersWithPlansInputRepresentation membersWithPlansInputRepresentation, String censusId)
Parameters
- membersWithPlansInputRepresentation
- Type: ConnectApi.MembersWithPlansInputRepresentation
- Details of the members to add, the insurance plans to assign to each member, and the flow and duplicate detection settings to use while the members are processed.
- censusId
- Type: String
- ID of the group census to add the members to.
Return Value
Usage
Use this method to add a family of group census members, along with the insurance plans for each member, to a group census in a single call. Specify the group census in censusId and the members in the members property of the input representation.
For each member, specify name. Specify the member's plans in groupCensusMemberPlans. The addedPlans, upsertedPlans, and deletedPlans properties apply only when you update members with updateMembersWithPlans(membersWithPlansInputRepresentation, censusId).
To relate a dependent to a primary member, set the dependent's primaryGroupCensusMemberId and associationWithPrimaryMbr properties. For each plan, specify either contractGroupPlanId for a plan on the census's contract, or productCode and rootProductCode for an off-contract coverage.
Members are checked for duplicates by using the FirstName, LastName, AssociationWithPrimaryMbr, Email, and GroupCensusId fields. To include more fields in the duplicate check, specify their API names in duplicateDetectionFields.
Check the isSuccess property of the response to determine whether the operation succeeded. Request-level errors are in the top-level errors property, which is empty when isSuccess is true. Member-specific errors are in the errors property of each item in members.
Example
Here's an example of how to add a primary group census member and a dependent, each with their insurance plans, from Apex code. When you add a member, don't set the id property, and specify the member's plans in groupCensusMemberPlans.
1// Add group census members and their insurance plans in a single call.
2
3final String CENSUS_ID = '0rfxx000000022IAAQ';
4final String GROUP_CLASS_ID = '0rExx000000004uEAA';
5final String CGP_1 = '0rgxx00000001W4AAI';
6final String CGP_2 = '0rgxx00000001W3AAI';
7
8// 1) Build the plans for the primary member.
9ConnectApi.MemberPlanInputRepresentation primaryPlan1 = new ConnectApi.MemberPlanInputRepresentation();
10primaryPlan1.contractGroupPlanId = CGP_1;
11
12ConnectApi.MemberPlanInputRepresentation primaryPlan2 = new ConnectApi.MemberPlanInputRepresentation();
13primaryPlan2.contractGroupPlanId = CGP_2;
14
15// 2) Build the primary member.
16ConnectApi.MemberWithPlansInputRepresentation primary = new ConnectApi.MemberWithPlansInputRepresentation();
17primary.name = 'Apex AddTest Primary';
18primary.firstName = 'ApexAdd';
19primary.lastname = 'Primary';
20primary.associationWithPrimaryMbr = 'Self';
21primary.memberType = 'Primary';
22primary.birthdate = '1988-03-10';
23primary.gender = 'Male';
24primary.email = 'apexadd.primary@example.com';
25primary.groupClassId = GROUP_CLASS_ID;
26primary.isOptOutAllPlans = false;
27primary.isPortalUser = false;
28primary.groupCensusMemberPlans = new List<ConnectApi.MemberPlanInputRepresentation>{ primaryPlan1, primaryPlan2 };
29
30// 3) Build a dependent of the primary member.
31ConnectApi.MemberPlanInputRepresentation dependentPlan = new ConnectApi.MemberPlanInputRepresentation();
32dependentPlan.contractGroupPlanId = CGP_1;
33
34ConnectApi.MemberWithPlansInputRepresentation dependent = new ConnectApi.MemberWithPlansInputRepresentation();
35dependent.name = 'Apex AddTest Spouse';
36dependent.firstName = 'ApexAdd';
37dependent.lastname = 'Spouse';
38dependent.associationWithPrimaryMbr = 'Spouse';
39dependent.memberType = 'Dependent';
40dependent.birthdate = '1990-07-22';
41dependent.gender = 'Female';
42dependent.groupClassId = GROUP_CLASS_ID;
43dependent.isOptOutAllPlans = false;
44dependent.isPortalUser = false;
45dependent.groupCensusMemberPlans = new List<ConnectApi.MemberPlanInputRepresentation>{ dependentPlan };
46
47// 4) Add both members to the group census.
48ConnectApi.MembersWithPlansInputRepresentation input = new ConnectApi.MembersWithPlansInputRepresentation();
49input.members = new List<ConnectApi.MemberWithPlansInputRepresentation>{ primary, dependent };
50
51try {
52 ConnectApi.MembersWithPlansRepresentation result =
53 ConnectApi.GroupBenefitsApi.addMembersWithPlans(input, CENSUS_ID);
54
55 System.debug('isSuccess: ' + result.isSuccess);
56 for (ConnectApi.MemberWithPlansRepresentation member : result.members) {
57 System.debug('memberId: ' + member.memberId
58 + ', memberPlans: ' + member.memberPlans
59 + ', errors: ' + member.errors);
60 }
61} catch (Exception e) {
62 System.debug('Error while adding members with plans: ' + e.getMessage());
63}