Salesforce trigger could allow one parent will have only one child and same parent doesn't allow duplicates

Trigger Code :
----------------
trigger restrictChildDuplicates on Contact (before Insert) {
    if(System.trigger.isInsert && System.trigger.isBefore){
        restrictContactDuplicateHelper.avoidDuplicateRecords(trigger.new);
    }
}

Helper Apex Class :
-----------------------
    public class restrictContactDuplicateHelper{
    public restrictContactDuplicateHelper(){
 
    }
    public static set<Id> accId = new set<Id>();
    public static map<Id, Set<Decimal>> accConMap = new map<Id, Set<Decimal>>();
    public static void avoidDuplicateRecords(List<Contact> conLis){
        for(Contact con : conLis){
            if(con.AccountId != null){
                accConMap.put(con.AccountId, new set<Decimal>());
            }
       }
       if(!accConMap.isEmpty()){
            for(Contact con : [Select Id,Priority__c,AccountId from Contact where AccountId =: accConMap.keySet()]){
                accConMap.get(con.AccountId).add(con.Priority__c);
            }
      }
      if(!accConMap.isEmpty()){
        for(Contact conRec : conLis){
             if(accConMap.containsKey(conRec.AccountId)){              
                 Set<Decimal> conSet = accConMap.get(conRec.AccountId);
                 if(conSet.contains(conRec.Priority__c)){
                     conRec.Priority__c.addError('Priority was registered already for the Account.');
                }
            }
         }
      }
    }
}

Show or Hide fields in visualforce page using action function

VF:
----
<apex:page controller="actionFunctionController" tabStyle="Account">
    <apex:form >
        <apex:actionFunction name="priorityChangedJavaScript" action="{!priorityChanged}" rerender="out"/>
        <apex:pageBlock >
            <apex:pageBlockSection title="If you will select High Customer Priority then phone textbox will be shown" columns="1" id="out" collapsible="false">
                <apex:inputField value="{!acc.CustomerPriority__c}" onchange="priorityChangedJavaScript()"/>
                <apex:inputField value="{!acc.Phone}" rendered="{!showPhone}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex:
-----
public class actionFunctionController {
    public Account acc{get;set;}
    public Boolean showPhone{get;set;}
 
    public actionFunctionController(){
        acc = new Account();
        showPhone = false;
    }
 
    public PageReference priorityChanged(){
        if(acc.CustomerPriority__c == 'High'){
            showPhone = true;
        }
        else{
            showPhone = false;
        }
        return null;
    }
}

Screenshot:
----------

Featured

What is Cryptography in salesforce and what are all the algorithms provided by them ?

A). It is a security protocal between two systems. Lets say we are integration two systems without any encrytion mechanism then hackers wil...

Popular