function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JayeeJayee 

how to bind firstname , lastname in contact object list to show on the table row

i have this code
public void addMore() {
        try{

            string nameT  = Apexpages.currentPage().getParameters().get('nameT');
            string phoneT = Apexpages.currentPage().getParameters().get('phoneT');
            string emailT = Apexpages.currentPage().getParameters().get('emailT');
            //string temporaryLastNameValue;
            //string temporaryFirstNameValue;

            system.debug('[addMore] param : ' +nameT + '//' + phoneT + '//' + emailT);


            Contact att = new Contact();
            att.lastname = nameT;

            att.phone = phoneT;
            att.email = emailT;


            contactList = new List<Contact>();
List<Contact> con = [SELECT Name, FirstName, LastName FROM Contact WHERE Name =  : nameT];

            contactList.add(att);    

            insert contactList;

//it displays nothing on the row...
//maybe it needs to be bind both firstname and lastname

        }catch(Exception e){
            System.debug('[CONTACT] message     : ' + e.getMessage());
            System.debug('[CONTACT] LineNumber  : ' + e.getLineNumber());
            System.debug('[CONTACT] Cause       : ' + e.getCause());
        }

system.debug('[addMore] param : ' +nameT + '//' + phoneT + '//' + emailT);
-> parameter value shows fullname but
in org's row , it shows nothing
to show this on the table row how should i edit these codes?

Thank you!
Ajay K DubediAjay K Dubedi
Hi Jayee,

You can do like this. Please try below code.

Hope this helps you.

public void addMore() {
try{

    string nameT  = Apexpages.currentPage().getParameters().get('nameT');
    string phoneT = Apexpages.currentPage().getParameters().get('phoneT');
    string emailT = Apexpages.currentPage().getParameters().get('emailT');
    //string temporaryLastNameValue;
    //string temporaryFirstNameValue;

    system.debug('[addMore] param : ' +nameT + '//' + phoneT + '//' + emailT);

    List<String> nameList = new List<String>();
    
    //split your name in which form you are entering like entering space or hyphen etc.
    nameList = nameT.split('-');

    system.debug('Split Name List is::: '+nameList);
    system.debug('nameList[0]--->'+nameList[0]);
    system.debug('nameList[1]--->'+nameList[1]);

    contactList = new List<Contact>();

    Contact att = new Contact();
    att.Firstname = nameList[0];
    att.LastName = nameList[1];

    att.phone = phoneT;
    att.email = emailT;
    
    contactList.add(att);    

    insert contactList;


    List<Contact> con = [SELECT Name, FirstName, LastName FROM Contact WHERE Name =  : nameT];
    
    
}
catch(Exception e){
    System.debug('[CONTACT] message     : ' + e.getMessage());
    System.debug('[CONTACT] LineNumber  : ' + e.getLineNumber());
    System.debug('[CONTACT] Cause       : ' + e.getCause());
}

Please mark it as best answer if you find helpful.

Thank You
Ajay Dubedi
JayeeJayee
Hi Ajay
Thank you for your comment.
i tried this code but i wont work like this
User-added image
Ajay K DubediAjay K Dubedi
Can you please share your Url and code, so that we can check where we are getting wrong.