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
Sascha DeinertSascha Deinert 

Merging two lists into one


I have two different lists. A list of opportunities and a list of sales (Umsatz__c), the accountid appears in both lists. How can I merge these lists into one finallist at account level?

public class VTPv1 {       
    Public List<AggregateResult> OppGroup {get; set;}
    Public List<AggregateResult> SalesGroup {get; set;}
    public VTPv1() {          
        OppGroup    = [SELECT Account.Name AccName, Sum(ExpectedRevenue) Rev, Sum(Amount) Fin FROM Opportunity WHERE OwnerId = '005b0000001UAm4AAG' AND CloseDate = THIS_YEAR AND (IsClosed = false OR IsWon = true) GROUP BY Account.Name];
        SalesGroup  = [SELECT Einzelrisiko__r.Gruppenvertrag__r.Unternehmen__r.Name AccName, Sum(BWS_Brutto__c) BWS FROM Umsatz__c WHERE Berater__r.Id = '005b0000001UAm4AAG' AND Bewertungsmonat__c = THIS_YEAR GROUP BY Einzelrisiko__r.Gruppenvertrag__r.Unternehmen__r.Name];          
<apex:page controller="VTPv1">        
    <apex:pageBlock title="Opportunities Group">
        <apex:pageBlockTable value="{!OppGroup}" var="oppg">  
            <apex:column value="{!oppg['AccName']}">
                <apex:facet name="header">Account Name</apex:facet>
            <apex:column value="{!oppg['Rev']}">
                <apex:facet name="header">Expected Revenue</apex:facet>
            <apex:column value="{!oppg['Fin']}">
                <apex:facet name="header">Amount</apex:facet>
    <apex:pageBlock title="Sales Group">
        <apex:pageBlockTable value="{!SalesGroup}" var="salesg">  
            <apex:column value="{!salesg['AccName']}">
                <apex:facet name="header">Account Name</apex:facet>          
            <apex:column value="{!salesg['BWS']}">
                <apex:facet name="header">Sales</apex:facet>