+ Start a Discussion

Copy field Values

dear experts ,


i have  a custom object called prospects with two record types ( suspect and prospect) . if some one created a suspect they have an option to convert suspect to prospect . so that way two records will be created.  on each suspect lay out we have button called "convert" it iwll create new record when they click  the button. but i want to copy some of the fields  to when the push the button. i am not sure how to do this. any help will be appriciated. i would like to copy fields like for ex ( Type__C, notes__C,picklist__c) to prospect record .


here is my code for the suspect  to convert.

<apex:page standardController="Prospect__c" extensions="SusConvertToPros" action="{!convert}" showHeader="true" sidebar="true">
	<apex:pageMessages />


public with sharing class SusConvertToPros
    private ApexPages.StandardController standardController = null;

    public SusConvertToPros
        ApexPages.StandardController controller)
        standardController = controller;

    public PageReference convert()
        List<Prospect__c> prospects = new List<Prospect__c>();
        PageReference prospectPage = null;

            prospects = SuspectsService.convertToProspects(
                    new Set<ID> { standardController.getId() });

            String partialURL = '/' + prospects[0].Id;

            prospectPage = new PageReference(partialURL);
        catch (Exception e)

        return ApexPages.hasMessages() ? null : prospectPage;

 any help would be appriciated.


why not  (if you are determined to use static methods)?


public class SuspectService {
  public static List<Prospect__c> convertToProspects(Set<ID> suspectIdSet) {
    for (Prospect__c susp:  [select id, type__c, notes__c, picklist__c from Prospect__c where id IN :suspectIdSet) {
      Prospect__c p = susp.clone(false,true); // create deep clone without id; if you only want certain fields, dont use clone
p.recordTypeId = /* the prospect RecordtypeId that you should fetch only once outside of this loop */ pInsList.add(p); } insert pInsList; return pInsList; } }