How can I save list values in my controller to fields in my object? I keep getting the error "Initial term of field expression must be a concrete SObject: List". I can get the individual values in a visualforce page, so I can't understand why I can't get them in my controller when I try to save. Thank you in advance for any help/ guidance.
Please see the following for some background on the problem...
In my controller I have a JSON string which is parsed, and it's values are added into a list (please see below).
JSON String "this.studyJson"
{"study":{"moleculeDescription":"RONTfdasZUMAB","protocolTitle":"Ifw","protocolNumber":"GA0fda6","studyName":"n alpha ie II LCM Option","therapeuticArea":"INFRuafnda&BONE","startDate":"2009-03-25","endDate":"2013-08-22"}}
Controller, Study list
List<StudyWrapper> Study = new List<StudyWrapper>();
public List<StudyWrapper> getStudy(){
JSONParser parser = JSON.createParser(this.studyJson);
while(parser.nextToken() != null){
while(parser.nextToken()!= null){
if(parser.getCurrentToken()==JSONToken.START_OBJECT){
StudyWrapper s = (StudyWrapper)parser.readValueAs(StudyWrapper.class);
Study.add(s);
}
}
}
return Study;
}
class StudyWrapper{
public String moleculeDescription {get; set;}
public String protocolTitle {get; set;}
public String protocolNumber {get; set;}
public String studyName {get; set;}
public String therapeuticArea {get; set;}
public String startDate {get; set;}
public String endDate {get; set;}
}
On the visualforce page I can call the list values and show them (please see below)
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!Study}" var="s">
<apex:column headerValue="Protocol Title" value="{!s.protocolTitle}"/>
<apex:column headerValue="Molecule Description" value="{!s.moleculeDescription}"/>
<apex:column headerValue="Protocol Nickname" value="{!s.studyName}"/>
<apex:column headerValue="Therapeutic Area" value="{!s.therapeuticArea}"/>
<apex:column headerValue="Start Date" value="{!s.startDate}"/>
<apex:column headerValue="End Date" value="{!s.endDate}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
Just like on the visualforce page, what I want to do is get the list values and save them to the object's record fields when I hit the save button. Something like...
public PageReference save(){
Object__c.field__c = Study.studyname;
...
}
However, when I do this I get the inevitable error "Initial term of field expression must be a concrete SObject: List". In my controller, how can I get the values from the list and save them to a field on my object?