• shilpa narayan
  • 0 Points
  • Member since 2022

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1

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:pageBlockButtons >
            <apex:commandButton value="Add Another Record Type" action="{!addRecType}"/>
            <apex:commandButton value="Save All Record Types" action="{!saveType}" reRender="showMsg"/>

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>();

    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);
    public PageReference saveType() {
    	insert listRecType;
    return Page.NewRecType;