0

Is there a way to make this one? I want to get the result for successful and failed records, however I updated not the one object but two, and one of the object (Ph) has update records and create records.

SaveResult[] saveOppUpdatedResultList = SfdcBinding.update(oppList.ToArray());
SaveResult[] savePhUpdatedResultList = SfdcBinding.update(pHUpdateList.ToArray());
SaveResult[] savePhCreatedResultList = SfdcBinding.create(pHCreateList.ToArray());

I want this to put it in one variable, and get the results depend if saveOppUpdatedResultList or savePhUpdatedResultList or savePhCreatedResultList.

1
  • Please update your question to be more specific. It is a bit ambiguous and vague.
    – NSjonas
    Commented Nov 12, 2014 at 7:05

2 Answers 2

4

If you just want all the results in a single variable you could create a List and use the addRange method.

List<SaveResult> allSavedResults = new List<SaveResult>();
allSavedResults.addRange(SfdcBinding.update(oppList.ToArray()));
allSavedResults.addRange(SfdcBinding.update(pHUpdateList.ToArray()));
allSavedResults.addRange(SfdcBinding. create(pHCreateList.ToArray()));

You can then iterate over each saved result in a single loop

foreach(SaveResult result in allSavedResults){
    // do things with the results
}
4
  • what if you want them to categorize by object name? For example, records for Opportunity and records for Projection History.
    – rpm07
    Commented Nov 12, 2014 at 7:11
  • 1
    @robertpeter07 then you would want to create a Map<String,List<SaveResult>> where each key is the object API name and each value is a list of save results
    – NSjonas
    Commented Nov 12, 2014 at 7:13
  • which is in .NET a Dictionary. I see.
    – rpm07
    Commented Nov 12, 2014 at 7:14
  • 1
    exactly. Sorry, I'm constantly flipping between java, apex and .net. Its hard to keep it all straight.
    – NSjonas
    Commented Nov 12, 2014 at 7:20
1

You could reduce your API calls by using the upsert method to combine the creation and updates for the Ph records.

You can also use an external Id field to avoid looking up the Salesforce ID for the records.

1
  • I will do your suggestion after we make the program we are developing to run successfully. For now we are up to making it works, later we optimize and refactor its codes.
    – rpm07
    Commented Nov 13, 2014 at 0:46

You must log in to answer this question.

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