• #21394
    Salesforce | shariq shariq #1
    Forcetalks

    How to show error message on the detail page of Salesforce sobject through before delete trigger?

    I want to show error message on Account detail page, given below trigger shows error on the different page :-

    trigger testDelete on Account (before delete)
    {
    List <Account> acc = [SELECT Id, (SELECT Id FROM Opportunities ) FROM Account WHERE Id IN : Trigger.old];
    for(Account a : acc)
    {
    if(a.Opportunities.size()>0)
    {
    Trigger.oldmap.get(a.Id).addError(‘Cant Delete’);
    }
    }
    }

     

    #21406
    Forcetalks

    Hello Shariq,

    Try this once…

    1. Go to Setup | Customize | <Standard Object Name> | Buttons, Links & Actions and then Click ‘New Button or Link’ or if it is a Custom Object then go to Setup | Create | Objects and then click on the Custom Object name. Scroll down to find the section ‘Buttons, Links, and Actions’ and then click ‘New Button or Link’.
    2. Give it the Label: <A Valid Name>.
    3. Display Type: Detail Page Button.
    4. Behavior: Execute JavaScript.
    5. Content Source: OnClick JavaScript.

    Here is the JS:

    {!REQUIRESCRIPT(‘//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js’)}
    {!REQUIRESCRIPT(‘//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js’)}
    try{
    jQuery(function() {
    /*Append the jQuery CSS CDN Link to the Head tag.*/
    jQuery(‘head’).append(‘<link rel=”stylesheet” href=”//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/start/jquery-ui.css” type=”text/css” />’);

    /*Create the HTML(DIV Tag) for the Dialog.*/
    var html =
    ‘<div id=”dialog” title=”Go Home”><p>Do you want to go to the Home tab ?</p></div>’;

    /*Check if the Dialog(DIV Tag) already exists if not then Append the same to the Body tag.*/
    if(!jQuery(‘[id=dialog]’).size()){
    jQuery(‘body’).append(html);
    }

    /*Open the jQuery Dialog.*/
    jQuery( “#dialog” ).dialog({
    autoOpen: true,
    modal: true,
    show: {
    effect: “bounce”,
    duration: 1000
    },
    hide: {
    effect: “bounce”,
    duration: 1000
    },
    buttons: {
    “Continue”: function() {
    location.replace(‘/home/home.jsp’);
    jQuery( this ).dialog( “close” );
    },
    Cancel: function() {
    jQuery( this ).dialog( “close” );
    }
    }
    });
    });
    }
    catch(e){
    alert(‘An Error has Occured. Error: ‘ + e);
    }

    Save the same!

    7. Now, just open any Record, click Edit Layout at top-right..
    9. From the Page Host, select Buttons list and drag the new button onto the Page Layout.
    10. Save and you are done!

    #21975
    Salesforce | Shubham Shubham #208
    Forcetalks

    Hi RadaKrishna

    How it is Work now,can you explain please

    Actually now It is also navigate to the other page on delete of a selected account in case of ‘before delete’ trigger is active

    #23514
    Salesforce | Satya Satya #425
    Forcetalks

    Using standard page we can have these kind of messages only when we save info , but we cannot have this for delete actions as the page will be redirected to some predefined page. The only way is to customize the detail page using visual force and there we can have own custom validation.

    Workaround :

    You can override Delete button with your javascript custom delete.
    Check you condition in JAVASCRIPT and if satisfied then display alert message. else delete that record.

    #23519
    Salesforce | Satya Satya #425
    Forcetalks

    Using stadard page we can have these kind of messages only when we save info , but we cannot have this for delete actions as the page will be redirected to some predefined page. The only way is to customize the detail page usign visual force and there we can have own custom validation.

Viewing 5 posts - 1 through 5 (of 5 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?