function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KSusan CoxKSusan Cox 

Can we Refresh standard page using Controller?

Hi,
I have created one Apex Controller, from which I am controlling the standard visualforce page. Now the problem is that I want to refresh the page within the class. I don’t have any visualforce pages I want to refresh the standard page of Salesforce from class. So, if anybody knows please let me know that.

Thanks,
Susan
Shyam BhundiaShyam Bhundia
Hi Susan,

Could you give a bit more context around what you are trying to do?

Its a bit confusing, as you say you are using a controller to control a visualforce page, then go on to say that you don't have any visualforce pages...

Thanks
Shyam
KSusan CoxKSusan Cox
Hi Shyam,

Sorry for my Language  i am controlling Standard Page using trigger not VF Page,I don't have any VF Pages, and i want to referesh that standard page
Shyam BhundiaShyam Bhundia
Hello,

There is no way to refresh the standard page from the the trigger.   

Is the trigger based on the same object as the standard page?  If so, when you do a save after an edit, the standard page should refresh by it self.  
KSusan CoxKSusan Cox
Hi Shyam,
 
The trigger is same based on the object, but it is not refershing by itself 
Shyam BhundiaShyam Bhundia
Ok.  Could you explain your scenario please. As in what's the trigger event?  Is the trigger kicked of from the page you want to refresh?

Cheers
KSusan CoxKSusan Cox
Hi,

 Trigger event is "Afer Event ", and Yes,the trigger kicked of from the page i want to refresh.
Shyam BhundiaShyam Bhundia
OK I did a quick test and the standard page does refresh after you had editted it and saved it.

What is not refreshing on your page?
KSusan CoxKSusan Cox
Hi Shyam,
                     Thanks for your quick reply, I am trying to delete chatter post but problem is when  I manually refresh a page post is deleted automatically so I  want to refresh a page from my controller
Shyam BhundiaShyam Bhundia
Sorry for the delay in gettng back to you.

Let me clarify, are you deleteing chatter posts from the chatter feed on the chatter tab or from the chatter feed on the records?  
Is your trigger on the chatter feed?
Whats the purpose of your trigger?
KSusan CoxKSusan Cox
Hi Shyam,
Thanks for your response. 
I am deleting posts form chatter post, not from feed on the record. 

I have 'after insert'  trigger on FeedItem, let's say T1. I am deleting some post based on our business requirement from apex class, C1. We are calling one method of  class C1 from Trigger T1 to delete the FeedPost. The class C1 is performing delete process. 

Now suppose if I delete some post using class C1, content are getting posted on the feed immediately and I am getting a pop-up message from system saying 'post has been removed' but the chatter page is not getting refreshed. When I manually refresh the page, the post is disappearing.

I want something to refresh the page automatically after that pop-up message. I had tried another trigger on FeedItem (after delete) and called one method  that returns Pagerefence to refresh the chatter standard page but this did't work.

Please help me for this.
Thanks 
Shyam BhundiaShyam Bhundia
Why not have your trigger fire on before insert?

As you have tried already, there is no way to refresh a page from a trigger.
KSusan CoxKSusan Cox
Hi, Shyam,
 Is there any way to open another vf page from trigger? 

Thanks,
Shyam BhundiaShyam Bhundia
nope you cannot redirect from a trigger, as it runs in the background.

Are you trying to delete newly inserted feeditems or exisiting ones?
KSusan CoxKSusan Cox
I am trying to delete newly inserted feeditems
Shyam BhundiaShyam Bhundia
ok, so try using a before insert trigger.  To prevent a feed item being inserted, add an error to the record using record.addError('some message').  This will stop the record from being added and i believe it will show the message you entered on the chatter feed.
KSusan CoxKSusan Cox
Hi Shyam,
Thanks for your reply. We have inserted the feed item first for some reason and after inserting we need to delete that post based on some condition. The delete process is also performed by apex class as I described in previous comment. Is there any other solution to delete the post and auto refresh the page once deleting is completed
Shyam BhundiaShyam Bhundia
The only way I can think of is to have the logic in the before insert trigger and add an error message, which will prevent the feed item from being inserted and will tell the user why the feed item is not posted.  Which I think is a better solution because the user doesn't know why their feed item is not posted, they might re-post it and again it will disappear. 

Is there a reason why you need to have the record inserted before you delete it?
KSusan CoxKSusan Cox
Hi Shyam,
                     I have already tried before insert trigger. It is preventing the feed item from being inserting and gives error message to User But, Problem is when I do this I am not able to save the data which I prevent from being post.

Thanks,
Shyam BhundiaShyam Bhundia
OK, so we're nearly there :)
 
Where do you want to save the data?  by data are you talking about the actual content of the feed item?
KSusan CoxKSusan Cox
Yes, the Actual content of the feed item, stored data in object any other option is there to store the data?
Shyam BhundiaShyam Bhundia
How about just after you add the error to the feeditem (to prevent it from being inserted), you create a new record of the object where you want the feed item content to be stored in?  That way the feed is not inserted and the content is saved in another object..


KSusan CoxKSusan Cox
Hi Shyam,
Could you elaborate a bit more context around what you are trying to say?
Shyam BhundiaShyam Bhundia
the below pseudo code describes what i mean

before insert trigger{

	//list of records of the object which holds the deleted feed items content
	List<DeletedFeedItem> deletedFeedItemsList

	for(FeedItem newItems : feedItemsToBeInserted){
	     If(newItem is to be deleted){ //depending on your business rule

	         //add error to the feed item to stop it from being inserted
	         newItem.addError(your message goes here);
	        
	        //create a new record of the object where you want to store the deleted feed content
	         DeletedFeedItem aDeletedFeedItem = new DeletedFeedItem
	         aDeletedFeedItem.content = newItem.Body
	         deletedFeedItemsList.add(aDeletedFeedItem)
	     }
	}
	//insert the list of records that hold the deleted feed item contents
	insert deletedFeedItemsList
}