I want a VF page that would aid creating multiple child records for selected IDs.
As an example, I would start from Account, select 5 or 7 Contacts, click a button which would take me to a custom VF page on a custom object where I can add data a la Excel style. Contact ID would be a parent ID.
Ideally it would use standard controller.
Do you think it's possible or have you seen any examples?
I am going to guess it could be a good time saver for many teams!
Thanks ~dzh
EDIT: Code I've got so far.
VF:
<apex:page standardController="Electricity_Meter__c" recordSetVar="ElecMeters" extensions="massQuoting" tabStyle="Electricity_Meter__c" sidebar="false">
<apex:form >
<apex:pageBlock title="Populate all fields with the same value" mode="edit" id="masspgblck">
<apex:pageBlockTable value="{!Electricity_Meter__c}" var="mult" >
<apex:column headerValue="RecordType" value="{!mult.RecordType.Name}"/>
<apex:column headervalue="Linked Basket" footervalue="Linked Basket">
<apex:inputField value="{!mult.Linked_Basket2__c}">
<apex:actionSupport event="onchange" rerender="muselected"/>
</apex:inputField>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageblock title="Selected Meters" id="muselected">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" />
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:column headervalue="Linked Basket" footervalue="Linked Basket">
<apex:inputField value="{!elecM.Linked_Basket2__c}"/>
</apex:column>
<apex:column headerValue="Day Rate" footerValue="Day Rate">
<apex:inputField value="{!newQuotes.Day_rate__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex extension:
public class massQuoting{
ApexPages.StandardSetController mycon;
public List<Quote__C> newQuotes {get; set;}
public List<Electricity_Meter__c> Selectedmeters {get; set;}
ID accId{get;set;}
public massQuoting(ApexPages.StandardSetController controller) {
accId = ApexPages.currentPage().getParameters().get('id');
mycon = controller;
Selectedmeters = mycon.getSelected();
}
public void save(){
newQuotes = new list<Quote__c>();
for (Electricity_Meter__c m : Selectedmeters){
newQuotes.add(new Quote__c(
Day_rate__c=decimal.valueOf('0.01'), /* needs to be entered from VF */
Standing_Charge__c=decimal.valueOf('120'), /* needs to be entered from VF */
Supplier__c='Avanti Gas', /* needs to be entered from VF */
All_Products__c=m.id
));
}
try {
insert newQuotes;
} catch (DmlException ex){
ApexPages.addMessages(ex);
}
mycon.save();
}
}