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
ANKITAANKITA 

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

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

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

Shashikant SharmaShashikant Sharma

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.

 

 

This was selected as the best answer
ANKITAANKITA

Yes. Its working.

You are too gr8 yar.

 

Thanku so much

ANKITA

ANKITAANKITA

hi what is the difference between c.clone(false) and c.clone(true).

 

Regards:

ANKITA

Shashikant SharmaShashikant Sharma

c.Clone(true) has the all the fields including id also

c.Clocne has all the fields excepts id