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
karthik Jonnalagaddakarthik Jonnalagadda 

Record type data type

Hi all,

I need to insert a values into record type field from Apex code. I saw the data type  as (Record Type). How should i insert Into Record Type filed.
PratikPratik (Salesforce Developers) 
Hi Karthick,

Please elaborate on your requirement. If you want to populate the Recordtype on record creation then you can enable that recordtype for that user profile so user can select the proper recordtype as it will be asked before cretaing new record.

If you want to update it, you can go for before update trigger.

Thanks,
Pratik
karthik Jonnalagaddakarthik Jonnalagadda
Hi Pratik,

My Requirement is I want move a record from one custom object another custom  object on button click from First object.
In second object Record type is required filed I need to pass value to record type to insert the value into second object, Now I am passing values manually as string to record type But it is not accepting (Error: Compile Error: Illegal assignment from String to RecordType at line 6 column 13).
What is the solution for this.
 
String RecordType='506(c)';   
            date EngDate = date.parse(EngagementDate);      
       Decimal myDecimal = decimal.valueOf((EstimatedTransactionValue.replace('$','')).replace(',',''));
       Decimal myDecimal1 = decimal.valueOf((TargetEnterpriseValue.replace('$','')).replace(',',''));       
           Ibanking_Project__c Project= new Ibanking_Project__c();
            Project.Name=OpportunityName;
          //  Project.Idea_Pitch__c=Company;
            Project.Company__c=Company;
            Project.Assignment__c=Assignment;
            Project.Engagement_Date__c=EngDate;
            Project.Referring_Party__c=ReferringParty;
            Project.Lead_Source__c=ReferringParty;
            Project.Type_of_Engagement__c=TypeOfEngagement;
            Project.Transaction_Value__c=myDecimal;
            Project.Fee_Structure__c=ProposedFeeStructure;
            Project.Engagement_Description__c=ProposedEngagementOverview;
            Project.Exclusivity__c=Exclusivity;
            Project.Enterprise_Value__c=myDecimal1; 
            Project.RecordType=RecordType;
                
             insert Project;

Working on above code.


Thanks.

 
SIVASASNKARSIVASASNKAR
Hi Karthik,

Recordtype field will accepts the ID of the record type, hence you would required to query the record type ID as below

ID rtId = [SELECT Id FROM RecordType WHERE sObjectType='Account' AND Name='RT1'].Id;
here sObjectType = Object Name and Name = Record type Name


and then assign the rtId to "Project.RecordType".

Project.RecordType=rtId ;

Thanks,
Sivasankar
karthik Jonnalagaddakarthik Jonnalagadda
Hi Sivasasnkar,

Thanks for the replay 
I am getting the error (Compile Error: Illegal assignment from Id to RecordType at line 25 column 12).
 
JayantJayant
Only change that you need to do is - 

project.RecordTypeId = rtId;

Please mark the question as resolved if it solves your problem.
SIVASASNKARSIVASASNKAR
Hi Karthik,

Try to convert it as String and assign it. 
Project.RecordTypeId = String.valueOf(rlId);

Or

Project.RecordTypeId = (String) rlId;

Hope this will help you, let me know in case any concerns.

Thanks,
Sivasankar.