• Desi FunSun
  • NEWBIE
  • -1 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
Hi,

I have a pretty simple VF page that allows a user to create 1 or more records of a custom object that has master-detail relationships to the Account and Contact objects. The user can enter a Type value for the custom object, but each related Contact can only have 1 record of each Type value. Type values on the custom object can be repeated on different Contacts.  

What I'm trying to do is highlight the Type values the user is choosing to create, that already exist for that Contact so they can then change the value or remove it. Is there a way to accomplish this?

VF Page
<apex:page Controller="NewRecController">
<apex:form >
    <apex:pageBlock >
        <apex:pageMessages id="showMsg"/>
        <apex:pageBlockTable value="{!listRecType}" var="rec1" >
            <apex:column headerValue="Record Type">
                <apex:inputField value="{!rec1.Rec_Type__c}"/>
            </apex:column>
        </apex:pageBlockTable>
        <apex:pageBlockButtons >
            <apex:commandButton value="Add Another Record Type" action="{!addRecType}"/>
            <apex:commandButton value="Save All Record Types" action="{!saveType}" reRender="showMsg"/>
        </apex:pageBlockButtons>
        </apex:pageBlock>
</apex:form>
</apex:page>

Controller
public class NewRecController {

    Record_Type__c rec = new Record_Type__c();
    public list<Record_Type__c> listRecType{ get; set; }

    Id acctId;
    Id contId;
    String RecTypes;
    
//    Constructor 

	public NewRecController() { 
        acctId = ApexPages.currentPage().getParameters().get('acctId');
        contId = ApexPages.currentPage().getParameters().get('contId');
        RecTypes = ApexPages.currentPage().getParameters().get('acctTypes');
        
        rec.Account__c = acctId;
        rec.Contact__c = contId;
system.debug('@@@@@@ - AccountTypes: '+acctTypes);

        listRecType = new list<Record_Type__c>();
        listRecType.add(rec);
	} 

    Public void addRecType() {
        Record_Type__c rec1 = new Record_Type__c();
    		rec1.Contact__c = contId;
        	rec1.Account__c = acctId;
system.debug('@@@@@@ - AccountTypes: '+acctTypes);
system.debug('@@@@@@ - Record Type: '+rec1);
		listRecType.add(rec1);
        }
            
    public PageReference saveType() {
    	insert listRecType;
    return Page.NewRecType;
    }
}


 
Hi,
I am having trouble with my Visualforce page and Apex Class. Everything seems to be fine apart from the error Unknown Property 'NFOSDisplayDivisions2Controller.Division_Space2__c'. I can't seem to figure out what is going on, could someone please help me out. Thank you.

Apex Class:
public with sharing class NFOSDisplayDivisions2Controller {
    
    public List<DivisionWrapper> listDivisionWrapper{get;set;}
    public List<Division_Space2__c> selectedDivisions{get;set;}

    public NFOSDisplayDivisions2Controller ()
    {
            listDivisionWrapper = new List<DivisionWrapper>();
            searchRecord();
    }
    
    public void searchRecord()
    {
        listDivisionWrapper.clear();
            for(Division_Space2__c a: [select Id, Name,Number_of_Competitors__c, Availability__c, RecordTypeID ,Active__c from Division_Space2__c limit 30]) 
            {
                listDivisionWrapper.add(new DivisionWrapper(a));
            }
    }

    public void processSelected() 
    {
        selectedDivisions = new List<Division_Space2__c>();
        selectedDivisions.clear();
        for(DivisionWrapper wrapDivisionObj : listDivisionWrapper) 
        {
            if(wrapDivisionObj.selected == true) 
            {
                selectedDivisions.add(wrapDivisionObj.acc);
                // Here you can add the counter or you check the selectedAccounts.size()
            }
        }
    }

    public void ActivateData() 
    {
        for(Division_Space2__c acc : selectedDivisions )
        {
            acc.Active__c= true;
        }
        update selectedDivisions ;
        searchRecord();
    }

    public void DeActivateData() 
    {
        for(Division_Space2__c acc : selectedDivisions )
        {
            acc.Active__c = false;
        }
        update selectedDivisions ;
        searchRecord();
    }
    


    // This is our wrapper/container class. 
    public class DivisionWrapper 
    {
        public Division_Space2__c acc {get;set;}
        public Boolean selected {get;set;}
        public DivisionWrapper(Division_Space2__c a) 
        {
            acc = a;
            selected = false;
        }
    }

}

Visualforce Page:
<apex:page controller= "NFOSDisplayDivisions2Controller">
    
<script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
    <apex:form >
        <apex:pageBlock id="PB1">
            <apex:pageBlockButtons >
                <apex:commandButton value="Add to Grid" action="{!processSelected}" rerender="table2,PB2"/>
            </apex:pageBlockButtons>

            <apex:pageblockSection title="Division Types" collapsible="false" columns="1">
                <apex:pageBlockTable value="{!listDivisionWrapper}" var="accWrap" id="table" title="Division Types">
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                        <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                    </apex:column>
                    <apex:column value="{!Division_Space2__c.acc.Name}" />
                    <apex:column value="{!Division_Space2__c.acc.Number_of_Competitors__c}" />
                    <apex:column value="{!Division_Space2__c.acc.Availability__c}" />
                    <apex:column value="{!Division_Space2__c.acc.Active__c}" />
                </apex:pageBlockTable>


            </apex:pageblockSection>
        </apex:pageBlock>
        
        <apex:pageBlock id="PB2" >
            <apex:pageBlockButtons >
                <apex:commandButton value="Activate" action="{!ActivateData}" rerender="PB1,PB2"/>
                <apex:commandButton value="DeActivate" action="{!DeActivateData}" rerender="PB1,PB2"/>
            </apex:pageBlockButtons>

                <apex:pageBlockTable value="{!selectedDivisions}" var="c" id="table2" title="Selected Divisions">
                    <apex:column value="{!c.Name}" headerValue="Division Type"/>
                    <apex:column value="{!c.Number_of_Competitors__c}" headerValue="Number of Competitors"/>
                    <apex:column value="{!c.Availability}" headerValue="Availability"/>
                    <apex:column value="{!c.Active__c}" headerValue="Active"/>
                </apex:pageBlockTable>
        </apex:pageBlock>

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