\affiliation command is not working in Overleaf or in Elsevier's manuscript submission system. But the documentation and templates in elsarticle package in CTAN (elsarticle version 3.3) has \affiliation coding. What to do?
overleaf has version 3.2 but you can use the documentation for that version which is on overleaf– David CarlisleJul 8, 2021 at 7:28
The elsarticle.zip (version 3.3) which is available on https://ctan.org/tex-archive/macros/latex/contrib/elsarticle is the latest one and \affiliation command will certainly work without any problem as given in the templates and documentation. However I am afraid some cloud-based LaTeX editors does not have the latest version packages in their TeX repositories.
You may always do a work around to overcome the problem. You may upload the latest elsarticle.cls also along with your manuscript to these interfaces (eg: Overleaf) or the publisher's manuscript submission portal or even in your working folder.
The elsarticle.zip does not contain elsarticle.cls seperately as in any other TeX packages, but you can run latex or pdflatex on elsarticle.ins which is available in the package (elsarticle.zip) which will provide you the elsarticle.cls. Alternatively you may just install the package using any package installer which will do all these steps by itself.
Hope it is clear now.
You can get an up to date version of
elsarticle.cls from the Overleaf template project.
At time of writing, the Overleaf environment has version 3.2 installed of the elsarticle class. If you declare:
... then in the overleaf log, within the top ten lines, you can see ...
L3 programming layer (/usr/local/texlive/2020/texmf-dist/tex/latex/elsarticle/elsarticle.cls Document Class: elsarticle 2019/02/25, 3.2: Elsevier Ltd \@bls=\dimen134
This is annoying. However the overleaf template project is up to date at 3.3. You can copy
elsarticle.cls from there into your own project, and it will resolve to the project-local version before the general environment.
This simplifies the workaround from @user30304, as you won't have to run latex on the CTAN package, but can get the contents directly.
But if you are watching, Overleaf overmind, please keep your installed packages up to date. Or consider some more version-aware package dependency settings.