You need to sign in to do that
Don't have an account?
Invalid Id Error calling map
Hi All,
I'm getting an invalid id error when I call userAccounts.get(p.Ownerid).AccountId; I think I may be populating my userAccounts map incorrectly?
I'm getting an invalid id error when I call userAccounts.get(p.Ownerid).AccountId; I think I may be populating my userAccounts map incorrectly?
list<ID> pubIds = new list<ID>(); for(Publication__c p: pubList){ pubIds.add(p.id); } list<ID> UserIds = new list<ID>(); for(Publication__c p: pubList){ UserIds.add(p.ownerid); } map<id,user> userAccounts = new map <id, user>([SELECT Id, Name, AccountId FROM User WHERE Id IN :UserIds AND IsActive = true]); list<Publication__c> pubsToUpdate = [SELECT ID, ownerId FROM Publication__c WHERE ID in: pubIds]; for(Publication__c p: pubsToUpdate){ p.Next_Object__c = stepOneMap.get(p.Id).id; if(userAccounts.get(p.OwnerId).AccountId !=''){ p.Account__c = userAccounts.get(p.Ownerid).AccountId; } } Update pubsToUpdate;
I beleive the problem was due to my null check. I had used AccountId !='' when I should have used AccountId !=null.
This solved the "invalid ID" error.
Thanks for your help!
All Answers
pLease update your code like below
Let us know if this will resolve your issue
This helps with my null check, but I'm still getting an invalid ID error:
p.Next_Object__c = stepOneMap.get(p.Id).id;
I hope account__c is account lookup only ?
p.Account__c = userAccounts.get(p.Ownerid).AccountId;
I beleive the problem was due to my null check. I had used AccountId !='' when I should have used AccountId !=null.
This solved the "invalid ID" error.
Thanks for your help!