You need to sign in to do that
Don't have an account?
Akash Choudhary 17
Creating records in child object if a particular Parent record is selected
Hi All,
I have a scenario where I need to create a VF page with these details:
whenever a parent record from (Auctions__c) object is selected, automaically option for creating a child record in
(SellerAuctionItem__c) object opens up in which Auction field(read only) (master detial relationship) is autopopulated with the parent record selected. And rest can be filled and saved
I have a scenario where I need to create a VF page with these details:
whenever a parent record from (Auctions__c) object is selected, automaically option for creating a child record in
(SellerAuctionItem__c) object opens up in which Auction field(read only) (master detial relationship) is autopopulated with the parent record selected. And rest can be filled and saved
Please follow these:
- On Selecting Parent object, call vf page method createRelatedChildRecords().
- In createRelatedChildRecords(), create a new record SellerAuctionItem__c sai = new SellerAuctionItem__c(parentId = Auctions__c.Id)
- Put this into a list, if need to create more child record or make SellerAuctionItem__c sai{get;set} at the top of page.
- Refresh the defined section of the page, or initiate the popup. As per your requirement.
The remaining fields can be filled by Customer.Hope this will solve your problem. Do let me know if need more details on it.
Thanks,
Gaurav
Skype: gaurav62990
Email: gauravgarg.nmims@gmail.com
The thing is cutomer have to select the parent object record from the vf page, only then they can fill in the details with auction field auto populated with the parent record here is what I have tried but it is not working pls help:
vf page-
<apex:page controller="RegisterMultipleAuction" showHeader="false" sidebar="false" standardStylesheets="true">
<apex:form >
<apex:pageMessages />
<apex:pageblock title="Available auction">
<apex:pageblocktable value="{!Allauction}" var="a">
<apex:column headervalue="Select one">
<apex:actionsupport action="{!Allauction}" event="onclick" >
<input type="radio" />
<apex:param name="auctionid" value="{!a.Id}">
</apex:param></apex:actionsupport>
</apex:column>
<apex:column headervalue="Name">
<apex:outputfield value="{!a.Name}">
</apex:outputfield></apex:column>
<apex:column headervalue="Auction Code">
<apex:outputfield value="{!a.Auction_Code__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Auction Start Date">
<apex:outputfield value="{!a.Auction_Start_Date__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Auction End Date">
<apex:outputField value="{!a.Auction_End_Date__c}">
</apex:outputField>
</apex:column>
<apex:column headervalue="Auction Status">
<apex:outputField value="{!a.Auction_Status__c}">
</apex:outputField>
</apex:column>
</apex:pageblocktable>
</apex:pageblock>
<apex:pageblock id="registerauction" title="Register for this auction">
<apex:pageblocktable id="registerauction" value="{!registerauction}" var="b">
<apex:column headervalue="Name">
<apex:inputField value="{!b.Name}">
</apex:inputField>
</apex:column>
<apex:column headervalue="Category">
<apex:inputField value="{!b.Category__c}">
</apex:inputField>
</apex:column>
<apex:column headervalue="Minimum Price">
<apex:inputField value="{!b.Minimum_Price__c}">
</apex:inputField>
</apex:column>
<apex:column headervalue=" Auction">
<apex:outputField value="{!b.Auction__c}">
</apex:outputField>
</apex:column>
<apex:column headervalue="Description">
<apex:inputField value="{!b.Description__c}">
</apex:inputField>
</apex:column>
<apex:column headervalue="Item Code">
<apex:inputField value="{!b.Item_Code__c}">
</apex:inputField>
</apex:column>
<apex:column headervalue="Status">
<apex:inputField value="{!b.Status__c}">
</apex:inputField>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save" action="{!saveauction}"/>
</apex:pageblock>
</apex:form>
</apex:page>
Controller-
public class RegisterMultipleAuction {
list<Auctions__c> a = new list<Auctions__c> ();
Public List<Auctions__c> getAllauction(){
List <Auctions__c> allauctions = [Select Id,Name,Auction_Code__c,Auction_End_Date__c, Auction_Start_Date__c, Auction_Status__c From Auctions__c where Auction_Status__c ='new'];
a.addAll(allauctions);
return a;
}
public void registerauction(){
if(!a.isEmpty()){
List<SellerAuctionItem__c> submitItem = [SELECT Id, Name, Category__c,Minimum_Price__c, Auction__c, Description__c,Item_Code__c,Status__c FROM SellerAuctionItem__c ];
for(SellerAuctionItem__c item :submitItem ){
item.Auction__c = a.get(0).Name;
}}
}
}
this is not working. PLEASE HELP!
Thanks
Thanks,
Gaurav
vf page-
<apex:page controller="RegisterMultipleAuction" showHeader="false" sidebar="false" standardStylesheets="true">
<apex:form >
<apex:pageMessages />
<apex:pageblock title="Available auction">
<apex:pageblocktable value="{!Allauction}" var="a">
<apex:column headervalue="Select one">
<apex:actionsupport action="{!Allauction}" event="onclick" >
<input type="radio" />
<apex:param name="auctionid" value="{!a.Id}">
</apex:param></apex:actionsupport>
</apex:column>
<apex:column headervalue="Name">
<apex:outputfield value="{!a.Name}">
</apex:outputfield></apex:column>
<apex:column headervalue="Auction Code">
<apex:outputfield value="{!a.Auction_Code__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Auction Start Date">
<apex:outputfield value="{!a.Auction_Start_Date__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Auction End Date">
<apex:outputField value="{!a.Auction_End_Date__c}">
</apex:outputField>
</apex:column>
<apex:column headervalue="Auction Status">
<apex:outputField value="{!a.Auction_Status__c}">
</apex:outputField>
</apex:column>
</apex:pageblocktable>
</apex:pageblock>
<apex:pageblock id="registerauction" title="Register for this auction">
<apex:pageblocktable id="registerauction" value="{!registerauction}" var="b">
<apex:column headervalue="Name">
<apex:inputField value="{!b.Name}">
</apex:inputField>
</apex:column>
<apex:column headervalue="Category">
<apex:inputField value="{!b.Category__c}">
</apex:inputField>
</apex:column>
<apex:column headervalue="Minimum Price">
<apex:inputField value="{!b.Minimum_Price__c}">
</apex:inputField>
</apex:column>
<apex:column headervalue=" Auction">
<apex:outputField value="{!b.Auction__c}">
</apex:outputField>
</apex:column>
<apex:column headervalue="Description">
<apex:inputField value="{!b.Description__c}">
</apex:inputField>
</apex:column>
<apex:column headervalue="Item Code">
<apex:inputField value="{!b.Item_Code__c}">
</apex:inputField>
</apex:column>
<apex:column headervalue="Status">
<apex:inputField value="{!b.Status__c}">
</apex:inputField>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save" action="{!saveauction}"/>
</apex:pageblock>
</apex:form>
</apex:page>
Thanks.
<apex:pageblocktable id="registerauction" value="{!saiList }" var="b">
I trust you are doing very well.
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Parent Object : Account
Child Object : Contact
Visualforce:
Controller:
Screenshot:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.
Thanks and Regards,
Khan Anas