You need to sign in to do that
Don't have an account?
Sravan R Pinninti
Copy Field values from One Record to another using FieldSets!
Hi,
I have a cutom object named Custom__c. THis object consists almost 400 fields. This application is fully built on VF pages. During a record conversion process, based on certain conditions I want to create a Custom__c object record and this record should have field values copied from the existing Custom__c object record and this record should have a different record type values.
Our Administrator should have the flexibility to be able to add and remove the fields the needs to be copied over. Hence, I am planning to use fieldsets instead of querying the existing fields. Can someone suggest a sample code that can fulfill this requirement.
Thank You In advance for the help!!
I have a cutom object named Custom__c. THis object consists almost 400 fields. This application is fully built on VF pages. During a record conversion process, based on certain conditions I want to create a Custom__c object record and this record should have field values copied from the existing Custom__c object record and this record should have a different record type values.
Our Administrator should have the flexibility to be able to add and remove the fields the needs to be copied over. Hence, I am planning to use fieldsets instead of querying the existing fields. Can someone suggest a sample code that can fulfill this requirement.
Thank You In advance for the help!!
public with sharing class ContactFieldSets {
public Contact cont;
public ContactFieldSets (Apexpages.Standardcontroller stdcont)
{
string query = 'select ';
string oldid =Apexpages.currentPage().getParameters().get('exitingid');
cont = (Contact)stdcont.getRecord();
for(Schema.FieldSetMember fld : this.getFields())
{
query += fld.getFieldPath()+', ';
}
query += 'Id from Contact where Id =:oldid';
Contact oldcon = Database.query(query);
cont.FirstName = oldcon.FirstName;
System.debug(oldcon.FirstName);
}
public List<Schema.FieldSetMember> getFields()
{
return Schema.Sobjecttype.Contact.FieldSets.Contact_Demo.getFields();
}
}