0

Good afternoon,

I am hoping you can help me.

I am building a POC and i have hit a brick wall and really appreciate some help form the community.

Problem :

My visual force page doesn't show a tick box.

Ideal Solution :

"visual force" page below should show all the records in "materials" object (based on the criteria set in the apex class.

The visual force page should have the following fields displayed.

tick box materials Name Product items Quantity

and a save button

Apex Controller

public with sharing class testWrapper
{
    public List<Materials__c> Materials {get;set;} 
    public List<materialWrapper> materialWrapperList {get;set;} 

    public testWrapper()
    {   
        materialWrapperList = new List<materialWrapper>();
        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)
        {
         Materials_Junction__c temp ;
            if(obj.selectB == true)
            {
                temp = new Materials_Junction__c();
                temp.sales_and_marketing__c = 'a032000000VQaRT';
                temp.Materials__C= obj.recordId;
                temp.quantity__C = obj.quantity; 
                recordToInsert.add(temp);
            }
            //recordToInsert.add(temp); you are adding element outside the if condition that the reason for save button error
        }
        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;
        }
    }
}

Visual force page

    <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"> <!-- for loop of contact in Materials -->
                <apex:column value="{!MKT.selectB}"/>
                <apex:column value="{!MKT.name}"/>       
                <apex:column value="{!MKT.Product}"/>
                <apex:column value="{!MKT.Item}"/>
                <apex:column headerValue="Quantity">
                    <apex:inputText value="{!MKT.quantity}"/>
                </apex:column>

            </apex:pageBlockTable>

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

Really appreciate all the help i can get on this. looking forward to your response

  • Your question seems to be composed of multiple different questions. I'd really recommend you to split up the question into separate questions on this forum. That way it will be a lot easier for people to help you, and the answers provided will be much better reusable for others. – Guy Clairbois Sep 1 '16 at 14:07
  • @Guy - thanks for the hints / Tips its much appreciated. i will Split this question into three separate questions. Please see above updated question in relation to VF page – Masond3 Sep 1 '16 at 14:33
2

You are only outputting the value of the boolean and no input field.

Change

<apex:column value="{!MKT.selectB}"/>

to

<apex:column headerValue="[yourvaluehere]">
   <apex:inputCheckbox value="{!MKT.selectB}"/>
</apex:column>

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.