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 

Field is not writeable: Contact.Name


it keeps return not writeable error... how should i resolve this error?
 
private List<Contact> contactList;

   public void addMore() {
    

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

    system.debug(nameT + '//' + phoneT + '//' + emailT);


    Contact att = new Contact();

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

    contactList.add(att);


 //i want this parameters to List value but it doesnt work properly..
Best Answer chosen by Jayee
v varaprasadv varaprasad
Hi Jayee,

Please use Lastname instead of name in caontact .

 
Contact att = new Contact();

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

insert att;

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com

All Answers

v varaprasadv varaprasad
Hi Jayee,

Please use Lastname instead of name in caontact .

 
Contact att = new Contact();

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

insert att;

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
This was selected as the best answer
Amit Chaudhary 8Amit Chaudhary 8
Name field on contact is combination of FirstName and LastName. So Use FirstName and LastName Field in your code like below
private List<Contact> contactList;

   public void addMore() {
    

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

    system.debug(nameT + '//' + phoneT + '//' + emailT);


    Contact att = new Contact();
    att.LastName= nameT;
    att.phone = phoneT;
    att.email = emailT;
    contactList.add(att);


Let us know if this will help you
JayeeJayee
it works tho but

Attempt to de-reference a null object 
An unexpected error has occurred. Your development organization has been notified.


it keeps displaying this message

function of the code click and add row child to parent
User-added image

Parent
<script> 
function str1(name,phone,email)
 {  
  console.log(name + '//' + phone+ '//' + email);
  valueSet(name, phone, email);
 }
</script>

<input type="hidden" id="cname" value="str1()"/>
<apex:actionFunction action="{!addMore}" name="valueSet" reRender="table_panel">
         <apex:param name="nameT" value=""/>
        <apex:param name="phoneT" value=""/>
        <apex:param name="emailT" value=""/>
      </apex:actionFunction>

Child
<script> 
 function addRow(index)
 {  
      console.log(index);
    var nameVal = document.getElementById('contactName_'+index).value;
    var phoneVal = document.getElementById('contactPhone_'+index).value;
    var emailVal = document.getElementById('contactEmail_'+index).value;
    console.log(nameVal);
    console.log(phoneVal);
    console.log(emailVal);

  window.opener.str1(nameVal,phoneVal,emailVal);
  window.opener.winClose();
  }

</script>
 <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">
               <apex:variable var="index" value="{!0}"/>
            <apex:pageBlock id="searchResults"> 
              <apex:pageBlockTable value="{!results}" var="a" id="tblResults">

                <apex:column>
                  <apex:facet name="header">
                    <apex:outputPanel >Name</apex:outputPanel>
                  </apex:facet> 
                 <a id="clickFtn" href="javascript:void(0);" onclick="addRow('{!index}')">  
                  <input type="hidden" value="{!a.name}" id="contactName_{!index}"/>
                  <input type="hidden" value="{!a.phone}" id="contactPhone_{!index}"/>
                  <input type="hidden" value="{!a.email}" id="contactEmail_{!index}"/>
                  {!a.Name}</a>
                  <apex:variable var="index" value="{!index+1}"/>
               </apex:column>
                 <apex:column id="contactPhone">
                  <apex:facet name="header">
                    <apex:outputPanel >Phone</apex:outputPanel>
                  </apex:facet>
                  {!a.Phone}
               </apex:column>
                  <apex:column id="contactEmail">
                  <apex:facet name="header">
                    <apex:outputPanel >Email</apex:outputPanel>
                  </apex:facet>
                 {!a.Email}
               </apex:column>
            
              </apex:pageBlockTable>
            </apex:pageBlock>
          </apex:outputPanel>

 
JayeeJayee

situation is , get selected child parameter value  1. name , 2.phone 3.email  add on parent under row. but it won't works well..

Thank you for your reply