This is my public Site.
This site displays a list of records from a custom object.
If you try to do an inline edit on the 5th record you will see that you are able to do an inline edit/save successfully where as you will not be able to do an inline edit on the 3rd record .
Not sure how this inconsistency is possible as i dont have any custom logic built between these records.
My VF Page is as follows
<apex:page standardcontroller="Expense__c" extensions="ExpenseController" sidebar="false" showHeader="true" showChat="false" recordSetVar="exp" >
<script src="../../soap/ajax/30.0/connection.js" type="text/javascript"></script>
<apex:form >
<apex:inlineEditSupport />
<apex:pageBlock title="List of Expenses">
<apex:pageBlockTable value="{!exp}" var="item" >
<apex:column value="{!item.Date__c}"/>
<apex:column value="{!item.Type__c}"/>
<apex:column value="{!item.Amount__c}"/>
<apex:column value="{!item.Comments__c}"/>
</apex:pageBlockTable>
<p>Sum of All Expenses : Rs {!SumOfAllExpenses}</p>
</apex:pageBlock>
<apex:commandButton action="{!save}" value="Save" id="theButton1" />
<!--<apex:commandButton value="Total" id="theButton2" onclick="alert('Deleting the expense...')"/>-->
</apex:form>
</apex:page>
Can someone explain this weird behavior ?
UPDATE :
public with sharing class ExpenseController
{
private ApexPages.StandardSetController sc;
public Integer SumOfAllExpenses {get; set;}
public ExpenseController(ApexPages.StandardSetController sc)
{
this.sc = sc;
SumOfAllExpenses = displayTotal();
}
public Integer displayTotal()
{
List<AggregateResult> i = [SELECT SUM(Amount__c) FROM Expense__c];
SumOfAllExpenses = Integer.valueOf(i[0].get('expr0'));
return SumOfAllExpenses;
}
public PageReference save()
{
System.debug('Before Save - Comments Value :'+(Expense__c)sc.getRecord());
sc.save();
System.debug('After Save - Comments Value :'+(Expense__c)sc.getRecord());
displayTotal();
System.debug('After Total - Comments Value :'+(Expense__c)sc.getRecord());
PageReference p = new PageReference('/apex/addExpenses');
return p;
}
}
Attribution to: Varun
Possible Suggestion/Solution #1
Seems like the necessary pattern to make this work is to use an apex:outputfield
:
<apex:column headerValue="Date">
<apex:outputfield value="{!item.Date__c}"/>
</apex:column>
This is taken from Inline edit of PageBlockTable only saving one record.
Attribution to: Keith C
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32663