Is there a way to output a specific value in an list object of a list? I tried this but getting the range just returned int, so I can't actually returned an object.

List<SaveResult> allSaveResult = new List<SaveResult>();
allSaveResult.InsertRange(0, SfdcBinding.update(oppList.ToArray()));
allSaveResult.InsertRange(1, SfdcBinding.update(pHUpdateList.ToArray()));
allSaveResult.InsertRange(2, SfdcBinding.create(pHCreateList.ToArray()));

for (int i = 0; i < allSaveResult.Count; i++)
    Console.WriteLine("opps {0}", allSaveResult.GetRange(0, i));

I want to get some value, inside the oppList, pHUpdateList, pHCreateList. For instance, there is a field name from all of this object (Opportunity and PH). I can do this in a single Object. Like this:

SaveResult[] oppSaveResult = SfdcBinding.create(oppList.ToArray());
for (int i = 0; i < oppSaveResult.Count; i++)
    Console.WriteLine("opps {0} - {1}", oppList[i].Id, oppSaveResult[i].Id );

The problem is I'm updating and creating not only in one Object but two. I'm thinking it's more efficient if I put them in one List<SaveResult> and get the result at the same time iterate the records in each List I added in the List<SaveResult> like: oppList[i].Id, pHUpdateList[i].Opportunity__c, and pHCreate[i].Opportunity__c.

My Objective is to get all of the Opportunity Id in all of the children list under List<SaveResult>, since I just learned that the order of elements in oppList is the same order you have in SaveResult.

  • I'm a bit confused. You want all the Opportunity Id's from the SaveResults? Since you are doing an update on the opportunities you already have all the Ids in oppList. Do you also want the Ids for the ph records that were updated and created. – Daniel Ballinger Nov 16 '14 at 22:28
  • @DanielBallinger Yes! I want the id of opportunity in ph, since ph is related to opportunity which means it has an opportunity id also that being reference to it. and I also need the SaveResult to get the ids of those that being successfully updated and created. – rpm07 Nov 17 '14 at 0:41

It seems that all the Opportunity Id's you want are already in the input sObjects and hence the SaveResults are irrelevant.

Just loop through the inputs and capture the Ids.

HashSet<string> opportunityIds = new HashSet<string>();

oppList.ForEach(x => opportunityIds.Add(x.Id));
pHUpdateList.ForEach(x => opportunityIds.Add(x.Opportunity__c));
pHCreate.ForEach(x => opportunityIds.Add(x.Opportunity__c));

// opportunityIds now contains the Set of all distinct Ids across the three collections
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.