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
ekarthikekarthik 

Compile Error: Field is not writeable: in User add method

Hi

   I cretaed chatter groups. When i select chatter group , it needs to display all member in that group i need to display user imges

 

I get userid from for loop from that i need to get user image. 

In my case in a group , it may contain more than one user ,

 

so that i put in for loop and need to get and process so i have created User[] and add the results But i get error. I am unable to process further . Help Required.

 

 Compile Error: Field is not writeable: user.name

 

public List<User> chatGroupUser{get;set;}
public User[] usG{get;set;}
public List<CollaborationGroupMember> chatCollabGroup{get;set;}
public string chattergroupMember;
public string chatterArray{get;set;}
public List<string> chatterStringList{get;set;}

 

    

public void chatterMemberSelection(){
chattergroupMember = ApexPages.currentPage().getParameters().get('chatterGroup');

 

for(CollaborationGroupMember a:[select CollaborationGroupId,CollaborationRole, MemberId,NotificationFrequency from CollaborationGroupMember where CollaborationGroupId IN(select id from collaborationgroup where name=:chattergroupMember)])
{

  chatGroupUser =[SELECT Name,id FROM User where id=:a.MemberId];  

// error in the following line                

usG.add(new User(Name=chatGroupUser.name,id=chatGroupUser.id));

}

bob_buzzardbob_buzzard
You need to specify the firstname and lastname rather than the name - a bit like contacts. While there is a name field available via the API, its not mentioned in the fields reference guide:

http://login.salesforce.com/help/doc/en/salesforce_field_names_reference.pdf

I suspect you'll need to populate some more fields to add a user - profile for example. The fields I usually set up are:

alias
email
emailencodingkey
lastname
languagelocalekey
localesidkey
profileid
timezonesidkey
username
ekarthikekarthik

Hi

 

I used FirstName ,FullPhotoUrl and other specified fields  but unable to get proper answer

bob_buzzardbob_buzzard
What does "unable to get proper answer" mean - did you get an error, did the record fail to save?
ekarthikekarthik

Hi

  chatGroupUser =[SELECT FirstName FROM User where id=:a.MemberId];  

// error in the following line                

usG.add(new User(FirstName=chatGroupUser.FirstName));

 

 

same error occured 

bob_buzzardbob_buzzard
You got the field not writeable error?
ekarthikekarthik

yes

bob_buzzardbob_buzzard

I ran the following in my dev org which worked for me - no issue with writing to the fields:

 

Profile p = [select id from Profile where name='Chatter Free User'];

 User u = new User(alias = 'utest', email='Unit.Test@unittest.com',
                 emailencodingkey='UTF-8', firstName='First', lastname='Last', languagelocalekey='en_US',
                 localesidkey='en_US', profileid = p.id,
                 timezonesidkey='Europe/London', username='Unit.Test@unittest.com');

insert u;

 

ekarthikekarthik

I need to get values and to display in visual force page ,not inserting.

My requirement

selecting chatter group, then memberid i.e all member/user from that group based on that i need to display image 

My exact error is , for loop return 2 values(member) , i need to store in for loop then it needs to be accessed in visual force page.

 

When i add to User standard object , it produce error

User.add(new user(FirstName='x.FirstName'))

I hope you may understand the problem 

bob_buzzardbob_buzzard

Why are you doing User.add?  That would be trying to execute the add method of the user standard object 'class'.

 

Can you post the code that declares User?