• Bharat Seth 12
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Trigger ContactTrigger on Contact(before insert, after insert, before update, after update, before delete, after delete) {
    Set<Id> accountIds = new Set<Id>();
    Set<Id> contactIds = new Set<Id>(); 
    if (Trigger.isBefore) {
        if (Trigger.isInsert) {
            List<Id> accID = new List<Id>();
            for(contact c : trigger.new){
                if(c.accountId != null && c.isPrimary__c==true){
                    accID.add(c.accountId);
                }
            }
            
            List<account> acc = [select id, (select id, isPrimary__c from contacts where isPrimary__c= true) from Account WHERE Id In: accID];
            Map<id, boolean> bool = new map<id,boolean>();
            for(account a : acc){
                bool.put(a.id, a.contacts.size()>0 ? true : false);
            }
            
            for(Contact c : trigger.new){
                if(bool.get(c.AccountId) == true){
                    c.addError(System.Label.Is_Primary_Contact);
                }
            }
            
        } 
        if (Trigger.isUpdate) {
            List<Contact> ConList = New List<Contact>();
            for(Contact con : trigger.new){
                if(con.isPrimary__c != Trigger.oldMap.get(con.Id).isPrimary__c && con.isPrimary__c == true && con.AccountId !=null){
                    accountIds.add(con.AccountId);
                    ConList.add(con);
                }
                if(accountIds.size()>0)
                    ContactTriggerHandler.BeforeUpdate(accountIds, ConList);  
                
            }
        }
        if (Trigger.isDelete) {
            // Call class logic here!
        }
    }
    
    if (Trigger.IsAfter) {
        if (Trigger.isInsert) {
            
        } 
        if (Trigger.isUpdate) {
        }
        if (Trigger.isDelete) {
            // Call class logic here!
        }
    }
}
Can anyone help me write Test Class for below Apex Class.

public class CheckSalesTeam {
    public static boolean IsSalesTeam=false;
    public static Boolean profileApprover(){
        List<Profile> profileList = New List<Profile>([SELECT Name FROM PROFILE WHERE Id = :UserInfo.getProfileId() LIMIT 1]);
        if(profileList[0].Name !='Sales Approver')
            IsSalesTeam=True; 
        
        return  IsSalesTeam;
    }
    
}
I want to create a validation rule on Phone field where Phone field can only accept numbers, brackets and dashes with numbers may or may not start with '+'. And '+' should always be leading character when it comes in the number.

I have written below validation rule but its still allowing more than one '+' character in the numbers and its not allowed. It should only be the leading character if at all its required in the number. 

Someone kindly assist with this asap.

Find below my validation rule:

NOT(OR(REGEX(  Phone  , "[[+][0-9]\\(\\+\\)-]*"),
REGEX(  Phone  , "[[0-9]\\(\\+\\)-]*")))


Also I want to bypass this for System Admin Profile.
I want to create a validation rule on Phone field where Phone field can only accept numbers, brackets and dashes with numbers may or may not start with '+'. And '+' should always be leading character when it comes in the number.

I have written below validation rule but its still allowing more than one '+' character in the numbers and its not allowed. It should only be the leading character if at all its required in the number. 

Someone kindly assist with this asap.

Find below my validation rule:

NOT(OR(REGEX(  Phone  , "[[+][0-9]\\(\\+\\)-]*"),
REGEX(  Phone  , "[[0-9]\\(\\+\\)-]*")))


Also I want to bypass this for System Admin Profile.