+1 vote
by (163k points)

I have a trigger which creates new Cust_Alert_record when Policy__c record is updated.

Below is my trigger:

trigger AlertTextforContact on Policy__c (after update) {
    List<Cust_Alert__c> CustAlertList = new List<Cust_Alert__c>();

    for(Policy__c pol : trigger.new) {
        if(pol.Account_Role__r.role_name__c.contains('Duplicate') || pol.Account_Role__r.role_name__c.contains('Original')) {
            Cust_Alert__c custalert = new Cust_Alert__c(
                Contact__c = pol.Account_Role__r.Contact__c,
                Status__c = 'Active'

    insert CustAlertList;

I have two issues with my code above

  1. From line 5 (if statement) which checks for given Duplicate and Original keywords, I am getting Null pointer exception error even though Account_role__r.role_name__c has the given values.
  2. From line 8, Account_Role__r.Contact__c id not getting updated to Contact__c field. Account_Role__c is the parent and Account_Role__r.Contact__c is the grandparent of the Policy__c record.

Can anyone please suggest any changes to the above code so that I can get this done. Thanks!

1 Answer

Welcome to Memory Exceeded, where you can ask questions and receive answers from other members of the community.