0

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;
        }
    }
}

2 Answers 2

0

Line 36 :

recordToInsert.add(obj);

will need correction as below:

 for(materialWrapper obj : materialWrapperList)
        {
         Materials_Junction__c temp ;
            if(obj.selectB == true)
            {
                temp = new Materials_Junction__c();
                temp.sales_and_marketing__c = '01I20000000rV6V';
                temp.Materials__C= obj.recordId;
                temp.quantity__C = obj.quantity; 
            }
            recordToInsert.add(temp);
        }

recordToInsert is declared as list of Materials_Junction__c and you are trying to add an object of materialWrapper into it. So above mentioned correction would be required.

1
  • HI Mukesh, That allows me to save the class :) whoohoo.
    – Masond3
    Commented Aug 30, 2016 at 13:24
0

This is my code for my visual force page. But i am getting the following error "Error: Unknown property 'testWrapper.materialWrapper.select'" any ideas why based on the Apex Class above ?

<apex:page controller="testWrapper">
<apex:form >
    <apex:pageBlock title="Select Product">

        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlockButtons>

        <apex:pageBlockTable value="{!materialWrapperList}" var="MKT"> 
            <apex:column value="{!MKT.select}"/>
            <apex:column value="{!MKT.name}"/>       
            <apex:column value="{!MKT.Product}"/>
            <apex:column value="{!MKT.Item}"/>
            <apex:column headerValue="Quanity">
                <apex:inputField value="{!MKT.Quanity}"/>
            </apex:column>

        </apex:pageBlockTable>

    </apex:pageBlock>
</apex:form>

You must log in to answer this question.

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