You need to sign in to do that
Don't have an account?
Multiple if's
Hi,
I have an object 'Values' having the following fields:
Value Code(Name)[textbox]
Description(VSDesc__c)[textbox]
Parent(VSHead__c)[checkbox]
Parent Value(Parent_Value__c)[lookup with the filter, where VSHead__c = true]
Level(VSLevel__c)[numeric]
now, i simply want to maintain 3 Level hierarchy at the backend, i have written the following trigger:
trigger SetValueLevels on Seg1__c (before insert)
{
FOR(Seg1__c val : trigger.new)
{
IF (val.Parent_Value__c == null && val.VSHead__c == true)
{val.VSLevel__c = 1;}
IF(val.Parent_Value__c !=null && val.Parent_Value__r.Parent_Value__c==null)
{val.VSLevel__c =2;}
ELSE
{val.VSLevel__c = 3;}
}
}
It is working fine but the only issue is that it is not going for 3rd level.
Please help in this, Hope everything is clear..
Thanks in Advance :)
I added one formula field in the object with the following formula and it worked :)
IF(AND(VSHead__c =true, Parent_Value__c =null),1,IF(AND( Parent_Value__c <>null,Parent_Value__r.Parent_Value__c =null),2, 3))
All Answers
Try the following
Regards.
Apex trigger SetValueLevels caused an unexpected exception, contact your administrator: SetValueLevels: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.SetValueLevels: line 2,
(I have modified the code in my previous reply)
Can you quote the line where you got the null pointer exception?
Why don't you try using a formula field instead?
Still not working getting the following error
Review all error messages below to correct your data.
Apex trigger SetValueLevels caused an unexpected exception, contact your administrator: SetValueLevels: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.SetValueLevels: line 2, column 1
here it is mentioning the Null Pointer:
List<Seg1__c> allOfThem = [select Parent_Value__c, VSHead__c, Parent_Value__r.Parent_Value__c, VSLevel__c from Seg1__c where id in :trigger.newMap.keySet()];
actually i am very new to Salesforce so i dont know much of it, if u can guide me for Formula field I shall be very thankful to you
I used the formula field having the following formula:
IF(Parent_Value__c=null ,1, IF(AND(VSHead__c = true, Parent_Value__r.Parent_Value__c <> null), 2,3) )
I am unable to go to second leve.
Please help
Thanks
I added one formula field in the object with the following formula and it worked :)
IF(AND(VSHead__c =true, Parent_Value__c =null),1,IF(AND( Parent_Value__c <>null,Parent_Value__r.Parent_Value__c =null),2, 3))