I am having one req.

I am having 1 opportunityLineItem standard objects. It has 3 fields-Product_c, MType_c(Picklist) and MFactor__c(Percent).

I am having another object Config object. It has also same 3 fields similar to opportunityLineItem object.

So when user comes to OppLineitem and insert/update any line item by changing the its media type value, it will check following thing

If (chosen media type from line and media type from config obj matches) and (product from opplineitem and product from config obj matches) then assign config_c.MFactor_c to Opportunitylineitem.MFactor__c

This what I have done.

I have written a trigger with before insert and before update events.

Done all the bulkification.

and storing in Map.

Map<String,Map<String,Config__c>> mtfcMap = new Map<String,Map<String,Config__c>>();

        for(Media_Type_Factor_Config__c mtfc : [
                                                    SELECT MType__c,
                                                    FROM Config__c 
                                                    WHERE Product__c IN :prodSet     
                                                    AND MType__c IN : mediaTypeSet
            if(mtfcMap.get(mtfc.MType__c) == null){
                mtfcMap.put(mtfc.MType__c, new Map<String, Config__c>{mtfc.Product__c => mtfc});


//Now Processing all incoming opplineitem request

        for(OpportunityLineItem oppli : Trigger.New){
            //Here I have to use mtfcMap and write my logic

Any help???

Basically If it was a single map collection then I'd have done it, but here we are using Map inside Map so facing difficlty.


You can just use the standard Map methods of containsKey and get twice.

string mType = 'foo'; // Can you get this value from the OpportuntiyLineItem?
if(mtfcMap.containsKey(mType)) {
    Map<string,Config__c> innerMap = mtfcMap.get(mType);
    string oliProduct = 'bar'; // Can you get this value from the OpportunityLineItem?
    if(innerMap.containsKey(oliProduct)) {
        Config__c configForOli = innerMap.get(oliProduct);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.