You need to sign in to do that
Don't have an account?
Adaniels117
Help with Trigger Error: Attempt to de-reference a null object
Hey Everyone,
Beginner here, hoping if somebody could help me with my trigger. I'm attempting to create a new contract when a custom object is updated.
It allows me to save the trigger, but when i update the custom object I'm getting the following error:
Apex trigger AutoContract caused an unexpected exception, contact your administrator: AutoContract: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.AutoContract: line 11, column 1
Here is the code i'm using:
/////////////////////////////////////////////////
trigger AutoContract on Zuora__SubscriptionProductCharge__c (After Update) {
List<Contract> listContracts= new List<Contract>();
for(Zuora__SubscriptionProductCharge__c S: Trigger.new){
Contract C= new Contract();
C.Description=S.Zuora__ProductDescription__c;
C.accountid=S.Zuora__Account__r.Id;
C.Type_of_Sale__c=S.Zuora__ProductName__c;
C.Payment_Plan__c=S.Zuora__BillingPeriod__c;
C.Contract_Total__c=S.Zuora__ExtendedAmount__c;
C.StartDate=S.Zuora__EffectiveStartDate__c;
C.Account.Name=S.Zuora__Account__r.Name;
C.User__c='00550000002TLtx';
listContracts.add(c);
}
if(listContracts.isEmpty()== false)
{Database.insert(listContracts);
}
}
//////////////////////////////////////////////////
It seems that the line that is causing the error is the line where i'm trying to map the Contract account name. Can anybody help explain why i'm getting the error and what I need to add to fix?
Thank you!
Beginner here, hoping if somebody could help me with my trigger. I'm attempting to create a new contract when a custom object is updated.
It allows me to save the trigger, but when i update the custom object I'm getting the following error:
Apex trigger AutoContract caused an unexpected exception, contact your administrator: AutoContract: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.AutoContract: line 11, column 1
Here is the code i'm using:
/////////////////////////////////////////////////
trigger AutoContract on Zuora__SubscriptionProductCharge__c (After Update) {
List<Contract> listContracts= new List<Contract>();
for(Zuora__SubscriptionProductCharge__c S: Trigger.new){
Contract C= new Contract();
C.Description=S.Zuora__ProductDescription__c;
C.accountid=S.Zuora__Account__r.Id;
C.Type_of_Sale__c=S.Zuora__ProductName__c;
C.Payment_Plan__c=S.Zuora__BillingPeriod__c;
C.Contract_Total__c=S.Zuora__ExtendedAmount__c;
C.StartDate=S.Zuora__EffectiveStartDate__c;
C.Account.Name=S.Zuora__Account__r.Name;
C.User__c='00550000002TLtx';
listContracts.add(c);
}
if(listContracts.isEmpty()== false)
{Database.insert(listContracts);
}
}
//////////////////////////////////////////////////
It seems that the line that is causing the error is the line where i'm trying to map the Contract account name. Can anybody help explain why i'm getting the error and what I need to add to fix?
Thank you!
Instead of this
Try this
All Answers
Instead of this
Try this
thanks
chris
thanks
chris
I've checked off "best answer" on your response. Thanks again everyone!