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>