You need to sign in to do that
Don't have an account?
Abhi_Tripathi
How to delete child contact records of a parent Account Record USING SOQL QUERY.
hey,
I am trying to delete contacts (Child records) of an Account, but only when i remove the LastName(Mandatory field) of a contact record.
Actually i have visualforce page where LastName field of Contact is an input field, if user wants to update he can change the LastName and the record will be Updated...this thing is happening in my code
BUT trying to delete the records by removing the LastName and leaving it BLANK...Thats not happening.
Regards
Abhi Tripathi
Hi,
First get all the contact then apply select to that list.
Check the below example.
for(Contact con : conRecords){
if(con.LastName == null && con.LastName == ''){
DeleteContactsList.add(con);
}
}
if(DeleteContactsList.size() > 0){
system.debug('$$$$$ DeleteContactsList' + DeleteContactsList);
delete DeleteContactsList;
}
Regards,
All Answers
LastName is a required field on Contact record, hence you can not keep it blank.
You can keep one CheckBox field and based on that field value execute a apex method for deleting contact records.
Thanks,
Devendra
Thanks for the Reply sir...
but i have created that LastName field into an InputFiels on the vf page, that thing was happening but in a wrong manner, when i leave that LastName field blank other then that oll the child contact records were deleted.
so i think this can be done...but donno how..!!
Can you please explain the scenario?
Thanks,
Devendra
This is the code which i am trying to execute...if the user edits the LastName of the Contact and leave it blank then after click of a button the records of child contact will be deleted from the database.
for(Contact con : conRecords){
if(con.LastName == null && con.LastName == ''){
DeleteContactsList.add(con);
}
i f(DeleteContactsList.size() > 0){
system.debug('$$$$$ DeleteContactsList' + DeleteContactsList);
delete DeleteContactsList;
}
}
Why you are navigating to all the contact record using "conRecords" ?
Thanks,
Devendra
i am Navigating oll the child contacts only...i have provided you only the required code...not the whole thing..the conRecords is the only child contact list of an account.
thanks
Hi,
First get all the contact then apply select to that list.
Check the below example.
for(Contact con : conRecords){
if(con.LastName == null && con.LastName == ''){
DeleteContactsList.add(con);
}
}
if(DeleteContactsList.size() > 0){
system.debug('$$$$$ DeleteContactsList' + DeleteContactsList);
delete DeleteContactsList;
}
Regards,
for(Contact con : conRecords){
if(con.LastName == null || con.LastName == ''){
DeleteContactsList.add(con);
}
}
if(DeleteContactsList.size() > 0){
system.debug('$$$$$ DeleteContactsList' + DeleteContactsList);
delete DeleteContactsList;
}
~KR