Reply
Regular Contributor
ekarthik
Posts: 47
0

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));

}

Moderator
bob_buzzard
Posts: 6,467

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

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
--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter

I don't respond to private messages/emails asking for help.


Take the Bob Buzzard Sobject Fields quiz.

Regular Contributor
ekarthik
Posts: 47
0

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

Hi

 

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

Moderator
bob_buzzard
Posts: 6,467
0

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

What does "unable to get proper answer" mean - did you get an error, did the record fail to save?
--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter

I don't respond to private messages/emails asking for help.


Take the Bob Buzzard Sobject Fields quiz.

Regular Contributor
ekarthik
Posts: 47
0

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

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 

Moderator
bob_buzzard
Posts: 6,467
0

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

You got the field not writeable error?
--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter

I don't respond to private messages/emails asking for help.


Take the Bob Buzzard Sobject Fields quiz.

Regular Contributor
ekarthik
Posts: 47
0

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

yes

Moderator
bob_buzzard
Posts: 6,467
0

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

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;

 

--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter

I don't respond to private messages/emails asking for help.


Take the Bob Buzzard Sobject Fields quiz.

Regular Contributor
ekarthik
Posts: 47
0

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

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 

Moderator
bob_buzzard
Posts: 6,467
0

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

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?

--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter

I don't respond to private messages/emails asking for help.


Take the Bob Buzzard Sobject Fields quiz.