I am trying to implement functionality in SalesForce where when a user clicks a button then the following count increases.
Currently I have a simple test page that just shows the following count. When a user clicks a commandbutton they follow a new user and the following count gets increased by one. This all works OK on the back end. The followingCount gets increased by one.
The issue is that when I click the button my page appears to reload but the followingCount on the screen is not the new updated number but the old stale value.
Example: if the followingCount is 1 and I click the button, the followingCount in the back end is correctly increased to 2, however when the page reloads it still displays on the page as 1.
When I manually refresh the page myself the count is then displayed correctly as 2.
Here is my code:
VisialForce Page
//Section that holds some data is a list
<div class="ui-block-c text">{!followingCount}</div>
//Apex button
<apex:commandButton id="CommandButton1" value="Follow" action="{!followOwner}"/>
APEX Class
public PageReference followOwner()
{
User userDetails = GetLoggedinUserDtls();
User profileUser = getUserDtls();
EntitySubscription follow = new EntitySubscription ();
follow.parentId = UserId;
follow.subscriberid = UserInfo.getUserId();
insert follow;
return null;
}
So I'm guessing that when I click the command button my visualforce page isn't getting fully reloaded? I have tried to use rerender with the command button but it didn't make any difference. Can anybody suggest why this might be happening?
Adding code for following count:
//Variable
public Integer followingCount{get;set;}
//Constructor
public userData (ApexPages.StandardController stdController) {
UserId = UserInfo.getUserId();
GetCount();
}
//Method
public void GetCount() {
List<User> following = [SELECT Id, Name,title, SmallPhotoUrl FROM User WHERE Id =:parentsetid AND Id !=:u.id order by name];
followingCount = following.size();
}
followingCount
as well. The issue could be in how the count is done.