You need to sign in to do that
Don't have an account?
Anusha Gowravarapu
upsert failed in colleborationgroup member object
Hi, I am trying to upsert members to collaboration chatter group but I am receving
"common.apex.runtime.impl.DmlExecutionException: Upsert failed. First exception on row 0; first error: DUPLICATE_VALUE, User is already a Member of this group" exception.
Can some one suggest how to avoid this.Below is my code
List<DistributionList__c> userID=[SELECT userID__C FROM DistributionList__c where ChatterGroupName__c='testgroup'];
List<CollaborationGroupMember> CollGroupMembers = new List<CollaborationGroupMember>();
for(DistributionList__c user : userID)
{
CollaborationGroupMember member = new CollaborationGroupMember();
member.MemberId = user.userID__C;
member.CollaborationGroupId = '0F94D0000004Ebd';
CollGroupMembers.add(member);
}
try
{
upsert CollGroupMembers;
}
catch(DMLException e)
{
system.debug('The group members werent added properly. Error: '+ e);
}
"common.apex.runtime.impl.DmlExecutionException: Upsert failed. First exception on row 0; first error: DUPLICATE_VALUE, User is already a Member of this group" exception.
Can some one suggest how to avoid this.Below is my code
List<DistributionList__c> userID=[SELECT userID__C FROM DistributionList__c where ChatterGroupName__c='testgroup'];
List<CollaborationGroupMember> CollGroupMembers = new List<CollaborationGroupMember>();
for(DistributionList__c user : userID)
{
CollaborationGroupMember member = new CollaborationGroupMember();
member.MemberId = user.userID__C;
member.CollaborationGroupId = '0F94D0000004Ebd';
CollGroupMembers.add(member);
}
try
{
upsert CollGroupMembers;
}
catch(DMLException e)
{
system.debug('The group members werent added properly. Error: '+ e);
}
Fabio Fabiano
Does the DistributionList__c contains the Owner of the Group?
Anusha Gowravarapu
Yes it is
Fabio Fabiano
Good, so you need to remove the Owner from that list since the owner is already a member.
Anusha Gowravarapu
Thanks Fabio..!
I am thinking to do this way, If group.memberId=distributionlist.userId then skip insert other wise proceed for insert.
Appreciate your time.