Activity Forums Salesforce® Discussions How to invite people to user chatter via Apex code?

  • Abhinav

    Member
    May 27, 2016 at 1:20 pm

    Hi Piyush,

    You can do this in Apex by inserting a CollaborationInvitation.

     

    String emailAddress = '[email protected]';
    CollaborationGroup chatterGroup = [SELECT Id
    FROM CollaborationGroup
    WHERE Name='All acme.com'
    LIMIT 1];
    CollaborationInvitation inv = New CollaborationInvitation();
    inv.SharedEntityId = chatterGroup.id;
    inv.InvitedUserEmail = emailAddress;

    try {
    Insert inv;
    } catch(DMLException e){
    System.debug('There was an error with the invite: '+e);
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos