function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
aressaress 

vf remoting

Create a new link on the contact row to delete the contact from the account. On clicking the link, the contact should be deleted this time using VisualForce Remoting. On successful deletion, an alert should be displayed on the page stating “The contact has been deleted”.
Best Answer chosen by aress
Nitin ShyamnaniNitin Shyamnani
Hi Ayisha,

You need to create an Apex class and add this method:

@RemoteAction
global static Boolean updateContact(String conId) {
        try{
             contact con = new contact(AccountID = null, ID = conId);
              update con;          
              return true;
        }
        catch(Exception){
              return false;
         }
}

You can call this method using "Visualforce.remoting.Manager.invokeAction" and pass the contact ID to remove the accountId, and you will get result true if successfully deleted or false in case of any issue.

Here is the link for example of VF Remoting: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_example.htm

Thanks,
Nitin

All Answers

Shruti SShruti S
At first, would you be able to tell us how you would be displaying the Account and Contacts ?
suryansh guptasuryansh gupta
use vf remoting and update the contact 

Contact.AccountId = null;
Update contact;


and use https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_example.htm 
for remoting.
Nitin ShyamnaniNitin Shyamnani
Hi Ayisha,

You need to create an Apex class and add this method:

@RemoteAction
global static Boolean updateContact(String conId) {
        try{
             contact con = new contact(AccountID = null, ID = conId);
              update con;          
              return true;
        }
        catch(Exception){
              return false;
         }
}

You can call this method using "Visualforce.remoting.Manager.invokeAction" and pass the contact ID to remove the accountId, and you will get result true if successfully deleted or false in case of any issue.

Here is the link for example of VF Remoting: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_example.htm

Thanks,
Nitin
This was selected as the best answer