You need to sign in to do that
Don't have an account?
trikku
How To delete the Account Related contacts Through "DELETECONTACT" Button on Account page
Hai,
I added a button "DELETECONTACT" to Account page. if i click on "DELETECONTACT" Button then i want to delete the conatcts assosiated with that account.using Ajax..Is there any help
Thanks in advance
Hi,
Try the below code snippet as reference:
Code on custom button of the account object
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js")}
sforce.connection.sessionId="{!$Api.Session_ID}";
var confirmation1=confirm('do you want to delete contact');
if(confirmation1)
{
var returnstring=sforce.apex.execute("deletecontact","deletecon",{evntid:"{! Account.Id }"});
window.location.reload();
}
------------ Apex Controller ------------------
global class deletecontact
{
webservice static void deletecon(string accountid1)
{
list<contact> con=[select id from contact where accountid=:accountid1];
if(con.size()>0)
{
delete con;
}
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Hi,
Try the below code snippet as reference:
Code on custom button of the account object
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js")}
sforce.connection.sessionId="{!$Api.Session_ID}";
var confirmation1=confirm('do you want to delete contact');
if(confirmation1)
{
var returnstring=sforce.apex.execute("deletecontact","deletecon",{evntid:"{! Account.Id }"});
window.location.reload();
}
------------ Apex Controller ------------------
global class deletecontact
{
webservice static void deletecon(string accountid1)
{
list<contact> con=[select id from contact where accountid=:accountid1];
if(con.size()>0)
{
delete con;
}
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thank u Ankit for your Valuble Time..
with little changes it works nicely
Hai Navthar,this works fine..
but I want this "DELETECONTACT" button works without class..can we write the query with in the button funcionalty without class..
Thanks in Advance..