+ Start a Discussion
MMA_FORCEMMA_FORCE 

Error: Compile Error: Field is not writeable???

Hi all:

    I am not trying to write the record I am trying to spit it out on a repeat tag in a report in Visual Force...

Here is my Apex:

 

public List<Subject_Area_RQ__c> queryResults{ get; set; } // Get all the data in one query AggregateResult[] groupedResults = [SELECT On_Track_Subject_Area__c, GL_Term_Value__c, Grade_Level__c, SUM(NLNS__CR_Min_Pass__c) minpass FROM Subject_Area_RQ__c GROUP BY CUBE (On_Track_Subject_Area__c, GL_Term_Value__c, Grade_Level__c) ]; queryResults = new List<Subject_Area_RQ__c>(); // Loop through the query for (AggregateResult ar : groupedResults) { Subject_Area_RQ__c myObject=new Subject_Area_RQ__c(); myObject.On_Track_Subject_Area__c = String.valueOf(ar.get('On_Track_Subject_Area__c')); //MY ERROR IS HERE myObject.GL_Term_Value__c = (Decimal)ar.get('GL_Term_Value__c'); queryResults.add(myObject); }

 Is there any way to get passed this error???

Thanks

 

 

Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae

You are "writing" to the record, at least in memory, since you create a new "Subject_Area_RQ__c" that you are trying to populate the GL_Term_Value__c field of with your AggregateResult data.

 

Are you just using that record as a holder for displaying that field, or do you need other fiels actually from that object?  If you don't, I would consider using a wrapper class object instead, you can have it's member "fields" with the proper format, and won't have the overhead in memory of instantiating a full record of the Subject_Area_RQ__c.

 

Something like this:

 

 

public class ARHolder { public String on_Track {get; set;} public Decimal GL_Term {get; set;} public ARHolder(){ } } public List<ARHolder> queryResults{ get; set; } // Get all the data in one query AggregateResult[] groupedResults = [SELECT On_Track_Subject_Area__c, GL_Term_Value__c, Grade_Level__c, SUM(NLNS__CR_Min_Pass__c) minpass FROM Subject_Area_RQ__c GROUP BY CUBE (On_Track_Subject_Area__c, GL_Term_Value__c, Grade_Level__c) ]; queryResults = new List<ARHolder>(); // Loop through the query for (AggregateResult ar : groupedResults) { ARHolder myObject=new ARHolder(); myObject.on_Track = String.valueOf(ar.get('On_Track_Subject_Area__c')); myObject.GL_Term = (Decimal)ar.get('GL_Term_Value__c'); queryResults.add(myObject); }

 

 

 

All Answers

JimRaeJimRae

You are "writing" to the record, at least in memory, since you create a new "Subject_Area_RQ__c" that you are trying to populate the GL_Term_Value__c field of with your AggregateResult data.

 

Are you just using that record as a holder for displaying that field, or do you need other fiels actually from that object?  If you don't, I would consider using a wrapper class object instead, you can have it's member "fields" with the proper format, and won't have the overhead in memory of instantiating a full record of the Subject_Area_RQ__c.

 

Something like this:

 

 

public class ARHolder { public String on_Track {get; set;} public Decimal GL_Term {get; set;} public ARHolder(){ } } public List<ARHolder> queryResults{ get; set; } // Get all the data in one query AggregateResult[] groupedResults = [SELECT On_Track_Subject_Area__c, GL_Term_Value__c, Grade_Level__c, SUM(NLNS__CR_Min_Pass__c) minpass FROM Subject_Area_RQ__c GROUP BY CUBE (On_Track_Subject_Area__c, GL_Term_Value__c, Grade_Level__c) ]; queryResults = new List<ARHolder>(); // Loop through the query for (AggregateResult ar : groupedResults) { ARHolder myObject=new ARHolder(); myObject.on_Track = String.valueOf(ar.get('On_Track_Subject_Area__c')); myObject.GL_Term = (Decimal)ar.get('GL_Term_Value__c'); queryResults.add(myObject); }

 

 

 

This was selected as the best answer
MMA_FORCEMMA_FORCE

Great thanks Jim...

Yeah I am trying to create a Matrix view Report in VF...

Group By Cube is the method to use but do not know how to yet...

 

Like I need Subject going down and Term going across then the Sum of MinPass going underneath the term...Etc..

 

But question I had was what is a wrapper class and is there any documentation on it so I can learn how to use it?

 

Thanks

JimRaeJimRae

In the sample code I posted, I created a wrapper class called ARHolder in your code.

 

Here is a great tutorial on creating a wrapper class from the Wiki:

 

http://wiki.developerforce.com/index.php/Wrapper_Class

 

Think of it this way, a wrapper class is kind of like creating a temp table, but can hold anything from the system, including primatives and sObjects and even lists and maps of these items.  They are great for creating a temporary list of elements in a way that they can be exposed to a Visualforce page.

 

My guess for your requirement, you will need to create a list of items in such a way that each of them has their subject as the first  element, then the terms as the next x number of elements.

Depending on how dynamic the report is, you could manually create the header in your VF page, and then you would only need to build the data for the report.  Or, consider generating the header "record" outside of the data list.

Don't know too much about the Group by Cube, I hope you post what you figure out back in this thread so I can see what you came up with!

MMA_FORCEMMA_FORCE

I will definetly reply back with my solution once I figure it out...

GROUP BY Cube in the documents is told that it can do cross-tabular tables which I still have not found out a way to do it...

But I will be working on that today... I'll keep this updated...

Thank you for helping me out...