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
ponneri navadeepponneri navadeep 

i want code for change record type for existing record(see the below requirement)

  1. The line of code:

The users are making the wrong selection and then proceeding to fill out the form and save the question and then they realize
they’re in the wrong section.  There’s no way for them to change the record type once selected.
 
I’ve setup the skeleton of a Custom Button and a Visualforce page that you will program to provide the user the opportunity
to change the record type.
 
Your first objective will be to add a drop down list to the visualforce page and load it with the possible records  type
for the Core_Ask_A_Question__c object.
 
You can read the record types using the Schema IPA, and from that you’ll get a list of record types.  Load the available record types
into the drop down list.  There’s more – and I’ll provide the rest shortly.
 
I set up a skeleton consisting of the following artifacts:
 
 
 
  objAAQ = (Core_Ask_A_Question__c) controller.getRecord();
 
This get’s the AAQ record that the user is currently looking at when they pressed the “Change Record Type” button.
Get the record type from objAAQ and only show, in the drop down list, those record types that aren’t the same
as the record type of the current record.  Right now there’s only one other choice, but in the future, there will be more.
You can even auto-populate the new record type field if there’s only one selection available.
 
  1. Add a “Save” button.
 
  1. When the user presses “Save”, use the Schema API to get the fields for the AAQ record and select the fields that have picklists.
 
Requirement:  Make sure that the picklist selections in the picklist fields are still available in the new record type.
 
You’ll have to use the Schema API to get the picklist values for the new record type, and then compare them
with the values entered on the AAQ record to make sure that they are still valid.  If the value is longer supported
by the new record type, blank it out on the objAAQ variable.