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
niharnihar 

Please could you help me to get the correct code to the below issue? Illegal assignment from Schema.SObjectField to String

<apex:page controller="EnrollmentFormClass" showHeader="false" sidebar="false">
    <apex:form >
    <apex:pageBlock title="Opportunitiy Zone Enrollment Form" id="pb1">
            <apex:pageBlockSection columns="3">
                <apex:inputField value="{!primarycontact.Student_Name__c}"/>
                <apex:inputField value="{!primarycontact.School__c}"/> 
                <apex:inputField value="{!primarycontact.Date__c}"/>     
            </apex:pageBlockSection>     
            <br/> 
            <br/>
                    SPARC programs are funded by United Way of Greater Atlanta. As such, we are required to report demographic, income, educational and health access information on every individual/family we serve. With the United Way belief that serving one family member serves them all, we collect general information on each member of your household. We appreciate your willingness to complete this form in its entirety so that we can continue providing free programs to the community. Thank you!
            <br/>  
            <br/> 
            <apex:pageBlockSection title="Head of Household Information:">
                <apex:inputField value="{!primarycontact.FirstName}"/>
                <apex:inputField value="{!primarycontact.LastName}"/>
                <apex:inputField value="{!primarycontact.Date_of_Birth__c}"/>
                <apex:inputField value="{!primarycontact.Gender__c}"/> 
                <apex:inputField value="{!primarycontact.Do_you_have_a_primary_medical_provider__c}"/>
                <apex:inputField value="{!primarycontact.Do_you_have_a_primary_medical_provider__c}"/>
                <apex:inputField value="{!primarycontact.Address__c}"/>
                <apex:inputField value="{!primarycontact.City__c}"/>
                <apex:inputField value="{!primarycontact.State__c}"/>
                <apex:inputField value="{!primarycontact.County__c}"/>
                <apex:inputField value="{!primarycontact.Phone__c}"/>
                <apex:inputField value="{!primarycontact.Email_Address__c}"/>
                <apex:inputField value="{!primarycontact.Preferred_Method_of_Contact_Circle_One__c}"/>
            </apex:pageBlockSection>
        
            <apex:pageBlocksection title="Demographic Data: (All information is confidential and is used in applying for grants to fund this program.)" columns="3">
                <apex:inputField value="{!primarycontact.Spanish_translation_Services_Needed__c}"/>
                <apex:inputField value="{!primarycontact.Race_Check_One__c}"/>
                <apex:inputField value="{!primarycontact.Marital_Status_check_one__c}"/>
                <apex:inputField value="{!primarycontact.HIGHEST_LEVEL_OF_EDUCATION_Check_one__c}"/>
                <apex:inputField value="{!primarycontact.Employment_check_one__c}"/>
            </apex:pageBlocksection>
        
            <apex:pageBlocksection title="Income:" columns="3">
                <apex:inputField value="{!primarycontact.Annual_Income__c}"/> 
                <apex:inputField value="{!primarycontact.Source_of_Income__c}"/> 
                <apex:inputField value="{!primarycontact.Primary_Method_of_Transportation__c}"/>
            </apex:pageBlocksection>
        
            <apex:pageBlocksection title="HOUSEHOLD Information:" columns="3">
                <apex:inputField value="{!othercontact.Other_Adult_First_Name__c}"/>
                <apex:inputField value="{!othercontact.LastName}"/>
                <apex:inputField value="{!othercontact.Date_of_Birth__c}"/>
                <apex:inputField value="{!othercontact.Gender__c}"/> 
                <apex:inputField value="{!othercontact.Relationship_Primary_Care_Provider__c}"/>
                <apex:inputField value="{!othercontact.Medical_Insurance__c    }"/>   
            </apex:pageBlocksection>
               
            <apex:pageBlocksection title="Children (all children currently in your household, INCLUDING those participating in this program):" columns="1" />
                <apex:variable var="rowNum" value="{!0}"/>
                <!--<apex:pageBlock id="membAdd"/> -->  
                <apex:variable var="rowNum" value="{!0}"/> 
        
            <apex:pageblockSection id="pbs1">
                <apex:pageBlockTable value="{!ContactList}" var="c">
                <apex:column headerValue="Number" style="width:20px; text-align:center;" headerClass="centertext">
                <apex:outputText value="{0,number, ###}" style="text-align:center;">   
                <apex:param value="{!rowNum+1}"/>   
                </apex:outputText>
                </apex:column>
                 
                <apex:column headerValue="Name"> 
                <apex:inputfield value="{!c.lastName}"/>    
                </apex:column>
                    
                <apex:column headerValue="Delete">
                <apex:commandLink style="font-size:15px; font-weight:bold; text-align:center;color:red;" value="X" action="{!delRow}" reRender="pbs1" rendered="{!rowNum>0}">
                <apex:param value="{!rowNum}" name="index"/>
                </apex:commandLink>
                <apex:variable var="rowNum" value="{!rowNum+1}"/> 
                </apex:column>      
             
                <apex:column headerValue="AddRow">
                <apex:commandButton value="Add Row" action="{!addRow}"/>  
                </apex:column>
                     
            </apex:pageBlockTable>
            </apex:pageblockSection>
            <apex:commandButton value="Save" action="{!save}"/> 
        
    </apex:pageBlock>
   </apex:form>
</apex:page>

public class EnrollmentFormClass {
public Contact primarycontact{get;set;}
public Contact othercontact{get;set;}
public Contact childcontact{get;set;}
public List<Contact> ContactList{get;set;} 
public Account acc{get;set;}
public Household__c hoh{get;set;}    
public String ContactName {get;set;}
public Integer rowNum{get;set;}
    
public EnrollmentFormClass() {
       primarycontact  = new Contact();
       othercontact    = new Contact();
       childcontact    = new Contact(); 
       acc             = new Account();
       hoh             = new Household__c();
       String sql      = 'SELECT Name FROM Contact';
       ContactList     = Database.Query(sql); 
       ContactList     = new List<Contact>();   
       ContactList.Add(new Contact());
       }
    
public void AddRow(){
       childcontact = new Contact();
       ContactList.Add(childcontact);
       }
    
public void delRow() {
       rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
       ContactList.remove(rowNum);     
       }   
    
public void save(){
       insert  primarycontact;  
       acc.name = primarycontact.lastName;
       acc.name = Household__c.Name;
       insert acc;     
       primarycontact.accountId = acc.id;
       upsert primarycontact;
       othercontact.accountId = acc.id;
       othercontact.Contact1__c = primarycontact.Id; 
       insert othercontact;    
       for(contact cc : ContactList){
       cc.accountId = acc.id;
       cc.Contact1__c = primarycontact.Id;
       }
       upsert  ContactList;
       }
       }
Best Answer chosen by nihar
Vinod ChoudharyVinod Choudhary
Hi Nihar,

Use     String.valueOf()  where you are getting error.

Hope this will help you :)

Thanks
Vinod