I am using compareTo sort implementation. After sorting the wrapper I would like to get back a list of sObject. Is there a way to clone them off directly without hardcoding all field names?
Code:
public class OpportunityWrapper implements Comparable {
public Electricity_Meter__c oppy;
public OpportunityWrapper(Electricity_Meter__c op) {
oppy = op;
}
public Integer compareTo(Object compareTo) {
OpportunityWrapper compareToOppy = (OpportunityWrapper)compareTo;
Integer returnValue = 0;
if (oppy.Meter_Details__c > compareToOppy.oppy.Meter_Details__c ) {
returnValue = 1;
} else if (oppy.Meter_Details__c < compareToOppy.oppy.Meter_Details__c ) {
returnValue = -1;
}
return returnValue;
}
}
public inputnulls(ApexPages.StandardSetController controller) {
mycon = controller;
Selectedmeters = mycon.getSelected();
OpportunityWrapper[] oppyList = new List<OpportunityWrapper>();
for (Electricity_Meter__c met: selectedmeters ){
oppyList.add( new OpportunityWrapper(met ));
}
oppyList.sort();
for (OpportunityWrapper met: oppyList){
selectedmeters2.add(new Electricity_Meter__c (met));
}
selectedmeters = selectedmeters2;
}
Currently I get SObject constructor must use name=value pairs
error when adding sObjects back to collection.
Help please.