You need to sign in to do that
Don't have an account?
Save error: Method does not exist or incorrect signature: [MAP<Id,Double>].ketSet() in Batch APEX
Hi Everyone,
I wrote the code where i am able to store the id and another value in the MAP ,By using list i need to access the values and update the price in the Opportunity
Below is the code.
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>();
//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';
System.debug('The Query@@@@@@@@'+lineitem);
return Database.getQueryLocator(lineitem);
}
global void execute(Database.BatchableContext BC,List<Sobject> batch)
{
List< OpportunityLineItem> Lineitemcast = (List<OpportunityLineItem>) batch;
for(OpportunityLineItem optyrecord : Lineitemcast)
{
if(optylineitem.containsKey(optyrecord.opportunityid))
{
Double listPrice = optyrecord.ListPrice + optylineitem.get(optyrecord.opportunityid);
optylineitem.remove(optyrecord.opportunityid);
optylineitem.put(optyrecord.opportunityid, listPrice);
}else
{
optylineitem.put(optyrecord.opportunityid,optyrecord.listPrice);
}
}
}
global void finish(Database.BatchableContext BC)
{
List<Double> optylist = new List<Double>(optylineitem.values());
system.debug('Map List Values'+optylist);
for(Integer i=0;i<optylist.size();i++)
{
Opportunity tempstore= new Opportunity();
tempstore.id=optylineitem.keySet().get(optylineitem.Id);
tempstore.testvantage__RollupBatches__c=optylineitem.get('Double');
updatelist.add(tempstore);
}
try
{
if(updatelist.size()>0)
{
system.debug('Final List######### '+updatelist);
}
}catch(DMLException e)
{
system.debug('Batch dosent contain records'+e);
}
}
}
Thanks for teh help
Hi,
Try to use following code for your requirement.
Batch Apex:
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 Hitesh,
I got that fixed but i am getting another variable form the map how is possible to assign
Thanks for the help.
Hi,
Try to use below line instead.
Hi Hitesh,
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);
}
}
}
Can you please help me out how to set the values
Hi,
try to use below code.