I am hoping you can help me.
I am getting the following error "Compile Error: Incompatible element type testWrapper.materialWrapper for collection of Materials_Junction__c at line 36 column 13".
This is my Controller.
public with sharing class testWrapper
{
public List<Materials__c> Materials {get;set;}
public List<materialWrapper> materialWrapperList {get;set;}
public testWrapper()
{
Materials = [select ID,name,Product__c, Item__c,Quanity__c, Active__c from Materials__c where Active__c =true limit 10];
for(Materials__c obj : Materials)
{
materialWrapper tempObj= new materialWrapper();
tempObj.recordId = obj.id;
tempObj.name = obj.name;
tempObj.product = obj.Product__c;
tempObj.item = obj.Item__c;
tempObj.quantity = obj.Quanity__c;
tempObj.selectB = false;
materialWrapperList.add(tempObj);
}
}
//save method
public void save()
{
list<Materials_Junction__c> recordToInsert = new list<Materials_Junction__c>();
for(materialWrapper obj : materialWrapperList)
{
if(obj.selectB == true)
{
Materials_Junction__c temp = new Materials_Junction__c();
temp.sales_and_marketing__c = '01I20000000rV6V';
temp.Materials__C= obj.recordId;
temp.quantity__C = obj.quantity;
}
recordToInsert.add(obj);
}
insert recordToInsert;
}
public class materialWrapper
{
public string recordId {get; set;}
public string name {get; set;}
public string product {get; set;}
public string item {get; set;}
public Decimal quantity {get; set;}
public boolean selectB {get; set;}
public void materialWrapper()
{
recordId = '';
name = '';
product = '';
item = '';
quantity = 0.0;
selectB = false;
}
}
}