1

Here i am trying to get the userid if i get userid, i've to check if that userid is present in an public group and perform some function. but it's showing some error. can anyone please help me out.

sforce.connection.sessionId = "{!$Api.Session_ID}}";
var user = sforce.connection.getUserInfo();
alert(user);

Error that i am getting. enter image description here

2
  • 1
    try {!$user.Id} Mar 8 '16 at 4:52
  • ya i got the user id, one more thing how i can check whether userid is present in an public group @Tushar Sharma
    – RAT__
    Mar 8 '16 at 5:01
3

You can use {!$User.Id} to directly get the current user id using global variable.

After that you can perform your next operations.

For your current case try to refresh the page and then try it again. sometimes when we don't refresh the window for long time then session.Id is expired. may be that the case.

Updates

List<GroupMember> lstgroupmember = [Select UserOrGroupId, Group.Type, GroupId 
                                      From GroupMember g 
                                     where Group.type = 'Regular' 
                                       AND UserOrGroupId='YourUserID' LIMIT 1]; 
if(lstgroupmember.size()>0){ 
        //fun 
}else{ 
     // keep quiet 
}
3
  • ya i got the user id, one more thing how i can check whether userid is present in an public group using javascript @Tushar Sharma
    – RAT__
    Mar 8 '16 at 5:10
  • @RAT__ is this chatter group or normal group? Mar 8 '16 at 5:14
  • 2
    List<GroupMember> lstgroupmember = [Select UserOrGroupId, Group.Type, GroupId From GroupMember g where Group.type = 'Regular' AND UserOrGroupId='YourUserID' LIMIT 1]; if(lstgroupmember.size()>0){ //fun }else{ // keep quiet } use this query Mar 8 '16 at 5:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.