function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kavya M 28kavya M 28 

Good Afternoon!!

I have a lightning page and the data in that page got mapped to the custom object's corresponding fileds. Now my requirement is the data in that lightning page should not allow duplicates. For that I need to add a key to the code to check if the data is already existing or new one. If already existing then we should not allow that duplicate record in the lightning page. 

I don't really know how to crack this. Please help me with the inputs.
Arun ParmarArun Parmar
Hi kavya M 28,

You can write a trigger on before update and check new and old values.
e.g. suppose on account object
public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map <String, Schema.SObjectField> fieldMap = schemaMap.get('Account ').getDescribe().fields.getMap();
for(Account acc :{
   for(Schema.SObjectField sfield : fieldMap.Values()){
       schema.describefieldresult dfield = sfield.getDescribe();
       String apiName = dfield.getType ();
       if(acc.get(apiName ) == Trigger.oldMap.get(apiName )){
            acc.addError('Duplicate value found on field->'+  dfield.getLabel ());
Hope this will help you.

Please mark as best answer is helpful.