You need to sign in to do that
Don't have an account?
Pallavi Ghole
Save button in Visualforce not saving to object field
Hello SFDC Gurus,
I am writing below code and while theSave button shows up on the VF page and on selecting a Rating value it seems to be updating all the selected records to that value on the VF page, however when I go back to the Account record from the standard search page and check the Account, its Rating has not been updated with the value I selected in the VF page.
Can you please help ?
<apex:page standardController="Account" recordSetVar="accounts">
<apex:form >
<apex:pageBlock title="Account List">
<apex:inputField value="{!Account.Rating}"/>
<apex:commandButton action="{!save}" value="Update Rating"/>
<apex:pageBlockTable value="{!selected}" var="acct">
<apex:column >
<apex:facet name="header">
Account Name
</apex:facet>
<apex:facet name="footer">
End of Table
</apex:facet>
<apex:outputField value="{!acct.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
Rating
</apex:facet>
<apex:facet name="footer">
End of Table
</apex:facet>
<apex:outputField value="{!acct.Rating}"/>
</apex:column>
</apex:pageBlockTable>
<apex:commandLink action="{!previous}"/>Previous<apex:commandLink />
<apex:commandLink action="{!next}"/>Next<apex:commandLink />
</apex:pageBlock>
</apex:form>
</apex:page>
I am writing below code and while theSave button shows up on the VF page and on selecting a Rating value it seems to be updating all the selected records to that value on the VF page, however when I go back to the Account record from the standard search page and check the Account, its Rating has not been updated with the value I selected in the VF page.
Can you please help ?
<apex:page standardController="Account" recordSetVar="accounts">
<apex:form >
<apex:pageBlock title="Account List">
<apex:inputField value="{!Account.Rating}"/>
<apex:commandButton action="{!save}" value="Update Rating"/>
<apex:pageBlockTable value="{!selected}" var="acct">
<apex:column >
<apex:facet name="header">
Account Name
</apex:facet>
<apex:facet name="footer">
End of Table
</apex:facet>
<apex:outputField value="{!acct.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
Rating
</apex:facet>
<apex:facet name="footer">
End of Table
</apex:facet>
<apex:outputField value="{!acct.Rating}"/>
</apex:column>
</apex:pageBlockTable>
<apex:commandLink action="{!previous}"/>Previous<apex:commandLink />
<apex:commandLink action="{!next}"/>Next<apex:commandLink />
</apex:pageBlock>
</apex:form>
</apex:page>
Try to write Apex class to this requirement, where
Create a new list for account,and create a method like
public void save()
{
// write your query here
// update query;
}
Regards,
Sumitha P
I am new to VF coding so am not sure how I need to write the method. The code I pasted is exactly how the code in the tutorial is , in the tutorial it seems to be updating multiple values to the database but is not doing that in my code.
Regards
Pallavi
I just noticed - the Account records I was selecting did not have a value in the Rating field to begin with so looks like the code above does not handle nulls yet (got to figure out that!). Once I updated each of those account rating fields and then selected them to show up on my VF page the Save button did its job and updated the selected records with the new value of rating.
Hope the layman explanation makes sense :)
Regards
Pallavi