Timeline for updating a records using external Id in Apex
Current License: CC BY-SA 4.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 16, 2023 at 22:18 | history | edited | Arthlete | CC BY-SA 4.0 |
edited body
|
Jun 5, 2018 at 2:17 | comment | added | SfdcBat | Is there a chance that you can let me know how this can work when a new Product is created and I want to copy that to Foo. salesforce.stackexchange.com/questions/220105/… | |
Jun 1, 2018 at 21:12 | vote | accept | SfdcBat | ||
Jun 1, 2018 at 16:53 | history | edited | Gareth Jordan | CC BY-SA 4.0 |
check the key doesn't already exist
|
Jun 1, 2018 at 16:51 | comment | added | Gareth Jordan | It should work, you just need to do a check on the key of the map to ensure it doesn't exist, made the change in the code | |
Jun 1, 2018 at 15:36 | comment | added | SfdcBat | It's from the first upsert call.. Yes , the product records are looped in this order - paretn1 , parent 2, child 1(parent1),child2(parent1). So the Map's value gets duplicate parent1, I can make it as a set to remove the duplicates and then covert to a list to upsert..but if the parent record already exist in foo__c , would the above approach work? I am covering a scenario where the child1 may be reparented to parent2.. | |
Jun 1, 2018 at 15:31 | comment | added | Gareth Jordan | Was that from the first update call or the second also is it possible that there are multiple child records for the parent product? Also is there a name for the Parent record that's created? | |
Jun 1, 2018 at 15:16 | comment | added | SfdcBat |
thanks... I get this error when trying the approach - System.DmlException: Upsert failed. First exception on row 0; first error: DUPLICATE_VALUE, Duplicate external id specified: genwatt diesel 200kw: [Externald__c] . It seems like it is trying to insert an existing record?
|
|
Jun 1, 2018 at 14:37 | history | edited | Gareth Jordan | CC BY-SA 4.0 |
added 1351 characters in body
|
Jun 1, 2018 at 13:35 | comment | added | SfdcBat | that worked.... I am trying to use the self lookup relationship on foo object also( Update my code). I hit a null pointer exception when I try to update with the parent's external Id. | |
Jun 1, 2018 at 13:18 | history | answered | Gareth Jordan | CC BY-SA 4.0 |