+ Start a Discussion
SImmySImmy 

Please help me with Map. My business requirement is , An opportunity can have multiple invoices and I need to map the correct invoice with opportunity lineitems whose account is similar to opportunity.

Please help me with this. I'm struggling due to multiple values it's overriding the values and thus it's not updating the OLIs.
ANUTEJANUTEJ (Salesforce Developers) 
Hi Slmmy,

You can have a map with the opportunity id as the key and the list of invoices as the values so that you can store multiple values in the map for a given opportunity id.

You could something like: Map<id, List<invoices>>

In case if helped can you please choose this as the best answer so that it can be used by others in the future.

Regards,
Anutej
SImmySImmy
But there's a lookup field on Invoice for account. And if the Oli.account== OPP.account then that invoice needs to be updated on OLI. How to check on the basis of opty id that the invoice has same account as oli
ANUTEJANUTEJ (Salesforce Developers) 
To my knowledge when you fetch that particular record from I believe you should be able to get the value of the account that you are referring to in the lookup field.

After getting all the records you can certainly check the condition Oli.account== OPP.account and update only the records that satisfy the condition.
SImmySImmy
Actually I need to check like this , if(OPP.account==Oli account) { If(optymap.containskey(OPP.id) Oli.invoice=optymap.get(OPP.id) ; // this should pickup only the invoice whose invoice.account==oli.account and oli.Opportunity Id== invoice.opportunityid. } How to do this? Could you please give me a sample code for this