I am trying to add a feature by which I can update all records from a JSON payload, but the insert should only occur for those which have "archived" value = False.
below is a sample JSON. My batch job currently adds all records ,both for archived = true and false. How ever , I would like false records to be added and existing records to get updated and even change from false to true. But for any insert with archived = true , should not get added to SF.
I tried the trigger (after insert) approach to check for archived = true , but that bombed because as soon as SF found one record which matches the criteria (record 1 .. payload below), it prevented that insert , but even stopped update of sister roots (record 2) from the same payload.
Checking the archived condition in the controller class also worked for insert, but it won't update existing records from the same payload.
{
"content":[
{
"record":1,
"number":12345,
"archived":"True"
},
{
"record":2,
"number":54321,
"archived":"False"
}
]
}
content
array and leave the rest to be upserted? – Mark Pond Jul 9 '18 at 18:55Database.update(recs,false) // allowpartialsuccess
and have a validation rule that rejects an update when archived is true (you'll need a custom field for that state) – cropredy Jul 9 '18 at 19:04