Samuel von Triewald, 1688-1742, författare, ämbetsman