0

I am creating a one list in which i am adding list of another item but it is giving me error Incompatible element type List for collection of Offer__c at line 25 column 10 I am Sharing my code with you.

public String sSliderField { get; set; }
    public String s { get; set; }
    public Opportunity objOpportunity {get;set;} 
   // public List<Opportunity > opp{get;set;}
   public List<Offer__c> lstoffer{get;set;} 
   public Offer__c off{get;set;}


    public PricingOptionCalculatorCtrl(ApexPages.StandardController controller) {
      String oid = controller.getRecord().id;

      lstoffer=new List<Offer__c>();

      objOpportunity =new Opportunity();
    // opp=new List<Opportunity>([select id,name,(select id,name,Opportunity__c,X15_of_Gross__c,Additional_Material_Needed__c,Avg_Monthly_Gross__c,AVG_Monthly_VMC__c,Cash_Wanted__c,Offer_Type__c,Reduced_UW_V_MC__c,WH_Withhold__c from Offers__r)from Opportunity where id=:oid ]);
      objOpportunity =[select id,name,Term__c,Monthly_Gross_Sales__c,Adjusted_Monthly_Gross_Sale__c,Hybrid_Holdback__c,Gross__c,Hybrid_Amount_Payment__c,Adjusted_Monthly_CC_Sale__c,Holdback__c,Credit_Card_Processing_Volume_LM__c,Deal_Length__c,Max_Monthly_Payment__c,Daily_Payment__c,Factor__c,Factor_Rate__c,Funding_Amount__c,Payback_Amount__c,Program_Type__c,ForecastCategoryName,Gross_Annual_Sales__c,Max_Deal_Size__c,Amount_Requested__c from Opportunity where id =:oid];

     List<Offer__c> lstTemp = new List<Offer__c>();
     lstTemp=[select id,name,Opportunity__c,X15_of_Gross__c,Additional_Material_Needed__c,Avg_Monthly_Gross__c,AVG_Monthly_VMC__c,Cash_Wanted__c,Offer_Type__c,Reduced_UW_V_MC__c,WH_Withhold__c from Offer__c where Opportunity__c=:oid];

     if(lstTemp!=null && lstTemp.size>0)
     { 
         lstoffer.add(lsttemp);
     }
    system.debug('---Slider Range-'+s );
    }

     public void save(){        
        //update d;      
     }

     public Pagereference addoffer()
     {
         off=new Offer__c();
        lstoffer.add(off);
         return null;
     }
}

2 Answers 2

3

The variable lstoffer is a list of Offer__c sObject records. The variable lstTemp is also a list of Offer__c sObject records. If you want to add all elements from one list to another you need to use the addAll(fromList) method:

lstoffer.addAll(lstTemp);
0

What you have done is declared a list of Offer__c but your are trying to add list rather than the object(offer__c). You need to use something like below, if you want to add list to a list

lstOffer.addall

2
  • god.. i have difficulty in writing code here...
    – Goki
    Commented Jul 24, 2015 at 6:58
  • write the code, select it and then click the {} icon Commented Jul 24, 2015 at 12:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .