As I understood the macro \AtBeginDocument, whatever it says will be run right after \begin{document}. In other words, it will follow whatever else there is in the preamble. But I've noticed that it matters when in the preamble \AtBeginDocument is run. Consider the following example, taken from Cite and sort author with lowercase prefix (biblatex).
When the line \AtBeginDocument{\toggletrue{blx@useprefix}} is placed before biblatex is loaded, the author van Helten is sorted under v in the bibliography. The biblatex option useprefix has in other words been changed to true. This is expected, since \toggletrue{blx@useprefix} is activated at the beginning of the document, thus overriding the option useprefix = false which was set in the preamble.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{filecontents}
\AtBeginDocument{\toggletrue{blx@useprefix}}
\usepackage[style=authoryear, useprefix = false]{biblatex}
\renewbibmacro*{begentry}{\midsentence}
\begin{filecontents}{\jobname.bib}
@ARTICLE{vanhelten1891,
AUTHOR = "W. van Helten",
TITLE = "Grammatisches",
JOURNALTITLE = "Beiträge zur Geschichte der deutschen Sprache und Literatur",
YEAR = "1891",
PAGES = "455--488",
VOLUME = "15"}
@BOOK{mccartney1967,
AUTHOR = "Paul McCartney",
TITLE = "Hey Jude",
YEAR = "1967"}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\cites{vanhelten1891}{mccartney1967}
\printbibliography
\end{document}

But when \AtBeginDocument{\toggletrue{blx@useprefix}} is placed after biblatex is loaded, the author van Helten is sorted under h in the bibliography. The biblatex option useprefix = false has in other words not been overridden by \toggletrue{blx@useprefix}. Why is this? Shouldn't \AtBeginDocument{\toggletrue{blx@useprefix}} be executed last anyway, and therefore override whatever the option useprefix is set to in the preamble?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{filecontents}
\usepackage[style=authoryear, useprefix = false]{biblatex}
\AtBeginDocument{\toggletrue{blx@useprefix}}
\renewbibmacro*{begentry}{\midsentence}
\begin{filecontents}{\jobname.bib}
@ARTICLE{vanhelten1891,
AUTHOR = "W. van Helten",
TITLE = "Grammatisches",
JOURNALTITLE = "Beiträge zur Geschichte der deutschen Sprache und Literatur",
YEAR = "1891",
PAGES = "455--488",
VOLUME = "15"}
@BOOK{mccartney1967,
AUTHOR = "Paul McCartney",
TITLE = "Hey Jude",
YEAR = "1967"}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\cites{vanhelten1891}{mccartney1967}
\printbibliography
\end{document}

\AtBeginDocumentmacro appends its contents to a token list, which is expanded right after\begin{document}. Hence, if you first issue\AtBeginDocument{\toggletrue{blx@useprefix}}andbiblatexappends\togglefalse{blx@useprefix}, because it is loaded afterwards the togglefalse part stands last and "wins". – Henri Menke May 15 '14 at 15:37biblatexalso appends\togglefalse{blx@useprefix}to the same "token list" that\AtBeginDocumentappends\toggletrue{blx@useprefix}to? – Sverre May 15 '14 at 15:40biblatexcode. – Henri Menke May 15 '14 at 15:43\AtBeginDocument{...\blx@bblinput...}where\def\blx@bblinput{...\blx@blxinit...}and\appto\blx@blxinit{...\def\ifuseprefix{\iftoggle{blx@useprefix}...}. Hence\toggle____{blx@useprefix}is buried deep inside\AtBeginDocument. – Henri Menke May 15 '14 at 15:49\AtBeginDocumentis not a token list, but a macro, which is extended via\g@addto@macroon every occurrence. – Henri Menke May 15 '14 at 15:54