You need to sign in to do that
Don't have an account?
mahesh p 54
Initially Tour Packages and Add Multiple Bookings should not be displayed.When i click save button the Tour Package section with Add Multiple Bookings needs to display.How can i achieve this?
After I click save button i need to display section
<apex:page Controller="CustomerController" > <apex:form > <apex:pageBlock title="Customer"> <apex:pageBlockSection columns="2" title="Basic Information"> <apex:inputField value="{!c.Name}"/> <br/> <apex:inputField value="{!c.Address_1__c}"/> <apex:inputField value="{!c.Address_2__c}"/> <apex:inputField value="{!c.Country__c}"/> <apex:inputField value="{!c.States__c}"/> <apex:inputField value="{!c.city__c}"/> <apex:inputField value="{!c.Zip_Code__c}"/> <apex:inputField value="{!c.Account__c}"/> </apex:pageBlockSection> <apex:pageBlockSection columns="2" title="Tour Information"> <apex:inputField value="{!c.Passport_Number__c}"/> </apex:pageBlockSection> <apex:pageBlockSection columns="2" title="Health Information"> <apex:inputField value="{!c.Blood_Group__c}"/> </apex:pageBlockSection> <apex:pageBlockSection columns="1" title="Tour Packages"> </apex:pageBlockSection> <apex:pageBlockTable value="{!listBookings}" var="b"> <apex:column headerValue="Type a Destination"> <apex:inputField value="{!b.Type_a_destination__c}"/> </apex:column> <apex:column headerValue="Travel Mode"> <apex:inputField value="{!b.Travel_Mode__c}"/> </apex:column> <apex:column headerValue="From Date"> <apex:inputField value="{!b.From_Date__c}"/> </apex:column> <apex:column headerValue="To Date"> <apex:inputField value="{!b.To_Date__c}"/> </apex:column> <br/> <apex:column headerValue="Bookings for Customer"> <apex:inputField value="{!b.Customer__c}"/> </apex:column> </apex:pageBlockTable> <apex:pageBlockButtons > <apex:commandButton value="Add Multiple Bookings" action="{!addBookings}"/> <apex:commandButton action="{!save}" value="Save"/> </apex:pageBlockButtons> <!--<apex:pageBlockTable value="{!samepage}" var="c"> <!--<apex:column headerValue="Name"> <apex:outputField value="{!c.name}"/> </apex:column> <apex:column headerValue="Address 1"> <apex:outputField value="{!c.Address_1__c}"/> </apex:column> <apex:column headerValue="Address 2"> <apex:outputField value="{!c.Address_2__c}"/> </apex:column> </apex:pageBlockTable>--> </apex:pageBlock> </apex:form> </apex:page>
public with sharing class CustomerController { Booking__c b=new Booking__c(); public list<Booking__c> listBookings{ get; set; } public Customer__c c { get; set; } public List<Customer__c> samepage { get; set; } public CustomerController(){ c=new Customer__c(); listBookings=new list<Booking__c>(); listBookings.add(b); } Public void addBookings() { Booking__c b = new Booking__c(); listBookings.add(b); } public PageReference save() { upsert c; upsert b; samepage= [select id,Name,Address_1__c,Address_2__c,Country__c,States__c,city__c,Zip_Code__c,Account__c,Passport_Number__c,Blood_Group__c,Type_a_Destination__c,From_Date__c,To_Date__c from Customer__c where id=:c.id]; return null; } public PageReference saveBookings() { for(Integer i=0; i<listBookings.size(); i++) { insert listBookings; } upsert c; upsert b; return Page.Allbookingssaved; } }
Initially Tour Packages and Add Multiple Bookings should not be displayed.When i click save button the Tour Package section with Add Multiple Bookings needs to display.How can i achieve this?
Take a boolean variable and render the button, section using that boolean:
Class:
and the rendered statment:
Hope this is useful.
Thanks.
All Answers
Take a boolean variable and render the button, section using that boolean:
Class:
and the rendered statment:
Hope this is useful.
Thanks.
You need not run a loop to insert list.
Please let me know if this helps.
Happy to help further.
Kindly mark this as solved if the reply was helpful.
Thanks,
Gulafsha
--- Clarification
Insert failed. First exception on row 0 with id a0B0K00000dJAOlUAO; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
Error is in expression '{!save}' in component <apex:commandButton> in page customers: Class.CustomerController.save: line 26, column 1
<apex:pageMessages/> in VF Page.
and in Class:
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!')); this as my message.But after the save button is clicked the tour packages section is displayed and i am adding either a single booking or multiple bookings then i need to display something like this
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Bookings are inserted Successfully.Thank you!'));
Is this Possible?
Thank you