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
Ashish Kumar YadavAshish Kumar Yadav 

how to check duplicate value insert

Hello Team ,

I want to check duplicate insert the record.if duplicate value found give the message else insert the record.

find below code

  Set<Id> accIds = new Set<Id>();
            lstAssignIndividual = new List<Scheme_Assign_Master__c>();
            scheme_masterobj=new Scheme_Master__c();
            if(sam.Scheme_Master__c != null){
                if(sam.Retailer_Account__c != null){
                    Scheme_Assign_Master__c objSAM = new Scheme_Assign_Master__c();
                    objSAM.Account__c = sam.Retailer_Account__c;
                    objSAM.Scheme_Master__c = sam.Scheme_Master__c;
                if(sam.Account__c != null){
                    Scheme_Assign_Master__c objSAM = new Scheme_Assign_Master__c();
                    objSAM.Account__c = sam.Account__c;
                    objSAM.Scheme_Master__c = sam.Scheme_Master__c;
            List<User> userList = new List<User>();
            if(lstAssignIndividual.size() > 0){
                insert lstAssignIndividual;
                userList = [SELECT Id,Email,IsActive FROM User WHERE Profile.Name = 'System Administrator' AND IsActive = True ];
AnudeepAnudeep (Salesforce Developers) 
Hi Ashish, 

I recommend implementing a trigger for this and using addError method for showing error message

For sample code, please see this blog post

Let me know if this helps