You need to sign in to do that
Don't have an account?
Akash Choudhary 17
Update a Field of child record
Hi All,
I am attemption to update a field of a child object of a master detail .
Here is the code:
public class SubmitApproval {
public static void createAccountManager(List<SellerAuctionItem__c> triggerNewList){
List<string> AuctionSet = new List<String>();
for (SellerAuctionItem__c item : triggerNewList) {
if(item.Auction__c != null){
AuctionSet.add(item.Auction__r.Name);
system.debug('Name' +AuctionSet);
}
}
Map<String, Auctions__c> mapAuction = new Map<String,Auctions__c>([Select Name , Account_Manager__c From Auctions__c WHERE Name IN:AuctionSet ]);
system.debug('Name and account manager' +mapAuction);
for (SellerAuctionItem__c item : triggerNewList) {
if(item.Account_Manager__c == Null){
item.Account_Manager__c = mapAuction.get(item.Auction__c).Account_Manager__c;
} }
}
}
It is giving null pointer error : Attempt to de-reference a null object
Please help, Thanks
I am attemption to update a field of a child object of a master detail .
Here is the code:
public class SubmitApproval {
public static void createAccountManager(List<SellerAuctionItem__c> triggerNewList){
List<string> AuctionSet = new List<String>();
for (SellerAuctionItem__c item : triggerNewList) {
if(item.Auction__c != null){
AuctionSet.add(item.Auction__r.Name);
system.debug('Name' +AuctionSet);
}
}
Map<String, Auctions__c> mapAuction = new Map<String,Auctions__c>([Select Name , Account_Manager__c From Auctions__c WHERE Name IN:AuctionSet ]);
system.debug('Name and account manager' +mapAuction);
for (SellerAuctionItem__c item : triggerNewList) {
if(item.Account_Manager__c == Null){
item.Account_Manager__c = mapAuction.get(item.Auction__c).Account_Manager__c;
} }
}
}
It is giving null pointer error : Attempt to de-reference a null object
Please help, Thanks
All Answers
The problem is, You're trying to traverse on parent object and fetching its name field,
AuctionSet.add(item.Auction__r.Name);
If its a Handler class of trigger and you're passing Trigger.New to createAccountManager method as argument, you must need to query, you can't traverse like that.
Then how according to yoy the code should look like .
thanks
The code worked, but instead of the name it fetched the ID.