Q:

user defined function in insert command

I created a function:
DELIMITER $$  

DROP FUNCTION IF EXISTS `heena`.`customer_id`$$ 

CREATE DEFINER=`root`@`localhost` FUNCTION  `heena`.`customer_id`(
  a varchar(20),
  b varchar(20)
) RETURNS varchar(50) CHARSET latin1     
DETERMINISTIC 
BEGIN       
   RETURN CONCAT(
            (select ((id), 0) + 1
             from heenaj),
             substring(a,1,2),
             substring(b,1,2));  
END;$$  

DELIMITER ;

The code executed fine, but when I'm inserting a value using:
insert into heenaj
   (c_id,name,number)
values
   (customer_id121("abcd",9868275817),"abcd",9868275817);

It shows an error:

Column 'c_id' cannot be null

A:

There's something wrong with your RETURN.
Maybe you are meaning to do this, although I am only guessing:
RETURN CONCAT(
            (select ifnull(max(id), 0) + 1
             from heenaj),
             substring(a,1,2),
             substring(b,1,2));

sqlfiddle
Then, you're calling customerid121() not customer_id(). Could this be typo?
Also, in looking at what you're trying to do: do you want your id as auto_increment and just want to have c_id as the id, concatenated with first 2 characters of name and concatenated with first 2 characters of number?
I suggest another solution. It might be nicer to drop your function and create a TRIGGER for before INSERT, like this:
CREATE TRIGGER set_customer_id BEFORE INSERT on heenaj
FOR EACH ROW
BEGIN
  SET NEW.c_id = CONCAT((SELECT IFNULL(MAX(id),0)+1 FROM heenaj),SUBSTRING(NEW.name,1,2),SUBSTRING(NEW.number,1,2));
END/

This way, when you insert you can just ignore c_id and insert like this:
insert into heenaj(name,number)
values ("abcd",9868);

The trigger will handle the setting of c_id for you.
sqlfiddle for TRIGGER
P.S. To create the trigger (in the sqlfiddle), I selected / as my delimiter. You might change that / to $$, since you're setting delimiter as $$.

