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
    Nov 12 '14 at 7:05
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
    Nov 12 '14 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
    Nov 12 '14 at 7:13
  • which is in .NET a Dictionary. I see.
    – rpm07
    Nov 12 '14 at 7:14
  • 1
    exactly. Sorry, I'm constantly flipping between java, apex and .net. Its hard to keep it all straight.
    – NSjonas
    Nov 12 '14 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
    Nov 13 '14 at 0:46

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.