+ Start a Discussion
Menaka RaghuvanshiMenaka Raghuvanshi 

Custom Button on List view

Hi,

I want to create a custom button "Remove" on lead list view. It should let user to remove selected leads from the specific view. I  know how to create the button and add it in search layout. However, I am not sure how to define the action. I think it would be via "OnClick Javascript"

Can anyone help me me the code for this functionality for the "Remove" button

Menaka
sandeep sankhlasandeep sankhla
Hi Menaka,

Removing the user from specific view means ? we create view add filters to the views and based on the filters records comes in the views..so here removing the records from specific view means..what exactly is your need ?

Thanks,
Sandeep
Menaka RaghuvanshiMenaka Raghuvanshi

Hi Sandeep,

I know we can use filter to filter out leads from the list view. But let's say there are 5 leads which I do not want to focus at all in the list view. So I want to be able to pick them individually and remove them from the list view via "remove button" rather than editing the filter criteria every time. Something like "Add to Campaign" standard button where used can pick leads from the view and add them to the campaign.

I think the action for the button will be defined via JavaScript. So I need help to develop the code that if I pick the lead and then hit "Remove" button then that lead is removed from the list view

Thanks,
Menaka



 

sandeep sankhlasandeep sankhla
Hi Menaka,

I would suggest you to use fileters ..if you dont want to see those 5 leads then you can simply add filter condition where lead name is not equal to your lead names which you dont want to see at all..

because if you will go for remove button , that will remove temporaly but when you again refresh the page and list view that time they will come again bcause in filter you have not added them....

but if you will add those in filter that will not come adn when you simply remov ethat filter that time that will come..

According to me there is no use of having this remove button because you are not attaching this lead with any other objct and relating..in your case you just want to remove from list view..which is not at all of any use..becuase eveytime when you see list view that will come..

It would be good if you go and add filters at once like fecth all leads but name or whatever field u need..should not be equal to value..
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer 
 
David ZhuDavid Zhu
First, you need to create a global class.
global class LeadExtClass{
    webService static void RemoveLeads(list<id> Leads)
    {
        delete [select id from lead where id in :Leads];
    }

}

Second, add the following code to custom button "Remove".
{!REQUIRESCRIPT('/soap/ajax/25.0/connection.js')}
{!REQUIRESCRIPT('/soap/ajax/25.0/apex.js')}

var records ={!GETRECORDIDS($ObjectType.Lead)};

if (records[0] == null) { alert("Please select at least one row") } 
else 
{
    var r = confirm("Are you sure want to remove the leads?");
    if(r == true)
    {
       sforce.apex.execute("LeadExtClass","RemoveLeads",{Leads: records});
       location.reload(true);
    }
}
User-added image
 
sandeep sankhlasandeep sankhla
Hi David,

Above code will delete the leads from database..I think menaka only wants to remove them from list view, not from database...According to me there is no way to remove from list view ...we can add them as filter and hide them..

Thanks,
Sandeep
Menaka RaghuvanshiMenaka Raghuvanshi
David,

Yes, I want to remove them from the list view and not delete them. Will the code work for that. Just want to double check

Thanks,
Menaka
sandeep sankhlasandeep sankhla
Hi Menaka,

Above code will delete them..I think you can simply add them as filter only..

Another solution I would say instead of deleting them we can update them so they will not full the creteria and they will not come in list view...

Thanks,
Sandeep
David ZhuDavid Zhu
Unfortunately NO.
I think you can use custom VF page to do that. 
Menaka RaghuvanshiMenaka Raghuvanshi
Thanks David & Sandeep

I guess I need to look at how to create custom VF page then