You need to sign in to do that
Don't have an account?

Reg: Cloning records in page block table
Hi,
I have a page block table, in which i need to display Action name="clone" (Commandlink) and Name,city__c values from a custom object (like as shown below)
Action Name City
clone A1 Hyd
clone A2 Jaipur
When i click on clone button, i need to add the same record again(below that existing record).
Can any one help me to solve this.
Thanks,
ANKITA
just pass the id as parameter and fetch all the fields from the record using SOQL and then clone the record and insert it.
It will be like this
Like assuming your obbject name is Contact and Id of the record for which you clicked command link is 00390000006ZfHn
so it will be assigned to some property like
public String IdOfRecordtoclone{get;set;}
//Please add all the field API name for slection so that complete record gets cloned.
Contact c = [Select FirstName , LastName , Email,Titile From Contact where id =: IdOfRecordtoclone];
Contact cloneContact = c.clone(false);
insert cloneContact ;
let me know if any issue in it.
All Answers
just pass the id as parameter and fetch all the fields from the record using SOQL and then clone the record and insert it.
It will be like this
Like assuming your obbject name is Contact and Id of the record for which you clicked command link is 00390000006ZfHn
so it will be assigned to some property like
public String IdOfRecordtoclone{get;set;}
//Please add all the field API name for slection so that complete record gets cloned.
Contact c = [Select FirstName , LastName , Email,Titile From Contact where id =: IdOfRecordtoclone];
Contact cloneContact = c.clone(false);
insert cloneContact ;
let me know if any issue in it.
Yes. Its working.
You are too gr8 yar.
Thanku so much
ANKITA
hi what is the difference between c.clone(false) and c.clone(true).
Regards:
ANKITA
c.Clone(true) has the all the fields including id also
c.Clocne has all the fields excepts id