You need to sign in to do that
Don't have an account?

Nested for loops
Afternoon everyone,
So I was wondering how to approach the following situation, i've been on the platform for about a year and a half now and still learning the programming side of things.
We have a custom obj called Employment History ("EH") which looks up to Contacts (since contacts can have many "employment" records). The EH associates to specific accounts that the person has worked for. The lookup field is called Contact_LU__c and the child relationship name for the lookup is Employment_Ownership_Histories.
What I am trying to do is the following:
I made a standard controller using Account with an extension (ExtensionEHReport) which will get the data so I can show it in a VFP.
I am trying to have the controller get the current EH for the account where status = active as a list and then iterate through the list. My problem is setting criteria in for loop for the list. So I have something like the following:
Any help you can provide would be awesome. Thanks.
So I was wondering how to approach the following situation, i've been on the platform for about a year and a half now and still learning the programming side of things.
We have a custom obj called Employment History ("EH") which looks up to Contacts (since contacts can have many "employment" records). The EH associates to specific accounts that the person has worked for. The lookup field is called Contact_LU__c and the child relationship name for the lookup is Employment_Ownership_Histories.
What I am trying to do is the following:
I made a standard controller using Account with an extension (ExtensionEHReport) which will get the data so I can show it in a VFP.
I am trying to have the controller get the current EH for the account where status = active as a list and then iterate through the list. My problem is setting criteria in for loop for the list. So I have something like the following:
Account acct; public List<Employment_History__c> getEH {get; set;} public List<Employment_History__c> pastEH {get; set;} public EHReportExtension(Apexpages.standardcontroller std) { acct = (Account)std.getRecord(); getEH = [SELECT Contact_LU__c FROM Employment_History__c WHERE Account__c = :acct.Id AND Employee_Type__c ='Principal' AND Employee_Status__c = 'Active' ]; for(Employment_History__c a : getEH) { PastEH = [SELECT Account__c,Employee_Type__c,Job_Title__c,Employee_Status__c,Contact_Lu__c, Disclosure_Date__c,of_Shares_Owned__c,of_ownership__c FROM Employment_History__c WHERE <I need to set the Contact_LU__c to the value in the list above (getEH).... but it doesn't work> ]; }Now I tried using maps, but since they're unordered; I feel as if that's not the right approach, but to be honest I am uncertain about maps and sets and how to use them properly anyway.
Any help you can provide would be awesome. Thanks.
All Answers
Can you please try below code:
Set<Id> setContactId = new Set<Id>();
for(Employment_History__c a : getEH)
{
setContactId.add(a.Contact_LU__c);
}
Now use below,
PastEH = [SELECT Account__c,Employee_Type__c,Job_Title__c,Employee_Status__c,Contact_Lu__c,
Disclosure_Date__c,of_Shares_Owned__c,of_ownership__c
FROM Employment_History__c WHERE Contact_Lu__c IN : setContactId];
JANE DOE President/CEO
JANE DOE Managing Partner
JOHN DOE Treasurer
JOHN DOE Manager
How do I get my VFP to show like this:
JANE DOE
President/CEO
Managing Partner
JOHN DOE
Treasurer
Manager