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
poonampoonam 

Inserting a new Record in Custom Object.

Hello all,
I'm a newbie on Salesforce and still learning. I'm coming across one problem for which i need your utmost help.
 
This is for the development of Employee Info application where the detail information of each employee is feeded into the application and can be managed accordingly... so,
How can i add(insert) a new record in my custom object where i have created a custom command button.
Below is the apex code for my controller:
 
here EmpInfo__c is custom object where all the information should be saved.
 

******************************

<apex:commandButton action="{!Save}" value="Save" /> // onclick of save button, a new record should be inserted

******************************

 

 

public class EmpCon {

String[] YOE = new String[]{};

String[] Desg = new String[]{};

EmpInfo__c emp;

String Id=System.currentPageReference().getParameters().get('IDInput');

String name=System.currentPageReference().getParameters().get('NameInput');

String add=System.currentPageReference().getParameters().get('AddInput');

String phone=System.currentPageReference().getParameters().get('PhoneInput');

String dob=System.currentPageReference().getParameters().get('DOBInput');

String doj=System.currentPageReference().getParameters().get('DOJInput');

String exp=System.currentPageReference().getParameters().get('ExpInput');

String desg1=System.currentPageReference().getParameters().get('DesgInput');

String skill=System.currentPageReference().getParameters().get('SkillInput');

 

public PageReference Save() {

PageReference curPage = System.currentPageReference();

EmpInfo__c emp;

emp = new EmpInfo__c(ID__c ='Id', Name__c='name', Address__c='add', Phone__c='phone', Years_Of_Experience__c='exp', Designation__c='desg1', Skills__c='skill');


try

{

insert emp; // here is the problem... how should insert a new record???


}catch (DmlException e) {

System.debug(e.getMessage());

}

return null;

}


 

**************

 Same problem occurs for Update

SurjenduSurjendu
Insert like this:::

If TestExtranet__c is your custom object and Name__c, Extranet_Name__c and URL__ c are your fields in the custom object insert a new record the way I have mentioned below...

TestExtranet__c co = new TestExtranet__c();
co.Name__c = "hello";
co.Extranet_Name__c = "google.com";
co.URL__c="google.com";
insert co;
poonampoonam
thanks...
but the code that u helped  me with worked but its for inserting value hard core...
in my case, there is a page where in when i feed in the values in respective textbox and select respective options from drop down list and finally click on SAVE button, the value should get inserted into corresponding fields of custom object.
eg: value of employee id feeded in the Text box  should get inserted in custom object's custom field.
Hope this will help to know my issue...
thanks for concern.
 
 
arundevarundev
hii..
did u ever get it resolved  ...I am also trying to get values from the form input apex field....in overrided SAVE() function to insert a record.. but i am not able to get field values in my custom extension class.

do you know any method to read field values?

System.currentPageReference().getParameters().get('formfirstname') is NOT working ..

also ApexPage.currentPage().getParameters().get('formfirstname') too is not working.

Bhola VishwakarmaBhola Vishwakarma

It is working & I checked by taking one demo example...

I have one problem that when the value get inserted thereafter the values are there in text box but gets highlighted so how to remove text from textbox when the value get inserted instead of highlight....

I inserted value into the custom object but on the same page I need that when i insert value into object as name field then at the bottom i need thank you username so how can i achieve that....

Regards....