Created
July 17, 2017 07:40
-
-
Save swapnilshrikhande/8f47a0e94178c09e41c251fb16507af4 to your computer and use it in GitHub Desktop.
Clean method to remove nulls from sobject list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Account firstAccount = new Account(Name='Test 5'); | |
Account secondAccount = new Account(Name='Test 6'); | |
Account thirdAccount = new Account(Name='Test 7'); | |
List<Account> accountList = new List<Account>{null, firstAccount, null, secondAccount, null, null , thirdAccount, null }; | |
List<Sobject> clean(List<SObject> inputSobjectList){ | |
Integer listSize = inputSobjectList.size(); | |
for(Integer index=0;index < listSize; ++index){ | |
if( inputSobjectList[index] == null ){ | |
inputSobjectList.remove(index); | |
--listSize; | |
--index; | |
} | |
} | |
return inputSobjectList; | |
} | |
insert clean(accountList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment