+ Start a Discussion
Jyosi jyosiJyosi jyosi 

Map<Id,Set<Id> Syntax

Map<Id,Set<Id>> NoIFC_Product_Map= new Map<Id,Set<Id>();
Set<Id> NoIFC_Product= new set<id>();
for(product2 Products:AllProducts_Query)
            {
                if(Products.Test__c==true)
                {    
                      NoIFC_Product.add(Products.Id);
                      NoIFC_Product_Map.Put(Products.Id,NoIFC_Product);
                     for(SampleLineItemExt sliExt : sampleLineItemExtList) {
                         Sample_Line_Item__c sli = sliExt.sampleLineItem;
                if(sli.Id != null) { // Product_Number__c replaced by Product_No__c
                    if((sli.Product_No__c == null ) 
                    && (sliExt.iqty == null || sliExt.iqty.equals(''))
                    && (sli.Unit_Of_Measure__c == null || sli.Unit_Of_Measure__c.equals(''))
                    ) {
                        delSliSet.add(sliExt.sampleLineItem.Id);
                    }
                }
                if((sli.Product_No__c != null )&& (sliExt.iqty != null && !sliExt.iqty.equals('')) && (sli.Unit_Of_Measure__c != null && !sli.Unit_Of_Measure__c.equals(''))) {
                    sli.Quantity__c = Integer.valueOf(sliExt.iqty);
                    if(sli.Sample__c == null)
                       sli.Sample__c = sampleRecord.Id;
                       sli.Product_No__c=NoIFC_Product_Map.get(sli.Product_No__c); I want to access the id and get the set of ids,
I get the error  Illegal assignment from Set<Id> to Id when i use the Map.Get(Id).
Can you please help me out.
                       newSli.add(sli);
                }

Thanks

Regards,
Jyo
            }
venkat-Dvenkat-D
As per your map definition, you will get set<Id> as return value so  what you need to do is 
set<Id> temp = NoIFC_Product_Map.get(sli.Product_No__c);
Then you have to assign the value from this set to sli.Product_No__c.
Jyosi jyosiJyosi jyosi
Thanks for the reply.Can you please help me out how to assign 
sli.Product_No__c.=temp

Thanks for help

Regards,
Jyo
Mahesh DMahesh D
Hi Jyo,

Please find the corrected program.

Also added my comment whereever I modified with.

//MD - Modified
 
Map<Id,Set<Id>> NoIFC_Product_Map= new Map<Id,Set<Id>();
Set<Id> NoIFC_Product= new set<id>();
for(product2 Products:AllProducts_Query) {
	if(Products.Test__c) {    //MD - Modified
		NoIFC_Product.add(Products.Id);
		NoIFC_Product_Map.Put(Products.Id,NoIFC_Product);
		for(SampleLineItemExt sliExt : sampleLineItemExtList) {
			 Sample_Line_Item__c sli = sliExt.sampleLineItem;
			if(sli.Id != null) { // Product_Number__c replaced by Product_No__c
				if((sli.Product_No__c == null ) 
				&& (sliExt.iqty == null || sliExt.iqty.equals(''))
				&& (sli.Unit_Of_Measure__c == null || sli.Unit_Of_Measure__c.equals(''))
				) {
					delSliSet.add(sliExt.sampleLineItem.Id);
				}
			}
			if((sli.Product_No__c != null )&& (sliExt.iqty != null && !sliExt.iqty.equals('')) && (sli.Unit_Of_Measure__c != null && !sli.Unit_Of_Measure__c.equals(''))) {
				sli.Quantity__c = Integer.valueOf(sliExt.iqty);
				if(sli.Sample__c == null)
				   sli.Sample__c = sampleRecord.Id;
				   Set<Id> tempNoIFC_Prod = NoIFC_Product_Map.get(sli.Product_No__c); //MD - Modified
				   newSli.add(sli);
			}
		}
	}
}

Please do let me know if it helps.

Regards,
Mahesh
Mahesh DMahesh D
Hi Jyo,

As you are getting the set of Ids, what do you want to achieve here, if you can explain the requirement, it will be easy otherwise we can assign 0 index value into it using below:

sli.Product_No__c =  (new list<Id>(tempNoIFC_Prod) )[0] );

or else

for (Id idVal : tempNoIFC_Prod) {
        sli.Product_No__c= idVal;
        break;
}

Regards,
Mahesh
Jyosi jyosiJyosi jyosi
Thanks Mahesh,

But me need to assign the set of values to Sli.product__C=tempNoIFC_Prod  and that values to newSli list .How can this can be achevied.
Mahesh DMahesh D
Based on my understing
 
for (Id idVal : tempNoIFC_Prod) {
        sli.Product_No__c= idVal+',';
}

Regards,
Mahesh
venkat-Dvenkat-D
If Product_No__c is lookup or Master-Deatil you can not do what you are asking. If its a text field where you just want to store all possible Ids then you can use 

set<Id> temp = NoIFC_Product_Map.get(sli.Product_No__c);
for (Id idpno : temp) {
    sli.Product_No__c= idpno+',';
}
Jyosi jyosiJyosi jyosi
hello venky it's a  Master-Deatil  relation ship.

If needed how can achevie how this?

Thanks

Regards,
Jyo
Mahesh DMahesh D
Hi Jyo,

If it is Master-Details then you can assign only one value to it.
 
for (Id idVal : tempNoIFC_Prod) {
        sli.Product_No__c= idVal;
        break;
}

Regards,
Mahesh
venkat-Dvenkat-D
Can you tell your exact requirement now. I see that you are placing voth productid and map of product ids into map which might not be required for your case.
Jyosi jyosiJyosi jyosi
Hello Venky,

I have sample ,Sample_line_item object .In sample _Line item object we have a lookup relation to product2 .
There is one field test__c on product ,
suppose if the user selects prodcuts A=true,B=false,C=false, A B,C,
I need to insert A B C ,B,C in the sample_line_item. 

Thanks

Regards,
Jyo
 
venkat-Dvenkat-D
If you have lookup to Product2 on Sampleline, you can select one Product. How can you select more products..is is a junction object like you have sample as one object and product and then you have sample line item that stores prodcut and sample ?
Jyosi jyosiJyosi jyosi
IFU_DUP>>>> (01t50000002atr0AAA, 01t50000002at1TAAQ, 01t50000002at1UAAQ, 01t50000002at1YAAQ, 01t4B000000sTKMQA2, 01t50000002at1TAAQ, 01t50000002at1UAAQ, 01t50000002at1YAAQ)>>>>>> {}

LstProduct=[Select id,Name,Test__c from Product2 where Id=:IFU_DUP and BOM__c=false];
I am passing two identicals ids aganist the product ,I want the query to retun the list twice.

LstProduct=[Select id,Name,Test__c from Product2 where Id=:IFU_DUP and BOM__c=false];
            System.debug('  LstProduct>>> '+LstProduct.size()+' >>>>> '+LstProduct);

LstProduct>>> 3 >>>>>  here the list should be 6 but i am getting 3 values i know i am passing the same ids.
Is there any way the the list will loop to get all the records in the query.

Thanks for the help.

Regards,
Jyo
 
venkat-Dvenkat-D
What do you mean you want the query to return twice? Query once and you can add them to new list twive

list<Product2> duplicateProds = new list<Product2>();
duplicateProds.addall(listProd1);
duplicateProds.addall(listProd2);

But I am not sure why you need same records twice in the list.
Mahesh DMahesh D
Hi Jyo,

Can you paste the actual requirement and your exists trigger / class / vf page so that we can able to understand.

Regards,
Mahesh