I do not understand why my values keep getting switched. I think it assigns the value of the first input value box to the first item added and the value fields are not in order of the objects.
<apex:inputCheckbox value="{!...}" rendered="{!contains(...)}">
</apex:inputCheckbox>
<apex:SelectList rendered="{!contains(...)}" size="1" value="{!...}">
<apex:SelectOptions value="{!picklist}" />
</apex:SelectList>
</apex:outputPanel>
//
Sample Output when initially added
Name Value
Object2 55 // Added Second datatype: String
Object1 33 //Added First datatype: String
Output after save button is clicked once
Object1 33
Object2 55
Output after clicking the save button again, the values will keep switching.
Object1 55
Object2 33
//
Object are stored in a Map which is changed to a list using map.value() for displaying:
The list is of the subclass objects from below. public class AccountDetailInstance {
public List<SelectOption> pickList {get; set;}
public String textValue {get; set;}
}
The list is saved into the salesforce object by duplicating the values and the list gets regenerated based off of the salesforce objects that were saved everytime.
//This method loads all the instances for a page
private void loadInstances() {
instancesMap = new Map<Id, sObject>([SELECT Id, Name, Value__c, Type__C, content__c FROM sObject);
//debug account ...
for (sObject items: instancesMap.values()) {
subClassObject subItem = new subClassObject(items.Name);
subItem.Id = Item.Id;
if (items.Type__c.equals('Picklist') || adi.Type__c.equals('Multipicklist')) {
subItem.pickList = createLists(content__c); //generates selection list based on values
}
if (item.Type__c.equals('String'))
{
subItem.value = Item.value__c'
}
}
}
// This method adds an instance from a selection list which the user chooses in the UI
public void addItem() {
for (String id : selectedInstances) {
//creates new sublcass object and adds it to the instanceMap
instanceMap.put(subItem.Name, subItem);
}
}
}
public PageReference save() {
Account account = (Account) controller.getRecord();
List<sObject> sObjectList = new List<sObject>();
subClass subItem;
for (subClass subItem : InstanceMap.Values()) {
//Set all the fields for the sObject
sObjectList.add(subItem);
}
upsert detailInstanceList;
return ApexPages.currentPage();
}