Activity Forums Salesforce® Discussions How to set expire a link after one time click in Salesforce

  • How to set expire a link after one time click in Salesforce

    Posted by Anjali on September 18, 2018 at 7:36 am

    How to set expire a link after one time click in Salesforce?

    Note: I want to use only links no button.

    Mani replied 2 years, 3 months ago 5 Members · 4 Replies
  • 4 Replies
  • madhulika shah

    Member
    September 18, 2018 at 1:38 pm

    Hi,

    You'll need to store the fact that the link is expired somewhere, preferably where your end user can't get to it.

    If your link is pulling all of its information from a single object and sending it to one or multiple people at the same time, consider a custom date/time field on Opportunity to store the expiration date. I'm not going to go in to how to set that field.

    The links you send to your contacts should all reference the same Visualforce page, but they should have a URL parameter in them that references the object you want them to see information from:

    http://instance.salesforce.com/apex/YourPage?id=opportunityId

    If you're sending the link to the information on this object to multiple people at multiple different times, that complicates it. To use that field, in your visualforce page you'll want to do something like this:

    <apex:page action="{!checkExpiration}" controller="{!pageController}"/>

    That action runs on page load, and inside the controller you'll have a function that might look like this.

    public pageReference checkExpiration() {
    if(myObject.linkExpiration > System.now()) {
    //send your user to a page indicating the link is expired
    return new PageReference('/apex/LinkExpired');
    } else {
    return null;
    }
    }

    Thanks.

     

  • Parul

    Member
    September 18, 2018 at 6:20 pm

    Hi

    In your html:

    <a href="#" id="myButton" title="">Click Me!</a>
    In your js:

    (function(){
    var click_counter = 0;
    $('#myButton').on('click', function(event){
    event.preventDefault();
    var el = jQuery(this);
    click_counter += 1;
    if (!el.hasClass('inactive')){
    // should be activated
    alert('You have clicked the link ' + click_counter + ' once , And this will be disabled');
    };
    if (click_counter >= 1){
    // deactivate
    el.addClass('inactive');
    };
    });
    })();
    And to indicate your button has been clicked , add this class to your CSS

    a.inactive {
    color: gray;
    text-decoration: line-through;
    }

    Hope this helps!

     

    Thanks

  • shariq

    Member
    September 19, 2018 at 9:47 pm

    Hi,

    You need to use standard class JwtToken which generates token encoded from sobject field's values and append that token in URL. This class gives the functionality to expire the token within some time limit or immediate depend upon youe logic.

    Hope this helps.

  • Mani

    Member
    July 28, 2022 at 4:14 pm

    Hi, I know this is an old question and my answer is not an exact solution. But this might help other online readers. If you simply want to expire an existing link based on number of clicks or based on time then you can achieve that easily. You can use various online temporary expiry link such as https://expiry.link
    Thank you.

Log In to reply.

Popular Salesforce Blogs