function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BMT-DavidBMT-David 

Is it possible to create a Chatter Free user from a Contact Button?

This is Non-Profit where we are trying to integrate the community of volunteers through Chatter Free user accounts.

 

The first step would be creating a button on Volunteer Contact Records creating Chatter Free user accounts for each volunteer, using the contact email.

 

I have succeeded creating a Chatter Free account through apex data loader.

 

I am looking for limitations on this matter... but as wierd as it looks, I haven't found any.

 

Any suggestions?

 

Many thanks.

 

David.

Best Answer chosen by Admin (Salesforce Developers) 
Jia HuJia Hu

Try the code below,

 

VF page:

<apex:page standardController="Contact" extensions="ChatterFree" action="addUser">
</apex:page>

 

Apex class:

public class ChatterFree {

private final Contact acct;

public ChatterFree(ApexPages.StandardController stdController) {
this.acct = (Contact)stdController.getRecord();
}

public PageReference addUser() {
if(acct.id != null) {
Contact acc = [Select Lastname, Email From Contact Where Id =: acct.id];
User auser = new User();
auser.Lastname = acc.Lastname;
auser.Email = acc.Email;
auser.Username = 'Chatter.Free@XXX';
auser.Alias = 'C.FX';
auser.CommunityNickname = 'Chatter.FreeX';
auser.ProfileId = '00e1000XXXXX';  //Standard Chatter Free Profile Id
auser.LocaleSidKey = 'ja_JP';
auser.EmailEncodingKey = 'ISO-2022-JP';
auser.LanguageLocaleKey = 'en_US';
auser.TimeZoneSidKey = 'Asia/Tokyo';


insert auser;
}
return null;
}

}

All Answers

Jia HuJia Hu

Try the code below,

 

VF page:

<apex:page standardController="Contact" extensions="ChatterFree" action="addUser">
</apex:page>

 

Apex class:

public class ChatterFree {

private final Contact acct;

public ChatterFree(ApexPages.StandardController stdController) {
this.acct = (Contact)stdController.getRecord();
}

public PageReference addUser() {
if(acct.id != null) {
Contact acc = [Select Lastname, Email From Contact Where Id =: acct.id];
User auser = new User();
auser.Lastname = acc.Lastname;
auser.Email = acc.Email;
auser.Username = 'Chatter.Free@XXX';
auser.Alias = 'C.FX';
auser.CommunityNickname = 'Chatter.FreeX';
auser.ProfileId = '00e1000XXXXX';  //Standard Chatter Free Profile Id
auser.LocaleSidKey = 'ja_JP';
auser.EmailEncodingKey = 'ISO-2022-JP';
auser.LanguageLocaleKey = 'en_US';
auser.TimeZoneSidKey = 'Asia/Tokyo';


insert auser;
}
return null;
}

}

This was selected as the best answer
BMT-DavidBMT-David

Many Thanks. That was a full response. 

Anthony DoyleAnthony Doyle
Can anyone help with identifying a test class for this code. I'm new to this and struggling to contruct the right test class for the above code example.
If anyone can point me in the right direction that would really help me out.