0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

フロー内のグループメンバーからメールアドレスを取得する方法

Last updated at Posted at 2022-06-27

なかなか、うまく行かないですね。

How to get the email adress from groupmember within the flow
追記: 何とこのコードを回答として添付し、ロールを確認するように促したところベストアンサーをつけてくれましたが、何と速攻で質問を丸ごと削除して逃亡されました。自分が欲しい回答を得たらささっと消して無かったことにするんですね。

そこで、Apexで書いてみたら... なんとうまく行かないです。何故だろう? ロールをグループの中に記述した時にうまくいってない。
よく見るとロールってGroupMemberオブジェクトにないんですねぇ。どこにあるかと言えばGroupオブジェクトのRelatedIdというフィールド...
見事に騙されました。

最終的には以下のようなApexコードで実現できましたが、これをフローにする気にはなれません。

public class GroupMemberTest {

    public static Set<String> getAddoress(Id GroupId) {
    
        Set<String> AddoressSet = new Set<String>();
        Set<String> UserIdSet = new Set<String>();
        Set<String> RoleIdSet = new Set<String>();
        
        List<GroupMember> Loop1 = [SELECT Id,UserOrGroupId,Group.RelatedId FROM GroupMember WHERE GroupId =: GroupId];
        system.debug(Logginglevel.INFO,' ===== Loop1 ====== '+Loop1 );
        String MyId;
        Set<String> GroupSet2 = new Set<String>();
        for ( GroupMember g : Loop1  ){
            MyId = g.UserOrGroupId;
            if (myId.left(3) == '005') {
                UserIdSet.add(g.UserOrGroupId);
            } else {
                GroupSet2.add(g.UserOrGroupId);                
            }
            system.debug(Logginglevel.INFO,' ===== g.Group.RelatedId ====== '+g.Group.RelatedId );
            if (g.Group.RelatedId != null ) RoleIdSet.add(g.Group.RelatedId);
        }
        system.debug(Logginglevel.INFO,' ===== GroupSet2 ====== '+GroupSet2 );
        system.debug(Logginglevel.INFO,' ===== RoleIdSet ====== '+RoleIdSet );
        Set<String> GroupSet3 = new Set<String>();
        if (GroupSet2.size()> 0) {
            List<GroupMember> Loop2 = [SELECT Id,UserOrGroupId,Group.RelatedId FROM GroupMember WHERE GroupId =: GroupSet2];            
            
            for ( GroupMember g : Loop2  ){
                MyId = g.UserOrGroupId;
                if (myId.left(3) == '005') {
                    UserIdSet.add(g.UserOrGroupId);
                } else {
                    GroupSet3.add(g.UserOrGroupId);                
                }
                if (g.Group.RelatedId != null ) RoleIdSet.add(g.Group.RelatedId);
            }
        }
        system.debug(Logginglevel.INFO,' ===== GroupSet3 ====== '+GroupSet3 );
        Set<String> GroupSet4 = new Set<String>();
        if (GroupSet3.size()> 0) {
            List<GroupMember> Loop3 = [SELECT Id,UserOrGroupId,Group.RelatedId FROM GroupMember WHERE GroupId =: GroupSet3];            
            
            for ( GroupMember g : Loop3  ){
                MyId = g.UserOrGroupId;
                if (myId.left(3) == '005') {
                    UserIdSet.add(g.UserOrGroupId);
                } else {
                    GroupSet4.add(g.UserOrGroupId);                
                }
                if (g.Group.RelatedId != null ) RoleIdSet.add(g.Group.RelatedId);
            }
        }

        system.debug(Logginglevel.INFO,' ===== UserIdSet ====== '+UserIdSet );
        if( UserIdSet.size() >0 ){
            List<User> userList = [SELECT Id,email FROM User WHERE Id =: UserIdSet] ;
            
            IF(userList.size() >0 ) {
                for (User u : userList ){
                    AddoressSet.add(u.email);
                    system.debug(Logginglevel.INFO,' ===== vvvv ====== '+ u.email );
                }
            }
        }
        
        system.debug(Logginglevel.INFO,' ===== RoleIdSet ====== '+RoleIdSet );
        if( RoleIdSet.size() >0 ){
            List<User> userList2 = [SELECT Id,email FROM User WHERE UserRoleId =: RoleIdSet] ;
            
            IF(userList2.size() >0 ) {
                for (User u : userList2 ){
                    AddoressSet.add(u.email);
                    system.debug(Logginglevel.INFO,' ===== vvv2 ====== '+ u.email );
                }
            }
        }
        
    
        return AddoressSet;
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?