You need to sign in to do that
Don't have an account?
Ish
How to insert data to a custom object using apex controller
Hi,
I have created a UserDetail custom object. I tried to insert data into the object using binding.create() and passed the sObject. I got an error message stating "Only concrete SObject lists can be created ". How can acheive this task.
Thanks in Advance
Hey
Yeah I think you were looking at the wrong API initially, at least you got the insert sorted out. To perform an update you'd need to fetch the data
UserDetail__c u = [SELECT first_name__c FROM UserDetail__c WHERE last_name__c='Smith'];
u.first_name__c = 'Jim';
update u;
You may also want to look into 'upsert', which is a command that intelligently decides whether to insert or update a record e.g.
UserDetail__c u;
try{
u = [SELECT first_name__c FROM UserDetail__c WHERE last_name__c='Smith']; //try to fetch the record
} catch (System.QueryException e){
System.debug(e);
u = new UserDetail__c(last_name__c='Smith'); // no user with surname smith exists so create one
}
u.first_name__c = 'Jim';
upsert u; // if it's a new record insert it. if it's a change to a record perform update
Cheers,
Wes
All Answers
Hey
Are you using Java? Can you post a bit more code please?
Wes
Hi
I have used the following code to insert the data and it does the insert properly. Now i would like to know how to update the data.
Hey
Yeah I think you were looking at the wrong API initially, at least you got the insert sorted out. To perform an update you'd need to fetch the data
UserDetail__c u = [SELECT first_name__c FROM UserDetail__c WHERE last_name__c='Smith'];
u.first_name__c = 'Jim';
update u;
You may also want to look into 'upsert', which is a command that intelligently decides whether to insert or update a record e.g.
UserDetail__c u;
try{
u = [SELECT first_name__c FROM UserDetail__c WHERE last_name__c='Smith']; //try to fetch the record
} catch (System.QueryException e){
System.debug(e);
u = new UserDetail__c(last_name__c='Smith'); // no user with surname smith exists so create one
}
u.first_name__c = 'Jim';
upsert u; // if it's a new record insert it. if it's a change to a record perform update
Cheers,
Wes
This is the Scenerio, I want the new case will be build and all the records which are on fields on VF page, will go into comments?
IS it possible,
Actually, its a page, where customer will enter the information and once the customer hit Submit Button, then a new case will be build and it will insert all the record into a new case Comments field.
Help me guys.