You need to sign in to do that
Don't have an account?
Wik
Trigger for a Validation
Hi,
I have a Custom Object named preferred rate. It is related to the account in a Master detail relation ship with the account being the Master.
There are two record types in Account named Customer and SIte with the Customer Record type being the Parent of the Site Account record type. A Preferred Rate record can be created on Customer as well as Site account.
I am looking for a validation rule such that When the Expiration Date entered on the Preferred Rate record on Site Account is greater than that on the Customer Account, it should throw an error.
The Site Account record type is the child of the Customer Record Type.
I have a Custom Object named preferred rate. It is related to the account in a Master detail relation ship with the account being the Master.
There are two record types in Account named Customer and SIte with the Customer Record type being the Parent of the Site Account record type. A Preferred Rate record can be created on Customer as well as Site account.
I am looking for a validation rule such that When the Expiration Date entered on the Preferred Rate record on Site Account is greater than that on the Customer Account, it should throw an error.
The Site Account record type is the child of the Customer Record Type.
I have modified the trigger, tested it in my test org as well. It is working perfectly now.
If you want the validation error to appear under the field instead of on the top of the page, replace prr.addError with prr.expiration_date__c.addError
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
All Answers
1. Does the expiration date field exist ONLY on Preferred rate object or does that also exist on Account?
2. As per your question I assume that you would like to check the expiration date entered on preferred rate record related to site if greater than expiration date entered on preferred rate record related to customer then throw an error? or is it that expiration date on preferred rate related to site greater than customer account expiration date? please confirm
I would like to check the expiration date entered on preferred rate record related to site if greater than expiration date entered on preferred rate record related to customer then throw an error
This should help. Please note that this will work only if there is only one preferred rate record on the parent customer record type account.
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
Thanks shashank
Apex trigger ExpirationDateValidator caused an unexpected exception, contact your administrator: ExpirationDateValidator: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.ExpirationDateValidator: line 18, column 1
getting the above error while creating a new record
if(prr.expiration_date__c!=null){
with
if(prr.expiration_date__c!=null && prr.account__c!=null){
Also, please ensure that you are modifying the object names and field names as per your setup.
I did modify as per my setup
the same error persists even after the modification suggested by you
I have modified the trigger, tested it in my test org as well. It is working perfectly now.
If you want the validation error to appear under the field instead of on the top of the page, replace prr.addError with prr.expiration_date__c.addError
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
Can you guide me with the test class