I would like my own defined examples to appear as "List of examples" in the
table of contents and face the following two problems. 

First and foremost,
when using `tocloft`, I obtain an error (see 'Problem 1:' below). Why is `tocloft` complaining about the example environment being already defined? (isn't that the default case, that I already have an environment defined and would like it to appear in the toc?).

Second, I
would like to avoid the unnecessary indentation before the section number in the
toc (see 'Problem 2:' below; this already works for figures, but I guess a
`tocloft`-based approach might be cleaner). Also note that the space between the chapter/section/subsection number and the text in the list of figures should ideally be larger (comment out the list of examples to see the problem for the list of figures).

Note: The solution does not necessarily have to work with tocloft (see the 'history' below), I just thought it might be easier. If there is another solution, that's fine, too, but it should work with the defined example environments (amsthm/amstools). In the end, the list of figures and list of examples should look the same. 

**History/background**

Concerning Problem 1, I originally followed the solution [here](https://tex.stackexchange.com/questions/16494/generating-lists-of-custom-environment)
but as correctly noted [here](https://tex.stackexchange.com/questions/267810/formatting-list-of-something-in-accordance-to-koma-script)
this does not give the same format as the list of figures when using
Komascript. Also, I did not manage to adapt it to solve Problem 2.

```
\documentclass[listof=totoc]{scrbook}
\usepackage[american]{babel}
\usepackage{scrlayer-scrpage}
\usepackage{todonotes}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{tocloft}

% For examples
\declaretheoremstyle[%
  spaceabove=0.5em,
  spacebelow=0.5em,
  headfont=\sffamily\bfseries,
  notefont=\sffamily\bfseries,
  notebraces={(}{)},
  headpunct={},
  bodyfont=\normalfont,
  postheadspace=\newline
]{myexstyle}
\declaretheorem[style=myexstyle, numberwithin=section]{example}

% For list of examples in toc
% Problem 1: The following fails with error "Package tocloft Error: example has been previously defined."
\newcommand{\listexamplename}{List of examples}
\newlistof[section]{example}{loe}{\listexamplename}

% For list of figures in toc
\numberwithin{figure}{section}
\renewcommand*{\listfigurename}{List of figures}
% Remove overall left indentation of all figures in "List of figures"
% Problem 2: The following works but as numbers get too large, there is not enough space
\makeatletter
\renewcommand*\l@figure{\@dottedtocline{1}{0em}{2.3em}}
\let\l@table\l@figure
\makeatother

\begin{document}
\tableofcontents
\listofexamples
\listoffigures
\clearpage
% Dummy content
\setcounter{chapter}{1}
\setcounter{section}{2}
\setcounter{example}{3}
\begin{example}
  Dummy example 1.
\end{example}
\begin{figure}
  \missingfigure{}
  \caption{Dummy figure 1.}
\end{figure}
\setcounter{chapter}{10}
\setcounter{section}{11}
\setcounter{example}{12}
\begin{example}
  Dummy example 2.
\end{example}
\begin{figure}
  \missingfigure{}
  \caption{Dummy figure 2.}
\end{figure}
\end{document}

```

**Update**

This is a revised version after Pietvo's first suggested solution. It shows that
environments other than examples are also listed. How can this be avoided? Also,
why do the lof and loe not appear in the toc?

```
\documentclass[listof=totoc]{scrbook}
\usepackage[american]{babel}
\usepackage{scrlayer-scrpage}
\usepackage{todonotes}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{tocloft}

% For examples
\declaretheoremstyle[%
  spaceabove=0.5em,
  spacebelow=0.5em,
  headfont=\sffamily\bfseries,
  notefont=\sffamily\bfseries,
  notebraces={(}{)},
  headpunct={},
  bodyfont=\normalfont,
  postheadspace=\newline
]{myexstyle}
\declaretheorem[style=mythmstyle, numberwithin=section]{definition}
\declaretheorem[style=myexstyle, sibling=definition]{example}

% Kill the counter; see https://tex.stackexchange.com/questions/332398/how-to-obtain-list-of-examples-in-the-toc
\makeatletter
\let\c@example\relax
\makeatother

% For list of examples in toc
\newcommand{\listexamplename}{List of examples}
\newlistof[section]{example}{loe}{\listexamplename}
\cftsetindents{example}{0mm}{4em}% omit left indent

% Adapted from https://tex.stackexchange.com/questions/16494/generating-lists-of-custom-environment
\makeatletter
\def\ll@example{%
  \protect\numberline{\csname the\thmt@envname\endcsname}%
  \thmt@shortoptarg}
\makeatother

% For list of figures in toc
\numberwithin{figure}{section}
\cftsetindents{fig}{0mm}{4em}% omit left indent

\begin{document}
\tableofcontents
\listofexample
\renewcommand*{\listfigurename}{List of figures}% needs to be here to be respected
\listoffigures
\clearpage
% Dummy content
\setcounter{chapter}{1}
\setcounter{section}{2}
\setcounter{example}{3}
\begin{definition}[Dummy definition header]
  Dummy definition.
\end{definition}
\begin{example}[Dummy example header 1]
  Dummy example 1.
\end{example}
\begin{figure}
  \missingfigure{}
  \caption{Dummy figure 1.}
\end{figure}
\setcounter{chapter}{10}
\setcounter{section}{11}
\setcounter{example}{12}
\begin{example}[Dummy example header 2]
  Dummy example 2.
\end{example}
\begin{definition}[Dummy definition header 2]
  Dummy definition.
\end{definition}
\begin{figure}
  \missingfigure{}
  \caption{Dummy figure 2.}
\end{figure}
\end{document}

```