I would like to create a child record for the most recently created record in a list. Currently there would only be the possibility of one of the potential parents existing, so I was using a simple query to pull that one and create a child for it. But now, there is a potential of multiple types of the potential parent existing, and I would like to create a child for just the latest one created.
Here is the portion of my current code which is producing this list :
List<Client_Project__c> lstCP = new List<Client_Project__c>([Select c.Sales_Leader__c, c.Related_Opportunity__c, c.Project_Type__c,
c.Project_Status__c, c.Project_Scope__c, c.Name, c.Lead_Country__c, c.Account__c, c.Account__r.Name
From Client_Project__c c Where c.Account__c in : setAccIds AND c.Related_Opportunity__c in :setOppIds]);
Could I accomplish this by just doing an Order By on the objCP query and just doing a Limit 1 return ? Would that produce the most recently created record in that query ?
Thank you very much for your help and time.