I need one help. I am using next and previous custom buttons on account detail page to navigate through selected account record from list view without going back to list. For this, i stored selected account record ids into local storage. This is working perfectly. but if i manually open a account record (not from list view) and click on next button than it should show pop up message as 'This was the Last Account!'. But it's showing the Account records which I selected earlier from list view of Account. For this i want to remove record ids after navigation to that page from localstorage, its not working.
Please see below code to store ids in local storage.
var accounts = {!GETRECORDIDS( $ObjectType.Account )};
if(accounts .length >= 1){
localStorage['Accounts '] = accounts ;
alert(localStorage['Accounts']);
location.replace('/' + accounts [0]);
}
The code on next account button is-
if(localStorage['Accounts']){
var accounts = localStorage['Accounts'].split(',');
var accountsPos = accounts .indexOf('{!Account.Id}');
if(accountsPos == accounts.length - 1){
alert('Last Account!');
}
else{
location.replace('/' + accounts[accountPos + 1]);
}
}
Please help.