You need to sign in to do that
Don't have an account?
JWykel
Record Not Updating Outside Of Page
I have this bit of code:
When I open the page, all fields are correctly calculated and viewed. I view the debug logs and it shows 1 DML statement/row and shows the upsert with no errors. The fact that it does the upsert and then does a SELECT from the database for the record would lead me to believe the record was updated in the database.
However, this is not the case! When I view the record directly or via a report, the fields are not updated; they remain at their previous values.
If I run the AccountTrigger.ProcessAccountSummary(AccountId); via Execute Anonymous, the record gets updated correctly and shows in reports/view correctly.
Has anyone else experienced this? Does it have something to do with 'when' this code is called, in that it is called in a 'get' of a property for a VF page? How can that 'get' SELECT from the database the correct values when the database does not appear to get updated with correct values?
public AccountSummary__c Summary{ get{ if(AccountId == null){ return new AccountSummary__c(); } AccountTrigger.ProcessAccountSummary(AccountId); //Processes and upserts the record //SELECT the record that was processed and upserted above return Database.query('SELECT ' + SelectStar + ' FROM AccountSummary__c WHERE AccountId__c = :AccountId'); } }The page that uses this Summary record looks something like this:
<apex:pageBlock > <apex:pageBlockSection > <apex:pageBlockSectionItem ><apex:outputLabel value="Tests {!MonthNames[15]}"/><apex:outputText value="{!Summary.T15MA__c}"/></apex:pageBlockSectionItem> <apex:pageBlockSectionItem ><apex:outputLabel value="Patients {!MonthNames[15]}"/><apex:outputText value="{!Summary.P15MA__c}"/></apex:pageBlockSectionItem> <apex:pageBlockSectionItem ><apex:outputLabel value="Tests {!MonthNames[14]}"/><apex:outputText value="{!Summary.T14MA__c}"/></apex:pageBlockSectionItem> <apex:pageBlockSectionItem ><apex:outputLabel value="Patients {!MonthNames[14]}"/><apex:outputText value="{!Summary.P14MA__c}"/></apex:pageBlockSectionItem> ...
When I open the page, all fields are correctly calculated and viewed. I view the debug logs and it shows 1 DML statement/row and shows the upsert with no errors. The fact that it does the upsert and then does a SELECT from the database for the record would lead me to believe the record was updated in the database.
However, this is not the case! When I view the record directly or via a report, the fields are not updated; they remain at their previous values.
If I run the AccountTrigger.ProcessAccountSummary(AccountId); via Execute Anonymous, the record gets updated correctly and shows in reports/view correctly.
Has anyone else experienced this? Does it have something to do with 'when' this code is called, in that it is called in a 'get' of a property for a VF page? How can that 'get' SELECT from the database the correct values when the database does not appear to get updated with correct values?
All Answers
dditional tests:
I changed the
toand it errors out with DML not allowed. Is this a bug in SF in that the 'Property{ get{...' concept is acting differently than the 'getProperty(){...' concept?
My current workaround is to move the code into a method and call the method in the page's action tag:
This is You can follow this process :
1. Query in your constructor for AccountSummary__c if return 0 recods then send new AccountSummary__c();
2. Create Seprate method (If RefreshSummary is seprate then its OK)in which you wants to update record.
3. Remove action="{!RefreshSummary}" from <apex:page >
4. Add these in your Page
<script>
jsSummary();
</script>
and add also
<apex:pageMessages id="pgmsgId"/>
<apex:actionFunction name="jsSummary" action="{!RefreshSummary}" rerender="pgmsgId"/>
PS: If this answers your question then hit Like and mark it as solution!
Tejpal Kumawat, thanks for another way to get it working :) The <apex:page action="{!RefreshSummary}" works as expected; is there a best practice or other reason I do not know to use your suggestion over the page action?