You need to sign in to do that
Don't have an account?
Akshat Tiwari 2
Please help me with parent to child test class
I am trying to update the AnnualRevenue of Account into Opportunity amount and it is working for update.....During testing I am getting error System Variable does not exist: Amount
Here is the code
Here is the code
@isTest public class OppAmountUpdate_Test { @isTest public static void myMethod_Test(){ Account acc = new Account(); //acc.Id = '0015j00000dkZj0AAE'; acc.Name = 'Aviral Dandge'; acc.AnnualRevenue = 25000; insert acc; Opportunity opp1 = new Opportunity(); opp1.Name = 'Dandge Pvt Ltd'; opp1.CloseDate = system.today(); opp1.StageName = 'Qualification'; insert opp1; Test.startTest(); acc.AnnualRevenue = 50000; update acc; Test.stopTest(); /*Opportunity oppNew = new Opportunity(); oppNew.AccountId = acc.Id;*/ /*Account newAcc = [Select Name, Id, AnnualRevenue from account where Id =: acc.Id]; system.assertEquals(25000, acc.AnnualRevenue);*/ List<Opportunity> opp = [Select AccountId, id, Amount from Opportunity where AccountId =:acc.Id]; system.assertEquals(50000, opp.Amount); } }What modifications can I make in the code?
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
All Answers
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
The error is coming due to the below line:
system.assertEquals(50000, opp.Amount); ====> opp[0].Amount
Opp is a List so use the opp[0].
Thanks,
Maharajan.C
Bad Bunny Merch and @mukesh gupta I made 'system.assertEquals(50000, opp[0].Amount)'; and 'opp1.AccountId = acc.Id;' these modifications on the code and its working
Can I get some more clarity on why we are using opp[0] and not any other integer like opp[1] and when to use this?
Because we are using List that's have index 0,1,2 etc.
we can access only 0 index because Account have only one opportunity that's why we are using [0], if we try to use [1] then will face error becaue opportuity available on 0 index.
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh