You need to sign in to do that
Don't have an account?
John Neilan 18
Visualforce Page Duplicate Records
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
Controller
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; } }
Greetings!
Can you please check the controller code in the below thread to avoid duplicates in the list when working with the Visualforce pages.
https://salesforce.stackexchange.com/questions/84063/avoid-duplicates-entry-in-the-list-visualforce-page-controller
Kindly mark it as best answer if it helps so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
Hindi Status (https://www.desifunsun.com/hindi-status/)
Life Status (https://www.desifunsun.com/life-status/)
Love Status (https://www.desifunsun.com/love-status/)
Love status in hindi (https://www.digitalkhabar.in/%E2%99%A5love-status-in-hindi-for-whatsapp/)
Birthday Wishes for Mother in Hindi (https://www.digitalkhabar.in/happy-birthday-wishes-for-brother-in-hindi/)
Birthday Wishes for Boyfriend in Hindi (https://www.digitalkhabar.in/birthday-wishes-for-boyfriend-in-hindi/)
Birthday Wishes for Daughter in Hindi (https://www.digitalkhabar.in/birthday-wishes-for-daughter-in-hindi/)
Good Morning Images (https://www.digitalkhabar.in/new-good-morning-images/)
Motivational status (https://www.digitalkhabar.in/motivational-status-in-hindi/)
Anniversary Wishes for Mummy papa (https://www.digitalkhabar.in/marriage-anniversary-wishes-for-mummy-papa-in-hindi/)
PTE Coaching (https://indowestacademy.com/pte)
IELTS Coaching (https://indowestacademy.com/ielts)
Study Visa (https://indowestacademy.com/study-visa/)
IELTS Ambala (https://www.facebook.com/Indowestacademy/)