You need to sign in to do that
Don't have an account?
Xav Theo 4
List of parent IDs for which all related child records are closed
Hi all - We need to query a list of parent IDs for which all related record have a status = closed. In our case, the parent object is Contact and children are a Custom Object. Once we have the list we'll update a field on the Contact.
Can someone help with the SOQL query / list part?
Thanks!
Can someone help with the SOQL query / list part?
Thanks!
If you ONLY want the list of parent IDs for which related record have status closed :
Hope this helps you!
Thanks
Ishita
All Answers
Please check once below sample code :
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
If you ONLY want the list of parent IDs for which related record have status closed :
Hope this helps you!
Thanks
Ishita
Please refer the below code:-
public class UpdateContacts
{
public static void updatemethod()
{
List<Customobj__c > objlist=[SELECT Status__c,Contact__c from Customobj__c where Status__c='Closed'];
set<id> contactid=new set<id>();
for(Customobj__c c:objlist)
{
contactid.add(c.Contact__c);
}
List<Contact> newconlist=new List<Contact>();
List<Contact> contactlist=[SELECT LastName,Status__c from Contact where Id In:contactid];
for(Contact con:contactlist)
{
con.Status__c='updated';
newconlist.add(con);
}
update newconlist;
}
}
I hope this code helps you.
Customobj__c is my custom object and status__c(picklist) its field.
Also, I create a field on contact Status__c(Text). when Customobj__c field Status is getting closed then contact status will be updated.
You can add your field as you want.
Please mark it as best answer if it helps you.
Thank You,
Ajay Dubedi