Changing the primary domain name on a Google Apps account is a non-trivial process. I recently needed to do this for a customer, and created a console application that makes the job easier.
Clone the GitHub project:
git clone https://github.com/dougreese/ga-change-primary-domain.git
then follow the instructions in the README to build and run.
Some additional resources: