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
ANAMIKA MONDAL 8ANAMIKA MONDAL 8 

please help getting the list

I've written below snippet..  but getting error as 'Method does not exist or incorrect signature: void get(Id) from the type List<Line_Item__c>'


List<Line_Item__c>  liness = [Select Id,Order_c,status__c from Line_Item__c where Order_c in :orderss];
Map<ID, List<Line_Item__c>> connection = new Map<ID, List<Line_Item__c>>();
 for (Line_Item__c lii : liness)
    {
     connection.put(lii.Order_c, liness.get(lii.id)); 
    }


Need to get a list<Line_Item__c> from liness while putting the value into map.
sales force 48sales force 48
Hi Anamika,

Aparently the get method takes only the integer value .

Regards,
Srikanth U.
ANAMIKA MONDAL 8ANAMIKA MONDAL 8
yea thats right.. is there any way i can get the List<Line_Item__c> from liness as i need to put that in a map. that i can get a list of line itemms when ever we put the order id as key.
sravan velamasravan velama
Hi Anamika,

You can do it like this 

for(Line_Item__c lil : [select  Id,Order_c,status__c from Line_Item__c where Order_c in :orderss]) {
 if(connection.isEmpty()){
   connection.put(lil.Order__c, new List <Line_Item__c> {lil});
}
}
Amit Chaudhary 8Amit Chaudhary 8
Please update your code like below
List<Line_Item__c>  liness = [Select Id,Order_c,status__c from Line_Item__c where Order_c in :orderss];

Map<ID, List<Line_Item__c>> connection = new Map<ID, List<Line_Item__c>>();

for (Line_Item__c lii : liness)
{
	if(connection.containsKey(lii.Order_c))
	{
		List<Line_Item__c> lstLi = connection.get(lii.Order_c);
		lstLi.add(lii);
	}
	else
	{
		List<Line_Item__c> lstLi = new List<Line_Item__c>();
		connection.put( lii.Order_c, lstLi );
	}
}

Let us know if this will help you