In the following MWE
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[pdftex,unicode,final]{hyperref}
\input{glyphtounicode}
\pdfgentounicode=1
\makeatletter
\newcommand*{\boilerplate}{\@ifstar\@@boilerplate\@boilerplate}
\newcommand*{\@boilerplate}{Boilerplate for running text}
\newcommand*{\@@boilerplate}{Boilerplate for headings in capalized form}
\makeatother
\begin{document}
\section{\boilerplate*}
\end{document}
the star is used to obtain an alternative variant of the boilerplate. The MWE fails with
Token not allowed in a PDF string (Unicode):
(hyperref) removing `\@ifnextchar' on input line 19.
Obviously, the problem is the order of macro expansions. I have already tried to play around with \expandafter but did not find a solution.
Remark: If possibly, I would like to keep the starred-version to select the variant of the boilerplate. This design has been agreed upon some time ago and is used at myriads of places. In other words changing the macro definition to something like \boilerplateNormal and \boilerplateVariant is not an option, because that would break compatibility with other authors using the sty-file.

\section{$\setminus$boilerplate*}– M S May 28 '19 at 10:35\@ifnextchar(used in\@ifstar) is not expandable, and text in pdf strings (such as section titles) must expand completely. It is possible to make the command expandable but your\boilerplatecommand would require at least a final mandatory argument:\section{\boilerplate*{}}or\section{\boilerplate{}}. – Phelype Oleinik May 28 '19 at 10:37\texorpdfstring, see https://tex.stackexchange.com/questions/53513/hyperref-token-not-allowed. – Marijn May 28 '19 at 10:49pdftexoption. – egreg May 28 '19 at 10:49