+ Start a Discussion
John L.John L. 

request for help redirected here by Customer Support (salesforce.com Case Number 02343719)

I am receiving the following Apex Controller compile error message:
      Field is not writeable: Name.Name at line 17 column 38
Below is the code in question:

public class mySecondApexPageController { 

public String getMumbledpeg() { 
return ('Mumbledpeg'); 

public List<EmailTemplate> getTemplates() { 
System.debug('Entering getTemplates() in mySecondApexPageController'); 
List<EMailTemplate> Results = 
[ SELECT Id, EMailTemplate.Name, Subject, TemplateType, FolderId, 
FROM EmailTemplate 
WHERE IsActive = true 
ORDER BY Folder.Name, EMailTemplate.Name ]; 
for ( EMailTemplate i : Results ) { 
if (i.Folder.Name==null) { i.Folder.Name = 'Unfiled Email Template'; } 
return Results; 

My thinking was that the controller code did nothing to cause the field to be non-writeable, and there are not any programming facilities (that I know of) to make the field writable. BTW, I have also tried copying Results via the deepclone() method, but the cloned array is non-writable in this field also.  
That said, is there another methodology I can use to accomplish the desired goal of modifying the Results array contents prior to being returned by the getTemplates() method???
THanks in advance for your time and consideration. 
Well you can't change a field from a relationship, for one thing.  i.Folder.Name is a relationship.
John L.John L.

What if I were to  implement a GUI which provides function simular to that provided by salesforce.com?

My background in computer instructions, storage, cache, and disk storage suggests that many times things are displayed differently than they are stored. Your post suggests I can only display the information in the same format that it is stored. I can appreciate the source of the problem; I could use help with an appropriate solution. Much of the available documentation adds nothing regarding the source of the "problem", or a method of "solution". 

The existing salesforce.com implementation also suggests there is a possible solution, if in fact the existing user interfaces are  based on the services offered for customization. As a new solution provider, I appreciate any help you can provide to achieve that goal.

Thanks in advance for any help you can provide. 

My point is that, in your code, you are modifying something that is inherently unmodifiable.

i.Folder.Name = 'Unfiled Email Template';

That doesn't work. You could, however, do something like:

//don't do this inside a loop
Folder fld = [select Id from Folder where Name='Unfiled Email Template'];
//other code here...

//later on...
i.FolderId = fld.Id;
So: you can't set the Name field because it comes from a relationship. But you can directly set the FolderId field that drives that relationship.
The other problem being that what shows as Unfiled in the Salesforce front-end is actually stored as a null folder in the record.