You need to sign in to do that
Don't have an account?
Manjunath reddy 25
Hi I am getting null for opp.Account.name when ued system.debug('opp.Account.name'+opp.Account.name);
Actually iam trying to disount on amount when related account of the opportunity is changed to Axis.
Can some one help me on this?
Getting null for account name.
trigger abcAccount on Opportunity (before update) { list<id> oppIds = new list<id>(); //if(trigger.isInsert || trigger.isUpdate){ for(opportunity opp : trigger.new){ system.debug('opp'+opp); system.debug('opp.Account.name'+opp.Account.name); if(opp.Account.name=='Axis'){ system.debug('opp'+opp); opp.amount = opp.amount*10/100; //oppIds.add(opp.id); } } //} }
Hi I am getting null for opp.Account.name when ued system.debug('opp.Account.name'+opp.Account.name);
Actually iam trying to disount on amount when related account of the opportunity is changed to Axis.
Can some one help me on this?
You need to query for those values since they don't come down natively in the trigger. Anything that is related will be null (like op.Account.Name)
Please see below code.
Hope this helps you!
Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards
Sandhya
All Answers
You need to query for those values since they don't come down natively in the trigger. Anything that is related will be null (like op.Account.Name)
Please see below code.
Hope this helps you!
Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards
Sandhya
In above code there are two problems :
1. First you are accessing the
opp.account.namefield with the reference to trigger.new which is wrong because we can only use the opp.accountId field.2. This trigger will run every time if the account is updated or not. So whenever we write code for update we first check the old and new values.
Use below code for your problem :
Thanks.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger abcAccount caused an unexpected exception, contact your administrator: abcAccount: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.abcAccount: line 15, column 1
debug logs are as follows
20:46:01.0 (660299)|CODE_UNIT_STARTED|[EXTERNAL]|01q28000000RHCN|abcAccount on Opportunity trigger event BeforeUpdate for [0062800000BIdmd] 20:46:01.0 (2479732)|SOQL_EXECUTE_BEGIN|[10]|Aggregations:0|SELECT id, name FROM account WHERE (name = 'Axis' AND id IN :tmpVar1) 20:46:01.0 (5403866)|SOQL_EXECUTE_END|[10]|Rows:0 20:46:01.0 (5673945)|USER_DEBUG|[14]|DEBUG|accName 0012800000liw4yAAA 20:46:01.0 (5773133)|EXCEPTION_THROWN|[15]|System.NullPointerException: Attempt to de-reference a null object 20:46:01.0 (6009406)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object Trigger.abcAccount: line 15, column 1 20:46:01.0 (6023980)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object Trigger.abcAccount: line 15, column 1 20:46:01.6 (6080968)|CUMULATIVE_LIMIT_USAGE 20:46:01.6 (6080968)|LIMIT_USAGE_FOR_NS|(default)| Number of SOQL queries: 1 out of 100
Now it is working than you