You need to sign in to do that
Don't have an account?
Vinay J
Test class for trigger
Dear firends,
I have two objects in lookup relationship.. Auction and Bid where bid is child.... Whenever a Auction's status is changed to Ended, amount field from bid object is copied to Auction object's field amount by a trigger.. Now, I'm writting test class where I'm creating Auction and the child Bid record..
Auction__c auction = new Auction__c();
auction.Auction_Status__c = 'Active';
auction.Bid_Amount__c = 0;
insert auction;
Bid__c bid = new Bid__c();
bid.Auction__c = auction.id;
bid.Bid_Amount__c = 10;
insert bid;
auction.Auction_Status__c = 'Ended';
update auction;
system.debug('*****Auction = ' + auction);
system.debug('*****Bid = ' + Bid);
The trigger work fine when I test from UI i.e. when I update Auction's status to Ended, Amount from bid is copied to amount on Auction. But in by test class, The debug still gives me amount as 0.
Can someone please help me in understanding why? Debug in trigger also shows the correct amount.
I have two objects in lookup relationship.. Auction and Bid where bid is child.... Whenever a Auction's status is changed to Ended, amount field from bid object is copied to Auction object's field amount by a trigger.. Now, I'm writting test class where I'm creating Auction and the child Bid record..
Auction__c auction = new Auction__c();
auction.Auction_Status__c = 'Active';
auction.Bid_Amount__c = 0;
insert auction;
Bid__c bid = new Bid__c();
bid.Auction__c = auction.id;
bid.Bid_Amount__c = 10;
insert bid;
auction.Auction_Status__c = 'Ended';
update auction;
system.debug('*****Auction = ' + auction);
system.debug('*****Bid = ' + Bid);
The trigger work fine when I test from UI i.e. when I update Auction's status to Ended, Amount from bid is copied to amount on Auction. But in by test class, The debug still gives me amount as 0.
Can someone please help me in understanding why? Debug in trigger also shows the correct amount.
Then do you assert on updatedBid to make sure it was actually updated.
for(Auction__c endedAuction : listEndedAuctions) {
//For all ended auctions, create a list of consumer payments to be created.
Payment__c accountPayment = new Payment__c();
accountPayment.Account__c = endedAuction.Registered_Charity__c;
accountPayment.Payment_Amount__c = endedAuction.Bid_Amount__c;
accountPayment.Payment_Status__c = sPending;
accountPayment.Payment_Date__c = date.newInstance(dPresentDate.year(), dPresentDate.month(), 1);
add to payment__c list..
}
insert list;
In the test class, I've written like..
Account acc = new Account();
acc.name = 'Test';
insert acc;
Auction__c auction = new Auction__c();
auction.Auction_Status__c = 'Active';
auction.Bid_Amount__c = 0;
auction.account = acc.id;
insert auction;
Bid__c bid = new Bid__c();
bid.Auction__c = auction.id;
bid.Bid_Amount__c = 10;
insert bid;
auction.Auction_Status__c = 'Ended';
update auction;
bid__c bid1 = [Select id, bid_amount__c from bid__c where auction__c = : auction.id];
system.debug('*****bid1 = ' + bid1);
payment__c pay = [Select id, name, payment_amount__c from payment__c where account__c = :acc.id];
system.debug('*****pay = ' + pay);
*************************
on the query.. payment__c pay = [Select id, name, payment_amount__c from payment__c where account__c = :acc.id]; , I get error list has no row for assignment....
But the functionality is working fine when I tested from UI... Payment did get created when a acution record is updated to Ended.