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
AlecSAlecS 

Copy RecordType from Standard Object to A Custom Object

Whenever, I activate a Contract, a trigger is executed and creates a custom object called Invoice__c. I am able to copy all the values from Contract to Invoice__c EXCEPT for the RecordType. 

 

RecordType is a standard field present in ALL objects. How can I copy the RecordType of Contract to the RecordType of Invoice__c? I just need this code.

 

Thanks.

Mayank_JoshiMayank_Joshi
Schema.DescribeSObjectResult oSObjectResult = Event.SObjectType.getDescribe();
ListRecordTypeInfo> oRecTypeInfos = oSObjectResult.getRecordTypeInfos();

OR

SELECT Id, Name FROM RecordType;
sf_evolutionsf_evolution

HI Alec,

I

don't think you can, because part of the information of a recordtype is the SObject type - as this FDC Explorer pic shows....

 

I think you have to duplicate the record-type for your custom object, and then look it up by Description (or whatever other criteria), and then use that ID when running your trigger.

 

...But, if all you want to do is copy the record type from some other object (like an account, for ex.) you can create a lookup field on your custom object and insert the account record type there, so that you can create reports and such.

 

pic