I have an object called objC which has a key field that is a Text(255) (Unique Case Insensitive) It's composed of objA.Id + objB.Id. Now ObjC has a field called value wherein it should be updated whenever an ObjC record is being created wherein it's key value is already existing. Meaning there is already an ObjC existing that uses that key.

The issue that I'm facing is that In my trigger, it's not updating the existing ObjC record since based on the Apex order of execution it will run System Validation before any record is updated/saved. Is there any way to bypass this issue? Or a better approach for me to check the unique key value wherein it will hinder the insertion of the New ObjC record that uses a key that is existing and it will update the value field of the existing ObjC record.

Flow in UI

1.) UserA creates objC record with uniqueKey of ObjA.Id+objB.Id. (objC record is created)

2.) UserB creates objC record with uniqueKey of ObjA.Id+objB.Id (Trigger updates userA record's Value field, in the ui of userB it will show an error that uniqueKey is already existing)


  • Don't understand flow ... but I expect .. using upsert uniquefield__c will solve the problem
    – Ayub
    Commented Oct 5, 2019 at 13:05
  • Can you share your existing code in this post?
    – David Reed
    Commented Oct 5, 2019 at 15:24
  • is ObjC created from the UI or only via code? If the latter, the upsert approach might work per @Ayub. If the user is creating the record, then your before trigger has to consider uniqueness before setting the key field. Please clarify by using edit
    – cropredy
    Commented Oct 6, 2019 at 0:42
  • Hi, This is all UI except for the updating of exisiting objC which happens in trigger. And guys what do you mean by upsert of uniquefield__c. I'll update my question to make it clearer
    – imajmdf
    Commented Oct 6, 2019 at 1:07


You must log in to answer this question.

Browse other questions tagged .