Opportunity records fields compareing with custom metadata record and based on values match opportunity stagename will update but it is not working and gettin error in apex job also that duplicate id in list : 006M00011bEasQQ
here is the screenshot of record
Below is the custom metadata record
Above record have country usa , type new customer , lead source phone inquiry and that same value is matching with custom metadata record in that case opportunity stagename should be update with custom metadata record which is qualification but it is not working. opportunity stage is still prospecting.
below is the code
global class updatestageBatch implements Database.batchable<sobject>,database.stateful{
string query;
List<Opportunity> oppUdateList = new List<Opportunity>();
String country;
String type;
String leadSource;
String stage;
global database.queryLocator start(database.BatchableContext bc){
query = 'select id, stagename,country__c,LeadSource,type from opportunity';
return database.getQueryLocator(query);
}
global void execute(database.BatchableContext bc, List<Opportunity> scopeOfOpp){
Map<String,updateStageMetadata__mdt> meta = updateStageMetadata__mdt.getAll();
for(String str : meta.keyset()){
country = meta.get(str).Country__c;
type = meta.get(str).Type__c;
leadSource = meta.get(str).Lead_Source__c;
stage = meta.get(str).Stage__c;
for(Opportunity opp : scopeOfOpp){
Opportunity op = new Opportunity();
op.id = opp.id;
if(opp.Country__c == country && opp.Type == type && opp.leadSource == leadSource){
op.StageName = stage;
} else{
op.StageName = 'Closed Lost';
}
oppUdateList.add(op);
}
}
if(oppUdateList != null){
database.update(oppUdateList,false);
}
}
global void finish(database.BatchableContext bc){}
}
getAll
for Custom Metadata without telling us? Last I heard that method was unavailable.