• Chirag Sapkota 5
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 5
    Replies
Hello All,
Wanting to write Apex Code (Both Class and Trigger) to auto assign Users who are assign to Permission Set (Test) to a Community Chatter group. 
I Manage to assign to a community chatter group based on Profile but not Based on Permission set. Could you please help?

Below is my code based on Profile. 
trigger User_trigger on User (after insert, before insert, after update, before update) {

    if ( Trigger.isInsert ) {   

        if ( Trigger.isAfter ) {

            List<id> UserIds = new List<id>();

            for ( user u: Trigger.new ) {

                if ( u.Profile.UserLicense.Name <> 'Customer Community Plus' ) {

                    UserIds.add(u.id);

                }                

            }

            if ( UserIds.size() > 0 ) {

                asyncApex.addUserToGroup(UserIds); 

            }          

        }

    }

global class AsyncApex {

    @future

    public static void AddUserToGroup(List<ID> UserIds) {

        try {

            List<CollaborationGroupMember> cgm = new List<CollaborationGroupMember>();                     

            Id cgID = [ Select Id

                        FROM CollaborationGroup

                        WHERE Name = 'All Clients Groups' LIMIT 1 ].ID;

           for ( Id UserId : UserIds ) {

               cgm.add(new CollaborationGroupMember (CollaborationGroupId = cgID, MemberId = UserId));  

           }

           insert cgm;

        } catch (QueryException qe) {

            System.debug('QueryException in AsyncApex.AddUserToGroup is :' + qe); 

        } catch (Exception ex) {

            System.debug('Exception in AsyncApex.AddUserToGroup is :' + ex);

        }   

    }

}
 
Hello Everyone, 
Is it Possible to auto assign data.com licenses with 300 limit to newly created  users? If yes, How can it be done? Triggers? Process builder? 
Thank you for your help
How to Write Test Class for Scheduled Apex Class? I manage to write Schedule class but I need help to write test class for this. I am learning Apex code. I would be grateful if someone can help me out. 

public class DeactivateInactiveUsers implements Schedulable {
    public void execute(SchedulableContext context) {
        User[] selectedUsers = [SELECT Id FROM User WHERE IsActive = TRUE AND Id NOT IN (SELECT UserId FROM LoginHistory WHERE LoginTime = LAST_N_DAYS:30)];
        for(User record: selectedUsers) {
            record.IsActive = false;
        }
        Database.update(selectedUsers, false);
    }
}
Hello,
I need help to write a a trigger to auto populate a Permission Sets on All Active Users. I need to auto populate one permission set to every active users This should happend when a user is created or user record is updated. Could you please share your ideas or code? 
Thank you in advance
Hello developer gurus,
I have create a VF page form to capture leads for our community users. The form is StandradController "Lead" and TabStyle "Lead". I would like this form to be more advance. Below is the fuctionality I would like to create. I am newbee to the Apex.
1) Whenever a user (specially, Community User) access this form, the form should auto populate the User's FirstName, LastName, Email, Comapny, Account (info will be in Contact or User detail record)

Thank you in advance. Again, I would appreciate if you could provide me some codes 
How to Write Test Class for Scheduled Apex Class? I manage to write Schedule class but I need help to write test class for this. I am learning Apex code. I would be grateful if someone can help me out. 

public class DeactivateInactiveUsers implements Schedulable {
    public void execute(SchedulableContext context) {
        User[] selectedUsers = [SELECT Id FROM User WHERE IsActive = TRUE AND Id NOT IN (SELECT UserId FROM LoginHistory WHERE LoginTime = LAST_N_DAYS:30)];
        for(User record: selectedUsers) {
            record.IsActive = false;
        }
        Database.update(selectedUsers, false);
    }
}
Hello developer gurus,
I have create a VF page form to capture leads for our community users. The form is StandradController "Lead" and TabStyle "Lead". I would like this form to be more advance. Below is the fuctionality I would like to create. I am newbee to the Apex.
1) Whenever a user (specially, Community User) access this form, the form should auto populate the User's FirstName, LastName, Email, Comapny, Account (info will be in Contact or User detail record)

Thank you in advance. Again, I would appreciate if you could provide me some codes