• ugsfdc
  • NEWBIE
  • 45 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 2
    Replies
If count of contacts has a value 2, 2 contacts should be created on the account inserted, if its 3, 3 contacts should be created on the inserted account. 

Can you please help me debug or correct this? receiving null pointer  error. 

trigger CoCLikeNumberofContacts on Account (before insert) {
    
    List<Contact> conList = new List<Contact>();
    Account a = new Account();
    integer b = a.Count_of_Contacts__c.intValue();
    
        
    for(Account a : trigger.new) {
        
        
        if(b > 0) {
           
            
               for(integer b = 0; b > 0; b++) {
                  
               conList.add(new Contact(Lastname = a.Name, AccountId = a.Id)); 
             
                
            }
        }
        insert conList;
        
    }         
}
Dear Experts,
I want to fetch the second highest salary from object using SOQL and i was tried to use inner query it showing error.Could you suggest me how we can do it.



Regards,
ugsfdc.