I created following Wrapperclass to sort quote based on ceratedDate

global class QuoteCreateDateSortWrapper implements Comparable {

    public Quote quo;

    public QuoteCreateDateSortWrapper(Quote qu) {
        quo = qu;

    //Compare the quotes based on CreatedDate
    global Integer compareTo(Object compareTo) {
        //Cast argument to QuoteCreateDateSortWrapper
        QuoteCreateDateSortWrapper compareToQuo = (QuoteCreateDateSortWrapper) compareTO;

        //The return value of 0 indicates that both elements are equal.
        Integer returnValue = 0;
        if(Quo.CreatedDate > compareToQuo.Quo.CreatedDate){
            //Set the return value to positive value.
            returnValue = 1;
        }else if (Quo.CreatedDate < compareToQuo.Quo.CreatedDate) {
            //Set the return value to a negative value.
            returnValue = -1;

        return returnValue;


I created following quoteList to for different validation.

List<Quote> quoteList = new List<Quote>([SELECT Id,IsSyncing,CreatedDate FROM Quote WHERE OpportunityId = :opp.Id]); 

now I am trying to copy the above quoteList to wrapperclass list, but I am getting error.

List<QuoteCreateDateSortWrapper> quoListW = new List<QuoteCreateDateSortWrapper>();

Could you please help me to understand what I am doing wrong?


You need to "wrap" each record individually.

List<Quote> quoteList = [SELECT Id,IsSyncing,CreatedDate FROM Quote WHERE OpportunityId = :opp.Id]; 
List<QuoteCreateDateSortWrapper> quoListW = new List<QuoteCreateDateSortWrapper>();
for(Quote record: quoteList) {
  quoListW.add(new QuoteCreateDateSortWrapper(record));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.