Search code examples
listdictionarysalesforcesoql

map with list as value in SOQL


I'm working on a small project in Salesforce where a customer can be the master in a master-detail relationship to more than a single project object. Projects have a currency 'Max_Budget__c' and what I want to do is calculate the max budget per customer by adding the Max_Budget__c per project. This means that I need to collect a List per customer but also need customer stored so I can update the Max_budget__c object of it. I was thinking about storing it in a Map with Customer__c as key and Set as value, But I'm not sure how to do this in a single SOQL Query or if i'm even looking in the right direction. Any ideas? Thanks in advance


Solution

  • Let suppose you have multiple projects like project1, project2 etc .

    Each has many to one relationship with customer.

    i.e many project1 records to single customer record.

    many project2 records to single customer record and so on.

    so each customer would have many project1 records,project2 records etc..

    To calculate max budget per customer you need to calculate max budget from all project1 records,max budget from all project2 records etc..from each customer and add.

    So the requirement is simple write a roll up summary on each child(each project) and add all roll up summaries into a custom field.

    I hope this will help you or please let me know if anything else needed.

    Regards,

    Naveen

    Automated deployments , Dataloader , Sandbox back-ups, test automation for Salesforce applications