I have created the lemonade app. And for that app, I have created a visual force page which displays a form and a report. The form gets the value and inserts it into the object (Drink_Order__c).
Visual force page:-
<div class="row">
<div class="col-md-6">
<apex:form styleClass="form-group">
<apex:pageBlock>
<apex:inputField styleClass="form-control" value="{!d.Flavor__c}"/><br />
<apex:inputField styleClass="form-control" value="{!d.Size__c}"/><br />
<apex:inputField styleClass="form-control" value="{!d.Price__c}"/><br />
<apex:commandButton styleClass="btn btn-primary" action="{!save}" value="Take Order"/>
<apex:pageBlockTable value="{!samepage}" var="c">
<apex:column headerValue="Flavor">
<apex:outputField value="{!c.Flavor__c}"/>
</apex:column>
<apex:column headerValue="Size">
<apex:outputField value="{!c.Size__c}"/>
</apex:column>
<apex:column headerValue="Price">
<apex:outputField value="{!c.Price__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</div>
<div class="jumbotron" style="padding: 5px;">
<div class="">
<h3>Report</h3>
<analytics:reportChart developerName="" reportId="00O6F00000CbFKkUAN"/>
</div>
</div>
</div>
Controller:-
public with sharing class LemonadeController {
// fetching fields from Drink_Order__c
public Drink_Order__c d{get; set;}
public List<Drink_Order__c> samepage { get; set; }
public LemonadeController(){
d = new Drink_Order__c();
}
public PageReference save(){
insert d;
samepage = [SELECT Id, Flavor__c, Size__c, Price__c FROM Drink_Order__c WHERE id=:d.id];
return null;
}
}
I got the below error after 1 record insert
Insert failed. First exception on row 0 with id a086F000028cCCzQAM; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id] Error is in expression '{!save}' in component in page lemonadeapp: Class.LemonadeController.save: line 13, column 1