How to get postname in custom page?

You can use sanitize_title() on the page title:

http://codex.wordpress.org/Function_Reference/sanitize_title

and then you might try something like this:

$my_page_title = "My page name";

$my_page_slug = sanitize_title($my_page_title); 
// or you can set the slug you want:
//$my_page_slug = "my-slug-for-this-page"; 

$my_page_content = "This is my page content";

// Create page object
$my_page = array(
  'post_title'    => $my_page_title,
  'post_name'    => $my_page_slug,
  'post_content'  => $my_page_content,
  'post_status'   => 'publish',
  'post_type'   => 'page',
  'post_author'   => 1,
);

// Insert the page into the database
wp_insert_post( $my_page );

When updating a page, assuming you have access to the page ID, use the following code to prevent duplicate entries:

$my_page = array(
  'ID'            => $my_page_id // current page ID
  'post_title'    => $my_page_title,
  'post_name'     => $my_page_slug,
  'post_content'  => $my_page_content,
  'post_status'   => 'publish',
  'post_type'     => 'page',
  'post_author'   => 1,
);

// Update page
wp_update_post( $my_page );

Note that you only need to pass changed values to wp_update_post (so if you’ve only changed the page content, you should pass $my_page_content only)

error code: 523