Putting your hand to your heart after a greeting someone is a way of showing that you greeted them sincerely and is done whether people shake hands or do otherwise.
Maintaining good relationships with others is really important in Indonesia, and keeping up appearances and showing respect to whom respect is due are key parts of how people keep their relationships strong. Hierarchy, or how things are ordered, is also really important, especially when age is taken into account. And greetings are an ordinary but socially important way of showing respect, specifically, who is older than who. Here, let me show you an example of this: if there is a big event at school, every important person is introduced by title in the order of respect that their position deserves. But when there is a big difference in age between two people, that matters more than a person’s title, at least in terms of courtesy. For example, a principal is given a lot of respect because of his position, so he is introduced first, but he would still greet a really old person by putting that person’s hand to his forehead, communicating his respect. Or if an adult met a certain person for the first time who was obviously a lot older that the first person, then the younger adult might put the elder’s hand to her forehead, even though she herself is an adult.
Another way of showing respect to others and by honoring people according to their age is by using words that are similar in function to Mr./Mrs./Ms.