• Dipthi
  • NEWBIE
  • 84 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 21
    Replies

Hi

I have Matching Rules on Website field but, it doesn't work as Users some time feed Website filed as www.test.com (or) https://www.test.com   (or)  test.com

Is there any other way to avoid this situation?

  • February 22, 2022
  • Like
  • 0
Hi ,

I am struck on my validation Rule. seeing the below error msg.
Error : Field Type is a picklist field. Picklist fields are only supported in certain functions. 


REQ: I have a multi-picklist field 'Permissions' on Contact and picklist field 'Account type' on Account. I can only select value 'unlimited' from 'Permissions' only if Account type = VIP/IMP

AND(

NOT(

OR(
ISPICKVAL(Account.Type = ‘VIP’), ISPICKVAL(Account.Type = ‘IMP’) ),

INCLUDES(Partner_User_Permissions__c , 'Unlimited')

)

Message : only contct with VIP & Imp Account type can have 'unlimited' permissions
 
  • February 10, 2022
  • Like
  • 0
Can some one help me out with Handler class (Update). When I go to Account -> Go to related Contact & update to a different Account. Account field 'Total no of Contacts' should be decremented. Can any one help me with UPDATE in my handler class.

This is my Trigger : 

trigger ContactsTotalDisplayOnAccount on Contact (after insert, after update, after delete, after undelete) {
contactHandler Handler = new contactHandler();
 
  if(Trigger.isAfter && Trigger.isInsert){
        Handler.countContacts(Trigger.new,null);
    }
    
    if(Trigger.isAfter && Trigger.isUpdate){
        Handler.countContacts(Trigger.new, Trigger.Old);

    }
    
    if(Trigger.isAfter && Trigger.isDelete){
        Handler.countContacts(Trigger.old,null);
    }
    
    if(Trigger.isAfter && Trigger.isUndelete){
        Handler.countContacts(Trigger.new,null);
    }
}

My Handler Class:

public class ContactHandler {
    
    List<account> accList = new List<Account>();    
    Set<Id> accId = new Set<Id>();                    
    
    public void countContacts (List<Contact> newList, List<Contact> updateList) {  
        for(Contact con : newList) {
            System.debug(con);
            if(con.AccountId != null) {
/* Where can I add this condition :  (con.AccountId != Trigger.oldMap.get(con.id).AccountId) ){    */
               accId.add(con.AccountId); 
               System.debug(accId); 
            }
        }
        for(Account acc : [Select Name,Id,Total_Number_of_Contacts__c,(Select Id from Contacts)
                       from Account Where Id IN :accId])  {
            System.debug(acc);               
            Account acts = new account();
            acts.Id = acc.Id;
            acts.Total_Number_of_Contacts__c = acc.Contacts.Size();
            accList.add(acts); 
            System.debug(accList);               
        }       
    update accList;        
   }

}    

 
  • March 11, 2021
  • Like
  • 0
To show total no of contact records on Account

trigger ContactsTotalDisplayOnAccount on Contact (after insert, after update, after delete, after undelete) {
//Contact can be added/deleted/undeleted

List<contact> contacts = Trigger.isDelete ? Trigger.old : Trigger.new;
set<Id> accId = new set<Id>();
// Set is used to store unique values
    
for(contact con : contacts) {
    If(con.AccountId != null) {
       accId.add(con.AccountId); 
    }    
}
List<account> acclist = new List<account>();

for(account acc : [Select Id,Name,Total_Number_of_Contacts__c,(Select Id from Contacts)
                   from Account 
                   where Id IN :accId]) {
    account acts = new Account();
    acts.Id = acc.Id ; 
    acts.Total_Number_of_Contacts__c = acc.contacts.size(); 
    acclist.add(acts);                   
}
update acclist;
}

 
  • March 06, 2021
  • Like
  • 0
trigger AccountIndustryAnnualRevenue on Account (before insert , before update) {
    List<Account> AccList = new List<Account>();
    for(Account Acc : Trigger.new) {
        If((Acc.Industry == 'Chemicals') && (Acc.AnnualRevenue <= 1200)){
           AccList.add(Acc);
        }    
        If(AccList.size() > 0) {
          Acc.addError ('When Industry is ‘Chemical’, annual revenue cannot be less than 1200'); // logic is incorrect. 
          
        }   
    }
}
  • March 06, 2021
  • Like
  • 0
Hi Awesome coders,
I have a checkbox field 'Out of Zip' on Account. When an Account's 'Billing Postal code' field is updated, check its Contacts 'mailing postal code'. If more than one contacts 'mailing postal code' field is not matching with Account then 'Out of Zip' field on Account should be turned True.

Plz correct my code in bold

trigger AccountOutOfZip on Account (After Update) {
    // Adding record Id's of Accounts whose postal code is updated
    Set<Id> AccIdSet = new Set<Id>() ;
    for(Account acc : Trigger.new) {
        Account oldAcc = Trigger.oldMap.get(acc.Id);
            If(acc.billingpostalcode  != oldAcc.billingpostalcode ) {
               AccIdSet.Add(acc.Id) ;
            }    
    }
    
    List <Account> AccUpdateList = New List<Account>();

    If(AccIdSet.size() > 0) {
        Account[] accList = [SELECT Id from Account where Id IN :AccIdSet] ; 
        Contact[] conList = [SELECT Id,AccountId from Contact where AccountId IN :AccIdSet] ;
        for(Account a : accList) {
            for(Contact c : conList) {
                If(a.billingpostalcode != c.MailingPostalCode) {
                  // a.Out_Of_Zip__c = True ;
                   AccUpdateList.add(a.Id = c.AccountId, a.Out_Of_Zip__c = True) ;

                }
            }
        }
     
    If(!AccUpdateList.isEmpty()) {
         update AccUpdateList ; 
    }
}    
    
  • October 15, 2020
  • Like
  • 0
Hi awesome coders , I am not able to get what is going wrong. when i execute the below class through Annonymous window, I see no results. : AccGroupByIndustry.getAccountGrByIndMap(); 

public class AccGroupByIndustry {

// Get all Accounts with Industry as Key and List of Accounts as value
    public static Map<String,List<Account>> getAccountGrByIndMap() {
    
    Map<String, List<Account>> accountsGroupedByIndustry = new Map<String, List<Account>>();
    // Fetch all accounts with Industry
    List<Account> accountsWithIndustry = [SELECT Id, Name, Industry From Account Where Industry <> Null];
    
        for (Account acc : accountsWithIndustry) 
        {
            List<Account> accountList;
            // Check if map already contains current Industry as KEY
              If(accountsGroupedByIndustry.containsKey(acc.Industry))
              {
                 // Fetch existing list and put it back to Map
                 accountList = accountsGroupedByIndustry.get(acc.Industry);
                 accountList.add(acc);   
              }
            // If key doesn't exist, add account to new List  
            else
            {
                 // Create new List
                 accountList = new List<Account>();
                accountList.add(acc);
            }
            
            // Finally put this List into Map with Industry as Key
            accountsGroupedByIndustry.put(acc.Industry,accountList);
        }  
           return accountsGroupedByIndustry;
    }   
}
  • October 13, 2020
  • Like
  • 0
trigger PreventDuplicateOnContact on Contact (before insert) {
    // Set to store Phone No's
    Set<String> ContactPhoneSet = new Set<String> ();
    // Set to store Email ID's
    Set<String> ContactEmailSet = new Set<String> ();
    
    // Iterate through each new Contact and add their email and Phone in to Sets 
    for(Contact Con : Trigger.new) {
        ContactPhoneSet.add(con.Phone);
        ContactPhoneSet.add(con.Email);
    }
   
   List<Contact> ContactPhoneList = new List<Contact>();
   List<Contact> ContactEmailList = new List<Contact>();
    
    
   ContactEmailList = [Select email From Contact Where Email IN : ContactEmailSet];
   ContactPhoneList = [Select Phone From Contact Where Phone IN : ContactPhoneSet];
   
   for(Contact Con : Trigger.new) {
       If(ContactEmailList.size() > 0) {
           Con.Email.AddError('Duplicate Contact Found With Same Email');
           System.debug('Email'); 
         }
        
       If(ContactPhoneList.size() > 0) {
          Con.Phone.AddError('Duplicate Contact Found With Same Phone');
        }
  }  
    
}
  • October 08, 2020
  • Like
  • 0

Hi Awesome coders, I am new to programming and need help with this Trigger. Your help is greatly appreciated !!

I have two Objects, 
1. Package_Shipment_Order__c (Parent) , 
2.Package_Shipment_Delivery__c (Child) M_Detail relationship . 
Parent object has a multi select picklist field ‘States__c’ . When User selects a couple of states, child records to be created on Package_Shipment_Delivery__c. Error is highlighted in Bold

trigger PicklistCreateChild on Package_Shipment_Order__c (after insert , after update) {
List<Package_Shipment_Delivery__c> PkgShipDe = new List<Package_Shipment_Delivery__c>();
    for(Package_Shipment_Order__c PkgShipOr : Trigger.new){
        if (PkgShipOr.Shipment_States__c != Null){
            List<String> ShipStates = PkgShipOr.Shipment_States__c.Split(';');
            If(ShipStates != Null && ShipStates.size()>0){
                for (String ShipSt : ShipStates){
       Package_Shipment_Delivery__c PkShipDe = new Package_Shipment_Delivery__c();   
       PkShipDe.Package_Shipment_Orders__c = PkgShipOr.Id;
       PkShipDe.State__c = PkgShipDe.get(ShipSt);  
                    PkgShipDe.add(PkShipDe) ;
                }
            }
        }
    Insert PkgShipDe;

Hi Coders, I am new to Coding and took a task to write a test class. I am working for a Leave management App and made my coverage for 65%. I am not understading why my for loop is not covered in coverage. your help is greatly appreciated !!


This my Class: (Bold code is NOT in coverage)
trigger OnLeaveApproval on Leaves__c (after update)
{
    
for(Leaves__c obj: Trigger.new)
{
    map<string, Object> leaveMap = new map<string, Object>();
    system.debug('coming here 1');   
    if (obj.Approval_Status__c != Null && obj.Approval_Status__c == 'Approved')
    {
            system.debug('coming here 1.2'+ obj.CreatedById); 
            system.debug('coming here 1.2'+ obj.Contact_ID__c); 
            system.debug('name'+ obj.Name);
            system.debug('coming here 1.2.1'+ obj); 
            leaveMap.put(obj.Contact_ID__c, obj.Req_Days_Off__c);
            system.debug('coming here 2'); 
    }
    system.debug('coming here 2.1' + leaveMap);
    if(leaveMap.size() > 0 ) {
  
            list<Contact> contact = [SELECT Id,Total_Available_Leaves__c,OwnerId FROM Contact WHERE  Id IN :leaveMap.KeySet()];
            system.debug('coming here 3' + contact); 
            list<Monthly_Take_Home__c> employeePayroll = [SELECT Id,Unpaid_Days__c, Paid_Days__c, Salary__c,Emp_Salary__c,Current_PayPeriod_Salary__c FROM Monthly_Take_Home__c WHERE Contact_ID__c IN :leaveMap.KeySet()];
            system.debug('coming here 3.1' + employeePayroll);
            list<Contact> contactUpdatelist = new list<Contact>();
            list<Monthly_Take_Home__c> employeePayrolllist = new list<Monthly_Take_Home__c>();
            for(Contact c: contact)
                {
                    system.debug('coming here 4'+ contact); 
                    //Integer totalApprovedLeaves = leaveMap.get(c.Name);
                    Integer totalApprovedLeaves = Integer.valueOf(leaveMap.get(c.Id));
                    if( c.Total_Available_Leaves__c - totalApprovedLeaves < 0 ) {
                        
                            system.debug('coming here 5'+c.Total_Available_Leaves__c); 
                             Integer lossOfPayDays = totalApprovedLeaves - c.Total_Available_Leaves__c.intValue();
                             system.debug('coming here 5.1'+ lossOfPayDays);
                            for(Monthly_Take_Home__c empPayroll: employeePayroll)
                            {
                                
                                  if(empPayroll.Unpaid_Days__c !=null)
                                      lossOfPayDays = lossOfPayDays + empPayroll.Unpaid_Days__c.intValue();
                                system.debug('coming here 5.1'+ lossOfPayDays);
                                system.debug('coming here 6.0'+empPayroll.Paid_Days__c); 
                                Integer totalPayDates = empPayroll.Paid_Days__c.intValue() - lossOfPayDays;
                                system.debug('totalPayDates 6'+totalPayDates); 
                                Double calculatedSalary =  Double.valueOf(empPayroll.Emp_Salary__c/empPayroll.Paid_Days__c.intValue());
                                system.debug('empPayroll.Salary__c 0'+ empPayroll.Emp_Salary__c);
                                system.debug('totalPayDates'+ totalPayDates);
                                system.debug('lossOfPayDays'+ lossOfPayDays);
                                empPayroll.Current_PayPeriod_Salary__c = (calculatedSalary * totalPayDates) ;
                                system.debug('totalSalary'+ calculatedSalary * totalPayDates);
                                empPayroll.Unpaid_Days__c = lossOfPayDays;
                                system.debug('empPayroll.Current_PayPeriod_Salary__c'+ empPayroll.Current_PayPeriod_Salary__c);
                                system.debug('calculatedSalary'+ calculatedSalary);     
                                employeePayrolllist.add(empPayroll);
                            }
                        c.Total_Available_Leaves__c = 0;
                    } else {
                        
                        c.Total_Available_Leaves__c =
c.Total_Available_Leaves__c - totalApprovedLeaves;
                    }
                    contactUpdatelist.add(c);
            }
            if(contactUpdatelist.size() > 0)
            {
                system.debug('coming here 7'+ contactUpdatelist); 
                update contactUpdatelist;
            }

            if(employeePayrolllist.size() > 0)
            {
                system.debug('coming here 8'+ employeePayrolllist); 
                update employeePayrolllist;
            }
        }
}
}


This my Test Class: Covered 65% of code
@isTest
private class OnLeaveApprovalTest {
 
@isTest
public static void CreateContactAndLeaveReq(){
test.startTest(); 

// Test data setup - Create a new Employee contact
Contact emp = new Contact ();
emp.FirstName = 'Jon';
emp.LastName = 'Snow';
emp.Emp_ID__c = 'Sp-343245';
emp.Total_Available_Leaves__c = 4;
emp.Emp_Salary__c = 10000;
    
insert emp;
system.debug(emp);

Contact EmpInfo = [Select Name,Id from Contact Where id =: Emp.Id]; 

//Enter record details on Leaves Object
Leaves__c leaveReq = new Leaves__c();
leaveReq.Employee_Name__c = EmpInfo.Id;
leaveReq.Request_Start_Date__c = date.newInstance(2020,06,10);
leaveReq.Request_End_Date__c = date.newInstance(2020,06,15);
leaveReq.Contact_ID__c = Emp.Id;

Insert leaveReq;
system.debug(leaveReq);


leaveReq.Approval_Status__c = 'Approved';
Update leaveReq;
    
Monthly_Take_Home__c TakeHome = new Monthly_Take_Home__c();
TakeHome.Employee_Name__c = EmpInfo.Id;
TakeHome.Salary_Start_Date__c = date.newInstance(2020,06,01);
TakeHome.Salary_End_Date__c = date.newInstance(2020,06,30);
TakeHome.Unpaid_Days__c = 6;
TakeHome.Contact_ID__c = Emp.Id;

Insert TakeHome;
test.stopTest();   
}
}

I am new to Apex and working on Leave Management App. Contact is Parent to LeaveEntry Object having Master-detail relationship on Name field.
( On contact Object while creating a record, I have First Name and LastName but on LeaveEntry Object while creating record I will select Employee full name which will populate from Contact ) 

I need clarification on 2 issues where I see errors (made their font bold)
1. Why am I getting Null value when I want to retrieve Name at System.debug
2. How can I pull Name value from contact to LeaveEntry?

@isTest
public class OnLeaveApprovalTest {
 
@isTest
public static void CreateContactRecord(){
Contact emp = new Contact ();

emp.FirstName = 'Jon';
emp.LastName = 'Snow';
emp.Emp_ID__c = 'Sp-34324';
insert emp;
system.debug('Full Name of emp is : ' + emp.Name);  // plz clarify
system.debug(emp);
 
//Enter record details on Leaves Object
Leaves__c leaveReq = new Leaves__c();
Emp Name = emp.FirstName + ' ' + emp.LastName;  //Plz Clarify
leaveReq.Request_Start_Date__c = date.newInstance(2020,06,10);
leaveReq.Request_End_Date__c = date.newInstance(2020,06,15);
Insert leaveReq;
  
}
}
I am new to development and I am working on Leave Management App where I need to add 4 leaves for field 'Total Leaves' on Contact Object at the end of every month for all Employees.

I am assuming I should go with Trigger. Can anyone help me with this trigger.
Hi ,

I am struck on my validation Rule. seeing the below error msg.
Error : Field Type is a picklist field. Picklist fields are only supported in certain functions. 


REQ: I have a multi-picklist field 'Permissions' on Contact and picklist field 'Account type' on Account. I can only select value 'unlimited' from 'Permissions' only if Account type = VIP/IMP

AND(

NOT(

OR(
ISPICKVAL(Account.Type = ‘VIP’), ISPICKVAL(Account.Type = ‘IMP’) ),

INCLUDES(Partner_User_Permissions__c , 'Unlimited')

)

Message : only contct with VIP & Imp Account type can have 'unlimited' permissions
 
  • February 10, 2022
  • Like
  • 0
Can some one help me out with Handler class (Update). When I go to Account -> Go to related Contact & update to a different Account. Account field 'Total no of Contacts' should be decremented. Can any one help me with UPDATE in my handler class.

This is my Trigger : 

trigger ContactsTotalDisplayOnAccount on Contact (after insert, after update, after delete, after undelete) {
contactHandler Handler = new contactHandler();
 
  if(Trigger.isAfter && Trigger.isInsert){
        Handler.countContacts(Trigger.new,null);
    }
    
    if(Trigger.isAfter && Trigger.isUpdate){
        Handler.countContacts(Trigger.new, Trigger.Old);

    }
    
    if(Trigger.isAfter && Trigger.isDelete){
        Handler.countContacts(Trigger.old,null);
    }
    
    if(Trigger.isAfter && Trigger.isUndelete){
        Handler.countContacts(Trigger.new,null);
    }
}

My Handler Class:

public class ContactHandler {
    
    List<account> accList = new List<Account>();    
    Set<Id> accId = new Set<Id>();                    
    
    public void countContacts (List<Contact> newList, List<Contact> updateList) {  
        for(Contact con : newList) {
            System.debug(con);
            if(con.AccountId != null) {
/* Where can I add this condition :  (con.AccountId != Trigger.oldMap.get(con.id).AccountId) ){    */
               accId.add(con.AccountId); 
               System.debug(accId); 
            }
        }
        for(Account acc : [Select Name,Id,Total_Number_of_Contacts__c,(Select Id from Contacts)
                       from Account Where Id IN :accId])  {
            System.debug(acc);               
            Account acts = new account();
            acts.Id = acc.Id;
            acts.Total_Number_of_Contacts__c = acc.Contacts.Size();
            accList.add(acts); 
            System.debug(accList);               
        }       
    update accList;        
   }

}    

 
  • March 11, 2021
  • Like
  • 0
To show total no of contact records on Account

trigger ContactsTotalDisplayOnAccount on Contact (after insert, after update, after delete, after undelete) {
//Contact can be added/deleted/undeleted

List<contact> contacts = Trigger.isDelete ? Trigger.old : Trigger.new;
set<Id> accId = new set<Id>();
// Set is used to store unique values
    
for(contact con : contacts) {
    If(con.AccountId != null) {
       accId.add(con.AccountId); 
    }    
}
List<account> acclist = new List<account>();

for(account acc : [Select Id,Name,Total_Number_of_Contacts__c,(Select Id from Contacts)
                   from Account 
                   where Id IN :accId]) {
    account acts = new Account();
    acts.Id = acc.Id ; 
    acts.Total_Number_of_Contacts__c = acc.contacts.size(); 
    acclist.add(acts);                   
}
update acclist;
}

 
  • March 06, 2021
  • Like
  • 0
trigger AccountIndustryAnnualRevenue on Account (before insert , before update) {
    List<Account> AccList = new List<Account>();
    for(Account Acc : Trigger.new) {
        If((Acc.Industry == 'Chemicals') && (Acc.AnnualRevenue <= 1200)){
           AccList.add(Acc);
        }    
        If(AccList.size() > 0) {
          Acc.addError ('When Industry is ‘Chemical’, annual revenue cannot be less than 1200'); // logic is incorrect. 
          
        }   
    }
}
  • March 06, 2021
  • Like
  • 0
Hi Awesome coders,
I have a checkbox field 'Out of Zip' on Account. When an Account's 'Billing Postal code' field is updated, check its Contacts 'mailing postal code'. If more than one contacts 'mailing postal code' field is not matching with Account then 'Out of Zip' field on Account should be turned True.

Plz correct my code in bold

trigger AccountOutOfZip on Account (After Update) {
    // Adding record Id's of Accounts whose postal code is updated
    Set<Id> AccIdSet = new Set<Id>() ;
    for(Account acc : Trigger.new) {
        Account oldAcc = Trigger.oldMap.get(acc.Id);
            If(acc.billingpostalcode  != oldAcc.billingpostalcode ) {
               AccIdSet.Add(acc.Id) ;
            }    
    }
    
    List <Account> AccUpdateList = New List<Account>();

    If(AccIdSet.size() > 0) {
        Account[] accList = [SELECT Id from Account where Id IN :AccIdSet] ; 
        Contact[] conList = [SELECT Id,AccountId from Contact where AccountId IN :AccIdSet] ;
        for(Account a : accList) {
            for(Contact c : conList) {
                If(a.billingpostalcode != c.MailingPostalCode) {
                  // a.Out_Of_Zip__c = True ;
                   AccUpdateList.add(a.Id = c.AccountId, a.Out_Of_Zip__c = True) ;

                }
            }
        }
     
    If(!AccUpdateList.isEmpty()) {
         update AccUpdateList ; 
    }
}    
    
  • October 15, 2020
  • Like
  • 0
Hi awesome coders , I am not able to get what is going wrong. when i execute the below class through Annonymous window, I see no results. : AccGroupByIndustry.getAccountGrByIndMap(); 

public class AccGroupByIndustry {

// Get all Accounts with Industry as Key and List of Accounts as value
    public static Map<String,List<Account>> getAccountGrByIndMap() {
    
    Map<String, List<Account>> accountsGroupedByIndustry = new Map<String, List<Account>>();
    // Fetch all accounts with Industry
    List<Account> accountsWithIndustry = [SELECT Id, Name, Industry From Account Where Industry <> Null];
    
        for (Account acc : accountsWithIndustry) 
        {
            List<Account> accountList;
            // Check if map already contains current Industry as KEY
              If(accountsGroupedByIndustry.containsKey(acc.Industry))
              {
                 // Fetch existing list and put it back to Map
                 accountList = accountsGroupedByIndustry.get(acc.Industry);
                 accountList.add(acc);   
              }
            // If key doesn't exist, add account to new List  
            else
            {
                 // Create new List
                 accountList = new List<Account>();
                accountList.add(acc);
            }
            
            // Finally put this List into Map with Industry as Key
            accountsGroupedByIndustry.put(acc.Industry,accountList);
        }  
           return accountsGroupedByIndustry;
    }   
}
  • October 13, 2020
  • Like
  • 0
trigger PreventDuplicateOnContact on Contact (before insert) {
    // Set to store Phone No's
    Set<String> ContactPhoneSet = new Set<String> ();
    // Set to store Email ID's
    Set<String> ContactEmailSet = new Set<String> ();
    
    // Iterate through each new Contact and add their email and Phone in to Sets 
    for(Contact Con : Trigger.new) {
        ContactPhoneSet.add(con.Phone);
        ContactPhoneSet.add(con.Email);
    }
   
   List<Contact> ContactPhoneList = new List<Contact>();
   List<Contact> ContactEmailList = new List<Contact>();
    
    
   ContactEmailList = [Select email From Contact Where Email IN : ContactEmailSet];
   ContactPhoneList = [Select Phone From Contact Where Phone IN : ContactPhoneSet];
   
   for(Contact Con : Trigger.new) {
       If(ContactEmailList.size() > 0) {
           Con.Email.AddError('Duplicate Contact Found With Same Email');
           System.debug('Email'); 
         }
        
       If(ContactPhoneList.size() > 0) {
          Con.Phone.AddError('Duplicate Contact Found With Same Phone');
        }
  }  
    
}
  • October 08, 2020
  • Like
  • 0

Hi Awesome coders, I am new to programming and need help with this Trigger. Your help is greatly appreciated !!

I have two Objects, 
1. Package_Shipment_Order__c (Parent) , 
2.Package_Shipment_Delivery__c (Child) M_Detail relationship . 
Parent object has a multi select picklist field ‘States__c’ . When User selects a couple of states, child records to be created on Package_Shipment_Delivery__c. Error is highlighted in Bold

trigger PicklistCreateChild on Package_Shipment_Order__c (after insert , after update) {
List<Package_Shipment_Delivery__c> PkgShipDe = new List<Package_Shipment_Delivery__c>();
    for(Package_Shipment_Order__c PkgShipOr : Trigger.new){
        if (PkgShipOr.Shipment_States__c != Null){
            List<String> ShipStates = PkgShipOr.Shipment_States__c.Split(';');
            If(ShipStates != Null && ShipStates.size()>0){
                for (String ShipSt : ShipStates){
       Package_Shipment_Delivery__c PkShipDe = new Package_Shipment_Delivery__c();   
       PkShipDe.Package_Shipment_Orders__c = PkgShipOr.Id;
       PkShipDe.State__c = PkgShipDe.get(ShipSt);  
                    PkgShipDe.add(PkShipDe) ;
                }
            }
        }
    Insert PkgShipDe;
Hi, I work at an organization without an in house developer. I'm hoping to determine how to address the following error message:

Apex trigger SyncCasesWithActivityHistories caused an unexpected exception, contact your administrator: SyncCasesWithActivityHistories: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Class.ActivityHistoriesToCaseSyncer.TaskCounts.getDirectionForType: line 34, column 1

This error seems to occur randomly from time to time when saving routine information.

Thanks,

Rebecca
Can we use duplicate rule in trigger?
I have a requirement where I need to update contacts if duplicate contact gets created or added.

Hi Coders, I am new to Coding and took a task to write a test class. I am working for a Leave management App and made my coverage for 65%. I am not understading why my for loop is not covered in coverage. your help is greatly appreciated !!


This my Class: (Bold code is NOT in coverage)
trigger OnLeaveApproval on Leaves__c (after update)
{
    
for(Leaves__c obj: Trigger.new)
{
    map<string, Object> leaveMap = new map<string, Object>();
    system.debug('coming here 1');   
    if (obj.Approval_Status__c != Null && obj.Approval_Status__c == 'Approved')
    {
            system.debug('coming here 1.2'+ obj.CreatedById); 
            system.debug('coming here 1.2'+ obj.Contact_ID__c); 
            system.debug('name'+ obj.Name);
            system.debug('coming here 1.2.1'+ obj); 
            leaveMap.put(obj.Contact_ID__c, obj.Req_Days_Off__c);
            system.debug('coming here 2'); 
    }
    system.debug('coming here 2.1' + leaveMap);
    if(leaveMap.size() > 0 ) {
  
            list<Contact> contact = [SELECT Id,Total_Available_Leaves__c,OwnerId FROM Contact WHERE  Id IN :leaveMap.KeySet()];
            system.debug('coming here 3' + contact); 
            list<Monthly_Take_Home__c> employeePayroll = [SELECT Id,Unpaid_Days__c, Paid_Days__c, Salary__c,Emp_Salary__c,Current_PayPeriod_Salary__c FROM Monthly_Take_Home__c WHERE Contact_ID__c IN :leaveMap.KeySet()];
            system.debug('coming here 3.1' + employeePayroll);
            list<Contact> contactUpdatelist = new list<Contact>();
            list<Monthly_Take_Home__c> employeePayrolllist = new list<Monthly_Take_Home__c>();
            for(Contact c: contact)
                {
                    system.debug('coming here 4'+ contact); 
                    //Integer totalApprovedLeaves = leaveMap.get(c.Name);
                    Integer totalApprovedLeaves = Integer.valueOf(leaveMap.get(c.Id));
                    if( c.Total_Available_Leaves__c - totalApprovedLeaves < 0 ) {
                        
                            system.debug('coming here 5'+c.Total_Available_Leaves__c); 
                             Integer lossOfPayDays = totalApprovedLeaves - c.Total_Available_Leaves__c.intValue();
                             system.debug('coming here 5.1'+ lossOfPayDays);
                            for(Monthly_Take_Home__c empPayroll: employeePayroll)
                            {
                                
                                  if(empPayroll.Unpaid_Days__c !=null)
                                      lossOfPayDays = lossOfPayDays + empPayroll.Unpaid_Days__c.intValue();
                                system.debug('coming here 5.1'+ lossOfPayDays);
                                system.debug('coming here 6.0'+empPayroll.Paid_Days__c); 
                                Integer totalPayDates = empPayroll.Paid_Days__c.intValue() - lossOfPayDays;
                                system.debug('totalPayDates 6'+totalPayDates); 
                                Double calculatedSalary =  Double.valueOf(empPayroll.Emp_Salary__c/empPayroll.Paid_Days__c.intValue());
                                system.debug('empPayroll.Salary__c 0'+ empPayroll.Emp_Salary__c);
                                system.debug('totalPayDates'+ totalPayDates);
                                system.debug('lossOfPayDays'+ lossOfPayDays);
                                empPayroll.Current_PayPeriod_Salary__c = (calculatedSalary * totalPayDates) ;
                                system.debug('totalSalary'+ calculatedSalary * totalPayDates);
                                empPayroll.Unpaid_Days__c = lossOfPayDays;
                                system.debug('empPayroll.Current_PayPeriod_Salary__c'+ empPayroll.Current_PayPeriod_Salary__c);
                                system.debug('calculatedSalary'+ calculatedSalary);     
                                employeePayrolllist.add(empPayroll);
                            }
                        c.Total_Available_Leaves__c = 0;
                    } else {
                        
                        c.Total_Available_Leaves__c =
c.Total_Available_Leaves__c - totalApprovedLeaves;
                    }
                    contactUpdatelist.add(c);
            }
            if(contactUpdatelist.size() > 0)
            {
                system.debug('coming here 7'+ contactUpdatelist); 
                update contactUpdatelist;
            }

            if(employeePayrolllist.size() > 0)
            {
                system.debug('coming here 8'+ employeePayrolllist); 
                update employeePayrolllist;
            }
        }
}
}


This my Test Class: Covered 65% of code
@isTest
private class OnLeaveApprovalTest {
 
@isTest
public static void CreateContactAndLeaveReq(){
test.startTest(); 

// Test data setup - Create a new Employee contact
Contact emp = new Contact ();
emp.FirstName = 'Jon';
emp.LastName = 'Snow';
emp.Emp_ID__c = 'Sp-343245';
emp.Total_Available_Leaves__c = 4;
emp.Emp_Salary__c = 10000;
    
insert emp;
system.debug(emp);

Contact EmpInfo = [Select Name,Id from Contact Where id =: Emp.Id]; 

//Enter record details on Leaves Object
Leaves__c leaveReq = new Leaves__c();
leaveReq.Employee_Name__c = EmpInfo.Id;
leaveReq.Request_Start_Date__c = date.newInstance(2020,06,10);
leaveReq.Request_End_Date__c = date.newInstance(2020,06,15);
leaveReq.Contact_ID__c = Emp.Id;

Insert leaveReq;
system.debug(leaveReq);


leaveReq.Approval_Status__c = 'Approved';
Update leaveReq;
    
Monthly_Take_Home__c TakeHome = new Monthly_Take_Home__c();
TakeHome.Employee_Name__c = EmpInfo.Id;
TakeHome.Salary_Start_Date__c = date.newInstance(2020,06,01);
TakeHome.Salary_End_Date__c = date.newInstance(2020,06,30);
TakeHome.Unpaid_Days__c = 6;
TakeHome.Contact_ID__c = Emp.Id;

Insert TakeHome;
test.stopTest();   
}
}

I am new to Apex and working on Leave Management App. Contact is Parent to LeaveEntry Object having Master-detail relationship on Name field.
( On contact Object while creating a record, I have First Name and LastName but on LeaveEntry Object while creating record I will select Employee full name which will populate from Contact ) 

I need clarification on 2 issues where I see errors (made their font bold)
1. Why am I getting Null value when I want to retrieve Name at System.debug
2. How can I pull Name value from contact to LeaveEntry?

@isTest
public class OnLeaveApprovalTest {
 
@isTest
public static void CreateContactRecord(){
Contact emp = new Contact ();

emp.FirstName = 'Jon';
emp.LastName = 'Snow';
emp.Emp_ID__c = 'Sp-34324';
insert emp;
system.debug('Full Name of emp is : ' + emp.Name);  // plz clarify
system.debug(emp);
 
//Enter record details on Leaves Object
Leaves__c leaveReq = new Leaves__c();
Emp Name = emp.FirstName + ' ' + emp.LastName;  //Plz Clarify
leaveReq.Request_Start_Date__c = date.newInstance(2020,06,10);
leaveReq.Request_End_Date__c = date.newInstance(2020,06,15);
Insert leaveReq;
  
}
}