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
Michele ToscanoMichele Toscano 

illegal assignment from list to list

global void execute(Database.BatchableContext BC, List Parlist) {

if(Parlist != null && !Parlist.isEmpty())
{
Map maprecTypewithId = new Map(); 
List listPARToUpdate = [select id,Name from recordType where SObjectType = 'Price_Authorization_Request__c'];
for(RecordType rec : listPARToUpdate )
{
maprecTypewithId.put(rec.Name,rec.id);
}

How can I avoid my illegal assignment of lists? Also, where would I specify a batchable size of 190?
Best Answer chosen by Michele Toscano
Amit Chaudhary 8Amit Chaudhary 8
Please update your code like below
global void execute(Database.BatchableContext BC, List<Sobject> Parlist) 
{
	if(Parlist != null && !Parlist.isEmpty())
	{
		Map<string,id> maprecTypewithId = new Map<string,id>(); 
		
		for(RecordType rec : [select id, DeveloperName from recordType where SObjectType = 'Price_Authorization_Request__c'])
		{
			maprecTypewithId.put(rec.DeveloperName,rec.id);
		}
	}
}
Let us know if this will help you
 

All Answers

KapilCKapilC
Hi Michele,

Your are defining list and map in a wrong manner so update your code as below.
global void execute(Database.BatchableContext BC, List Parlist) {
	if(Parlist != null && !Parlist.isEmpty()){
		Map<string,id> maprecTypewithId = new Map<string,id>(); 
		for(RecordType rec : [select id,Name from recordType where SObjectType = 'Price_Authorization_Request__c']){
			maprecTypewithId.put(rec.Name,rec.id);
		}
	}
}
And for creating and executing batch classes please refer this link (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm).

[If you got answer from my post please mark it as solution.]

Thanks,
Kapil
(forcecube@gmail.com)
Michele ToscanoMichele Toscano
It gives me a variable does not exist: rec.Name Regards, Michele Toscano Senior Applications Specialist Cabot Corporation Office: (678) 297-1455
KapilCKapilC
global void execute(Database.BatchableContext BC, List Parlist) {
	if(Parlist != null && !Parlist.isEmpty()){
		Map<string,id> maprecTypewithId = new Map<string,id>(); 
		for(RecordType rec : [select id, DeveloperName from recordType where SObjectType = 'Price_Authorization_Request__c']){
			maprecTypewithId.put(rec.DeveloperName,rec.id);
		}
	}
}
Hi Michele,
Although name shouldn't be cause of the error but you can use developername instead. Please try this. Let me know if problem still persists.

Thanks,
Kapil
(forcecube@gmail.com)
 
Amit Chaudhary 8Amit Chaudhary 8
Please update your code like below
global void execute(Database.BatchableContext BC, List<Sobject> Parlist) 
{
	if(Parlist != null && !Parlist.isEmpty())
	{
		Map<string,id> maprecTypewithId = new Map<string,id>(); 
		
		for(RecordType rec : [select id, DeveloperName from recordType where SObjectType = 'Price_Authorization_Request__c'])
		{
			maprecTypewithId.put(rec.DeveloperName,rec.id);
		}
	}
}
Let us know if this will help you
 
This was selected as the best answer
Michele ToscanoMichele Toscano
Yes, I no longer receive that error.