You need to sign in to do that
Don't have an account?
Developer99
Duplicate id in list
HI,
In my service it showing that an error for products Upsert
Map<string,Product2> existpccMap = new Map<string,Product2>();
set<string> pCodeSet = new set<string>();
for(integer k = 0;k<req.accounts.size(); k++){ // ONCE CHECK IT
for(integer j=0;j<req.accounts[k].prods.size();j++)
{
pCodeSet.add(req.accounts[k].prods[j].pCode);
}
(Product2 p2 : [select id,productCode from Product2 where ProductCode IN : pCodeSet]) {
existpccMap.put(p2.productCode,p2);
}
for(integer j=0; j< req.accounts[k].prods.size(); j++) {
if (existpccMap.containsKey(req.accounts[k].prods[j].pCode)) {
p = existpccMap.get(req.accounts[k].prods[j].pCode);
} else {
p = new Product2();
}
p.productCode = req.accounts[k].prods[j].pCode;
p.name =req.accounts[k].prods[j].pName;
pList.add(p);
}
}
Database.upsert(pList); // Error Occur Point May i know what i have to do.
In my service it showing that an error for products Upsert
Map<string,Product2> existpccMap = new Map<string,Product2>();
set<string> pCodeSet = new set<string>();
for(integer k = 0;k<req.accounts.size(); k++){ // ONCE CHECK IT
for(integer j=0;j<req.accounts[k].prods.size();j++)
{
pCodeSet.add(req.accounts[k].prods[j].pCode);
}
(Product2 p2 : [select id,productCode from Product2 where ProductCode IN : pCodeSet]) {
existpccMap.put(p2.productCode,p2);
}
for(integer j=0; j< req.accounts[k].prods.size(); j++) {
if (existpccMap.containsKey(req.accounts[k].prods[j].pCode)) {
p = existpccMap.get(req.accounts[k].prods[j].pCode);
} else {
p = new Product2();
}
p.productCode = req.accounts[k].prods[j].pCode;
p.name =req.accounts[k].prods[j].pName;
pList.add(p);
}
}
Database.upsert(pList); // Error Occur Point May i know what i have to do.
Use Map instead of List and update the map values values.
Thanks
ShaT
I tried By using set, at that time i am geeting an error
soapenv:ClientSystem.ListException: List index out of bounds:
the error where i am getting is----->>
for(integer j=0; j< req.accounts[k].prods.size(); j++) { Error occuring point
if (existpccMap.containsKey(req.accounts[k].prods[j].pCode)) {
p = existpccMap.get(req.accounts[k].prods[j].pCode);
} else {
p = new Product2();
}
p.productCode = req.accounts[k].prods[j].pCode;
p.name =req.accounts[k].prods[j].pName;
pset.add(p);
pList.addAll(pset);
}
}