You need to sign in to do that
Don't have an account?
Master-Detail relationship and list editing
I created an object to link Opportunities to Contacts with custom fields.
I set the relation to both Opportunity and Contact to Master-Detail type.
I'm trying now to create a Visualforce page to link several contacts at the same time with a pageBlocktable
<apex:pageBlockSection title="Contact Roles" showHeader="true" collapsible="false" columns="1" id="roleList"> <apex:pageBlockTable value="{!crs}" var="cr"> <apex:column headerValue="Contact"> <apex:inputField value="{!cr.Contact__c}"/> </apex:column> </apex:pageBlockTable> <apex:commandButton value="Add Row" action="{!AddRow}" reRender="roleList"/> </apex:pageBlockSection>
The point is that when I'm clicking on the Add Row button (which is adding a new record to the crs list in the controller) or if I click on cancel, I am blocked because the contact is mandatory (Opportunity is filled by code).
Is there a way to bypass this validation on Cancel or Add Row or should I change my relation to Lookup?
If I use a lookup, I will lost the cascade delete on Contacts, to have this functionality with lookups I will have then to write OnDelete and OnUndelete Triggers. Is that the better solution in your opinion?
thanks,
Are you inserting your Contact Role object inside the Add Row method, or just instantiating it?
Posting your AddRow method might be helpful.
well i dont know much about salesforce, as i am also new to it. Well as far I understood your issue you can achieve it by using extension and in it you can pass the mandatory feild in the constructor, and even u can override the add and cancel function there.
******CONTROLLER******
public class A
{
//property
public B prop {get;set;}
//Constructors
public A()
{
prop= new B ();
}
public A()
{
prop= new B (feild1__c='X', feild2__c='Y, feild3__c='Z'' );
}
}
*******VFPage********
<apex:page standardcontroller="here comes your standard controller" extension="A">
<apex:page>
perhaps it helps u
Regards,
Meer
Hi,
I'm calling the Page from Opportunity and filled the Opportunity by default but I want the contact to be choosen by the user.
I just instanciate a new Role and send back a null pagereference.
Hi,
It seems as you are looking for a list of records. Check this blog hope this will help you
http://bobbuzzard.blogspot.co.uk/2011/07/managing-list-of-new-records-in.html
Regards,
Meer
Hi,
This was a good idea but, my mandatory field is not a Name but a lookup to a Contact and the system is asking for a valid Contact ID.
Should I create and Save false contacts that I will delete after?
Is there any workaround for this or should I go to a lookup relationship with triggers?
thanks