You need to sign in to do that
Don't have an account?
Save error: Expression must be a list type: SET<Id>
global class RollUpSummaryMapNewTest implements Database.Batchable<sObject>
{
//one map and one loop.
Map<Id,Double> optylineitem=new Map<Id,Double>();
List<Opportunity> updatelist = new List<Opportunity>();
Set<Id> OptyIds = new Set<Id>();
//List<OpportunityLineItem> oppotylineitem =new List<OpportunityLineItem>();
public Double curecy=0;
global Database.QueryLocator start(Database.BatchableContext BC)
{
String lineitem='SELECT id,ListPrice, OpportunityId FROM OpportunityLineItem';
return Database.getQueryLocator(lineitem);
}
global void execute(Database.BatchableContext BC,List<Sobject> batch)
{
List< OpportunityLineItem> Lineitemcast = (List<OpportunityLineItem>) batch;
system.debug('Cast Values'+Lineitemcast);
for(OpportunityLineItem optyrecord : Lineitemcast)
{
if(optylineitem.containsKey(optyrecord.opportunityid))
{
Double listPrice = optyrecord.ListPrice + optylineitem.get(optyrecord.opportunityid);
system.debug('List Price '+listPrice);
optylineitem.remove(optyrecord.opportunityid);
optylineitem.put(optyrecord.opportunityid, listPrice);
}else
{
optylineitem.put(optyrecord.opportunityid,optyrecord.listPrice);
}
}
system.debug('Map Values '+optylineitem.values());
}
global void finish(Database.BatchableContext BC)
{
Set<Id> optylist = new Set<Id>(optylineitem.keySet()); //need to keep in the set as it reuring any values
system.debug('Map List Values'+optylist.size());
for(Integer i=0;i<optylist.size();i++)
{
Opportunity tempstore= new Opportunity(id=optylist[i]); //Save error: Expression must be a list type: SET<Id>
tempstore.testvantage__RollupBatches__c=optylineitem.get(optylist[i]);
updatelist.add(tempstore);
}
try
{
if(updatelist.size()>0)
{
//update updatelist;
system.debug('Final List######### '+updatelist);
}
}catch(DMLException e)
{
system.debug('Batch dosent contain records'+e);
}
}
}
Hi,
Try to use below code.
Batch class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/
All Answers
You can't index into a set, but you can iterate over the set in the for loop:
If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!
-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator
Hi,
Try to use below code.
Batch class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/
Hi
In batchable class is call the async call means member variable does not share the member value,
If you want to share the member value please implement the "Database.Stateful" interface it is share member variable value
global class RollUpSummaryMapNewTest implements Database.Batchable<sObject>,Database.Stateful
{
//one map and one loop.
Map<Id,Double> optylineitem=new Map<Id,Double>();
Set<Id> OptyIds = new Set<Id>();
//List<OpportunityLineItem> oppotylineitem =new List<OpportunityLineItem>();
public Double curecy=0;
global Database.QueryLocator start(Database.BatchableContext BC)
{
String lineitem='SELECT id,ListPrice, OpportunityId FROM OpportunityLineItem limit 50000';
return Database.getQueryLocator(lineitem);
}
global void execute(Database.BatchableContext BC,List<Sobject> batch)
{
List<OpportunityLineItem> Lineitemcast = (List<OpportunityLineItem>) batch;
system.debug('Cast Values'+Lineitemcast);
for(OpportunityLineItem optyrecord : Lineitemcast)
{
if(optylineitem.containsKey(optyrecord.opportunityid))
{
Double listPrice = optyrecord.ListPrice + optylineitem.get(optyrecord.opportunityid);
system.debug('List Price '+listPrice);
optylineitem.remove(optyrecord.opportunityid);
optylineitem.put(optyrecord.opportunityid, listPrice);
}else
{
optylineitem.put(optyrecord.opportunityid,optyrecord.listPrice);
}
}
system.debug('Map Values '+optylineitem.values());
}
global void finish(Database.BatchableContext BC)
{
Set<Id> optylist = optylineitem.keySet(); //need to keep in the set as it reuring any values
system.debug('Map List Values'+optylist.size());
List<Opportunity> updatelist = new List<Opportunity>();
for(Id oppId: optylineitem.keySet())
{
Opportunity tempstore= new Opportunity(id=oppId); //Save error: Expression must be a list type: SET<Id>
tempstore.testvantage__RollupBatches__c=optylineitem.get(optylist[i]);
updatelist.add(tempstore);
}
try
{
if(updatelist!=null && updatelist.size()>0)
{
update updatelist;
system.debug('Final List######### '+updatelist);
}
}catch(DMLException e)
{
system.debug('Batch dosent contain records'+e);
}
}
}
Hi Hitesh,
Can we write the block of code in the finish method,
Actually i am trying to update the Opty object in the finish method.
Is that possible?
Regards
Sailer
yes, you can write code there..