I have a scenario where a user if he/she uploads a file against a particular record, then the user will be redirected to a VF page after the file upload is successful. I wrote a simple trigger in which I am redirecting to a VF page. The code is as following :-

  trigger CheckAttachmentName on ContentDocumentLink (after insert) {
    if(trigger.isAfter) {
        if(trigger.isInsert) {
            system.debug('test line');
            //pageReference pdf = Page.ss;
            //PageReference pageRef = new PageReference('/apex/ss');
            PageReference pageRef = new PageReference('https://xxyyyaaaa-dev-ed--c.ap4.visual.force.com/apex/ss');

As one can see I have tried a few known ways to redirect to the VF page but have been unsuccessful. Here "ss" is the simple VF page which has a hard coded text message. Any suggestion can be very helpful for me.

2 Answers 2


Triggers cannot redirect you to a new page. You'll need to accomplish this with something like a button which brings your users into a visualforce page.


Let's take a step back ....

Triggers execute at the database layer of the software application stack. As such, they occur whenever DML occurs to the database object. In Salesforce, this can happen in many ways:

  • user action from the UX (e.g. clicking Save)
  • DML from a scheduled flow or batchable
  • DML within an APEX REST class
  • DML from execution of a native SFDC REST or SOAP API
  • Dataloader
  • BulkAPI
  • Downstream action from subscribing to a platform event
  • DML from a LWC or Aura component
  • ...

As such, redirecting to a VF page from this layer in the software stack does not make architectural sense.

Redirection to VF pages should be done when the initial stimulus is from a UX action and the redirection should be done by the "controller" that directly responds to the stimulus.

  • any idea how can I go along solving the above issue. Basically I am trying to show a custom alert message to the user after the file is uploaded...
    – Rivu Indra
    Mar 8, 2021 at 17:44
  • How is the file being uploaded? Is it through the standard UX or via some custom action?
    – cropredy
    Mar 8, 2021 at 17:54
  • it is getting uploaded by the standard UX way....
    – Rivu Indra
    Mar 8, 2021 at 18:05
  • Use a VF or LWC component on the Lightning Page for the record that queries the record's ContentDocumentLink.createdDate to decide whether an alert should be shown
    – cropredy
    Mar 8, 2021 at 18:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .