• Ramon Austria
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hello everyone,

I'm configuring Salesforce for a non-profit and I'm using Salesforce enterprise with the Non-Profit Starter Pack. We're linking our opportunities object to both contacts and accounts/households and we want our users to be able to, when filling up the opportunity form, select the contact that made the donation from a custom contact lookup field (Contact_Name__c) and upon creating the record the standard Account lookup field will be filled up with this contact's account/household name automatically. This way our users won't have to manually fill in both the contact and account fields for every opportunity record they wish to create.

This is the current trigger iteration I'm using:

trigger UpdateRegistrationHousehold on Opportunity (before insert, before update) 
{   
    for (Opportunity a:trigger.new)
    {
        if(a.recordtypeID == '012o0000000NnqM')   
        {a.Account.Name = a.Contact_Name__r.Account.Name;}
    }    
}

We want to implement this functionality only on a particular opportunity record type.

This particular code structure has worked for me when updating other fields prior to this, but for this specific issue it's been yielding errors and driving me nuts. I've been tweaking this bit of code a bit and depending on my tweaks, 1 of two things seems to happen: either the Account field remains unpopulated, or the form doesn't save and I get this error: Error:Apex trigger UpdateRegistrationHousehold caused an unexpected exception, contact your administrator: UpdateRegistrationHousehold: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.UpdateRegistrationHousehold: line 6, column 1

I have limited coding knowledge so I'm looking forward to hearing from you guys and learning more in the process! Cheers! :)



 
Hello everyone,

I'm configuring Salesforce for a non-profit and I'm using Salesforce enterprise with the Non-Profit Starter Pack. We're linking our opportunities object to both contacts and accounts/households and we want our users to be able to, when filling up the opportunity form, select the contact that made the donation from a custom contact lookup field (Contact_Name__c) and upon creating the record the standard Account lookup field will be filled up with this contact's account/household name automatically. This way our users won't have to manually fill in both the contact and account fields for every opportunity record they wish to create.

This is the current trigger iteration I'm using:

trigger UpdateRegistrationHousehold on Opportunity (before insert, before update) 
{   
    for (Opportunity a:trigger.new)
    {
        if(a.recordtypeID == '012o0000000NnqM')   
        {a.Account.Name = a.Contact_Name__r.Account.Name;}
    }    
}

We want to implement this functionality only on a particular opportunity record type.

This particular code structure has worked for me when updating other fields prior to this, but for this specific issue it's been yielding errors and driving me nuts. I've been tweaking this bit of code a bit and depending on my tweaks, 1 of two things seems to happen: either the Account field remains unpopulated, or the form doesn't save and I get this error: Error:Apex trigger UpdateRegistrationHousehold caused an unexpected exception, contact your administrator: UpdateRegistrationHousehold: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.UpdateRegistrationHousehold: line 6, column 1

I have limited coding knowledge so I'm looking forward to hearing from you guys and learning more in the process! Cheers! :)