Skip to main content
There is a list of products that I am trying to insert. that List contains the product name, and product description.

In order to get the Id for sucessful records i am using  Upsert Result.

 

List<Database.UpsertResult> productUpsertList = Database.upsert(productList,false); 

                    Id productId;

                    for (Database.UpsertResult ProdUpsert :                        productUpsertList ){

                         

                        if (ProdUpsert .isSuccess()) {   

                            productId = ProdUpsert .getId();

                            

But for the failed records I want to get the product description, And product Name both. 

Is there a way I can do that ?
1 answer
  1. Apr 12, 2022, 4:47 PM
    Hi Levy,

    Please follow below code:-

     

    List<Database.UpsertResult> productUpsertList = Database.upsert(productList,false); 

    Map<Id, Product> productMap = new Map<Id, Product>(productList);

                        Id productId;

                        for (Database.UpsertResult ProdUpsert :  productUpsertList ){

                             

                            if (ProdUpsert .isSuccess()) {   

      System.debug(productMap.get(ProdUpsert.getId()).Name);

    System.debug(productMap.get(ProdUpsert.getId()).Description);

    //productId = ProdUpsert .getId();

    }

    }

    if you need any assistanse, Please let me know!!

    Kindly mark my solution as the best answer if it helps you.

    Thanks

    Mukesh 
0/9000