-8

HI I wrote the webservice i am updating the field in quote object field based upon the opportuntiy field but it showing an error FATAL_ERROR|System.ListException: Duplicate id in list

Error occur Line------->>>> qtobj1.StageName = 'Closed Won'; oppitemlist.add(qtobj1); update oppitemlist; // ERROR LINE

   global class OrderUpdate
{
 }
 global class Inputcomb{

webservice String tax;
webservice String stagename;
}
global class ResponseClass{

 webservice static ResponseClass myMethod3(RequestClass1 req1)
   {     

  map<id,Opportunity> oppitemmap=new map<id,Opportunity>([select Name  from Opportunity  where id In:idlist1]);
   if(oppitemmap!=null){

         {
             if (qtobj1!=null){

           qtobj1.Name=icobj1.ordId;
           qtobj1.Amount = Decimal.valueOf(icobj1.amt);
           String[] str = icobj1.ordcdate.split(' ');
          String[] dts = str[0].split('/');
          Date myDate = date.newinstance(Integer.valueOf(dts[2]), Integer.valueOf(dts[0]), Integer.valueOf(dts[1]));
           qtobj1.CloseDate = myDate; 
            oppitemlist.add(qtobj1);
             } } }
    try{
  update oppitemlist;
  res.resoppId =qtobj1.Id;
  res.status = 'Success';
  }catch(exception e){
   res.status = 'Fail';
   }

    integer cnt = req1.inputcombList.size(); // to count the total size of the respose array
   for(integer i = 0; i< cnt; i++)
   {

     List<Quote__c>  quotes; // creating the object of quote
    quotes = [SELECT Id,Tax__c,Shipping_Cost__c FROM Quote__c WHERE Opportunity__c = :req1.inputcombList[i].oppId]; // selecting the quote details by qoute id
   if(quotes.size()>0)
   {
    quotes[i].Tax__c = Decimal.valueOf(req1.inputcombList[i].tax);// setting the values
    //quotes[i].GrandTotal__c = Decimal.valueOf(req1.inputcombList[i].Amt); // setting the values
    quotes[i].Shipping_Cost__c = Decimal.valueOf(req1.inputcombList[i].sCost);
    quotes[i].StageName__c = req1.inputcombList[i].stagename;
    if(req1.inputcombList[i].stagename == 'Ordered')
    {
      qtobj1.StageName = 'Closed Won';
       oppitemlist.add(qtobj1);
       update oppitemlist;
    }
    else
    {
      qtobj1.StageName = 'Closed Lost';
      oppitemlist.add(qtobj1);
      update oppitemlist;
     }

    try{
        update quotes; // updating the quote
    }catch(exception e){  system.debug('Error : updating tax for quote line items ' + quotes); }  // throwing error message

  } }  }  // End Of If Loop  }
     return res;       
   }

   } 
12
  • 7
    You know Sathya, I was writing up a long answer to your last question that you posted about this. I was just about to submit it when you deleted it. You should have kept that original question because now I wasted almost 20 minutes of my time writing up an answer for you... Anyway, please take some time to learn more about Apex - salesforce.com/us/developer/docs/apexcode/Content/… - You have nested SOQL queries and DML statements inside for loops. There is other stuff, but I am not writing up another answer for it. Commented Jun 18, 2014 at 12:17
  • 7
    No I can't. I am not sure why you deleted your question just to repost it again, but that is not how this site works. You have been here long enough now (having 70+ questions asked), you should know better. Please take some time to learn how the site works - salesforce.stackexchange.com/tour Commented Jun 18, 2014 at 12:23
  • 6
    I think you should take @JesseAltman's advice, and could not agree more. In order to get the people in this community to help, you really should take some time to learn the do's and don'ts of the community. People take time out of their busy schedules to answer these questions, and if they feel like their time is wasted or it is unappreciated, they will start to ignore questions from particular people. Really try to learn some of the rules of the road and general etiquette. Deleting a question, just to repost it, so it shows up as a new question, is a prime example of what NOT to do. Commented Jun 18, 2014 at 12:29
  • 5
    Sathya, there's a point at which "give me code" no longer motivates people to do that. A lot of users are very motivated to share knowledge, guide and teach others how to solve problems. That's how we've all learned. But when you show no interest in learning, but only in code ... consider hiring a skilled developer. Commented Jun 18, 2014 at 12:47
  • 3
    Just repeatedly asking for the specific code to complete you work, and not even apologising when your actions have put another contributor out is pretty poor SE etiquette too IMO. Luckily I personally keep an "awareness" of questions sources myself... Commented Jun 18, 2014 at 12:48

1 Answer 1

1

Duplicate question to Duplicate id in list

Anyways, you are adding the same Opportunity to the oppitemlist List

Create another List oppUpdateItemList

Replace oppitemlist.add(qtobj1); with oppUpdateItemlist.add(qtobj1);

Note: Use update outside loop or simply use "Update qtobj1;" instead of adding it to a List.

4
  • can you give me some code how to modify the error .
    – Sathya
    Commented Jun 18, 2014 at 12:20
  • 2
    If you are just interested in removing the error then replace these 2 lines in your code oppitemlist.add(qtobj1); update oppitemlist; with update qtobj1; And if you are interested in properly coding then kindly follow @JesseAltman's comment. I was about to post my answer to your previous question when you deleted it. Now I'm not gonna do that. So I've only given the important points.
    – A-d
    Commented Jun 18, 2014 at 12:27
  • 3
    I think you should take @JesseAltman's advice. In order to get the people in this community to help, you really should take some time to learn the do's and don'ts of the community. People take time out of their busy schedules to answer these questions, and if they feel like their time is wasted or it is unappreciated, they will start to ignore questions from particular people. Really try to learn some of the rules of the road and general etiquette. Deleting a question, just to repost it, so it shows up as a new question, is a prime example of what NOT to do. Commented Jun 18, 2014 at 12:27
  • @A-d i update th code as per you r suggestions but it is not working..
    – Sathya
    Commented Jun 18, 2014 at 12:53

Not the answer you're looking for? Browse other questions tagged .