0

I am creating a Visualforce page. On that page I want to have a form to save new records and below that I want to have a table that shows all thata from that object.

I created this, but the problem is if my form works.. then table doesnt work. If I add recordSetVar="exapmle" to the apex page on top, then table works, but when I want to save something in that form nothing happened - Just redirect me to home page of salesforce.

Do you have any advice for me? How to fix that in the easiest way for amateur?

<apex:page standardController="Car__c" recordSetVar="cars">
     <h1>Add new car</h1>
     <apex:form >
          <apex:pageBlock title="Add car">
               <apex:pageBlockSection >
                    <apex:inputField value="{! Car__c.Brand__c }"/>        
               </apex:pageBlockSection>
               <apex:pageBlockSection >
                    <apex:inputField value="{! Car__c.Model__c }"/>        
               </apex:pageBlockSection>
               <apex:pageBlockSection >
                    <apex:inputField value="{! Car__c.Year__c }"/>
               </apex:pageBlockSection>        
               <apex:pageBlockButtons >
                    <apex:commandButton action="{! save }" value="Save" />        
               </apex:pageBlockButtons>
          </apex:pageBlock>
     </apex:form>
     <apex:pageBlock title="Cars Table">
          <apex:pageBlockTable value="{!cars}" var="car">
               <apex:column value="{! car.Brand__c }"/>
               <apex:column value="{! car.Model__c }"/>
               <apex:column value="{! car.Year__c}"/>
          </apex:pageBlockTable>
     </apex:pageBlock>
</apex:page>
1

You won't be able to achieve it using only standard controller, you either have to create an extension controller or custom controller for this to work.

recordSetVar works on List of sObjects i.e. it is used to display list of records. But as in your requirement, you need to display both List as well as create new records.

You can go through this trailhead module for further help on this requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.