+ Start a Discussion
Jim MontgomeryJim Montgomery 

invalid type error in apex class line 20 it is in bold and underlined

public class CaseAddedProducts {
    public List<WrapperClass> listWrapper {get;set;}
    public Boolean allBool {get;set;}
    public  String caseID {get;set;}
    public CaseAddedProducts() {
    String accountID = System.currentPageReference().getParameters().get('accountID');
    caseID = System.currentPagereference().getParameters().get('caseID'); 
        listWrapper = new List<WrapperClass>();
        List<product> listprd = [SELECT Id, productcode, productname,productfamily,erp__c
        FROM product where isactive = true];
        if(listprd.size() > 0) {
            for(product prd : listprd) {
                listWrapper.add(new WrapperClass(prd));
            }
        }
    }
    
    public class WrapperClass {
        public Boolean checked {get;set;}
        public Product prd {get;set;}
        public WrapperClass(product prd) {
            this.prd = prd;
        }
    }
    
     public PageReference save()
    {
    PageReference caserec = new PageReference('/'+caseID);
    caserec.setredirect(true);
    return caserec;
    }
    
    public void add() {
        List<product> listprdforAdd = new List<product>();
        List<WrapperClass> listTempWrapper = new List<WrapperClass>();
        for(WrapperClass w : listWrapper) {
            if(w.checked) {
                listprdforAdd.add(w.prd);
            } 
        }
        //insert listWrapper into case_cancelled_inventory__c
        List<case_added_inventory__c> listCaseAddedInventory = new List<case_Added_inventory__c>();
   for(aproduct objprd : listprdforAdd){
    case_added_inventory__c objCaseAddedInventory = new case_added_inventory__c();     
    objCaseAddedInventory.Product_Code__c = objprd.productcode;
    objCaseAddedInventory.Product_Name__c = objprd.productname;
        objCaseAddedInventory.case__c = caseID;
    listCaseAddedInventory.add(objCaseAddedInventory);   
   }
   if(listCaseAddedInventory != null && listCaseAddedInventory.size() > 0)
    insert listAddedCaseInventory;
  //insert listWrapper into case_cancelled_inventory__c Ends

 
    }
    
    public void selectAll() {
        if(allBool) {
            for(WrapperClass w : listWrapper) {
                w.checked = true;
            }
        } else {
            for(WrapperClass w : listWrapper) {
                w.checked = false;
            }
        }
    }
}
Best Answer chosen by Jim Montgomery
Raj VakatiRaj Vakati
Change Product to Product2 .. 

Salesforce Product Object API Name is Product2 

 
public class WrapperClass {
    public Boolean checked {get;set;}
    public Product2 prd {get;set;}
    public WrapperClass(Product2 prd) {
        this.prd = prd;
    }
}
 
public class CaseAddedProducts {
    public List<WrapperClass> listWrapper {get;set;}
    public Boolean allBool {get;set;}
    public  String caseID {get;set;}
    public CaseAddedProducts() {
        String accountID = System.currentPageReference().getParameters().get('accountID');
        caseID = System.currentPagereference().getParameters().get('caseID'); 
        listWrapper = new List<WrapperClass>();
        List<product2> listprd = [SELECT Id, productcode
                                 FROM product2 where isactive = true];
        if(listprd.size() > 0) {
            for(product2 prd : listprd) {
                listWrapper.add(new WrapperClass(prd));
            }
        }
    }
}

 

All Answers

Raj VakatiRaj Vakati
Change Product to Product2 .. 

Salesforce Product Object API Name is Product2 

 
public class WrapperClass {
    public Boolean checked {get;set;}
    public Product2 prd {get;set;}
    public WrapperClass(Product2 prd) {
        this.prd = prd;
    }
}
 
public class CaseAddedProducts {
    public List<WrapperClass> listWrapper {get;set;}
    public Boolean allBool {get;set;}
    public  String caseID {get;set;}
    public CaseAddedProducts() {
        String accountID = System.currentPageReference().getParameters().get('accountID');
        caseID = System.currentPagereference().getParameters().get('caseID'); 
        listWrapper = new List<WrapperClass>();
        List<product2> listprd = [SELECT Id, productcode
                                 FROM product2 where isactive = true];
        if(listprd.size() > 0) {
            for(product2 prd : listprd) {
                listWrapper.add(new WrapperClass(prd));
            }
        }
    }
}

 
This was selected as the best answer
Raj VakatiRaj Vakati
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_product2.htm
Jim MontgomeryJim Montgomery
Thank you!
I should have known better!