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
Jainendra Jeet 6Jainendra Jeet 6 

Getting Input from user on VF page for entering records for custom objects

Hi All,

I am a newbie to Salesforce .

I am trying to get input from user on Visualforce page for entering Custom object's records.

Custom Object : Merchandise_c
Apex :
<apex:page controller="Merchandise_Input" >
  <apex:form >
  <apex:inputText value="{!Name}" />
  <apex:commandButton value="save" action="{!save}"/>
  
  </apex:form>
</apex:page>
Controller
public with sharing class Merchandise_Input {
public String Name { get; set; }

    public void save() {
   //Merchandise_c Mer = new Merchandise_c();
    Merchandise_c.Name = 'Laptop';
       }}

Tried to get input on save button cant succeded so tried to hard code it .
Getting error :
Error: Merchandise_Input Compile Error: Variable does not exist: Merchandise_c.Name at line 6 column 5
Pramodh KumarPramodh Kumar

After initialing the object reference try to use, the object alias name with your field name.

Ex: Merchandise_c mdr = new Merchandise_c;
      mdr.name = name; 

 
Jainendra Jeet 6Jainendra Jeet 6
Hi Pramod,'
I had tried it already 
Merchandise_c mer = new Merchandise_c();
        mer Name = Name;
its giving error Compile Error: Invalid type: mer at line 7 column 9
Pramodh KumarPramodh Kumar
. is mising in object reference after the name... please use this

mer.name = name;
Jainendra Jeet 6Jainendra Jeet 6
Error gone but it cant able to save value in records for Custom Object
 
Jainendra Jeet 6Jainendra Jeet 6
i have hard coded it like mer.Name = 'test'; but its not replicating in custom object record