74

If you want to develop an industrial-strength Force.com application, i.e. an AppExchange app, you CANNOT rely on either the Id or Name fields of RecordTypes as a means of getting at a desired RecordType for a given object. Why? Because the Id will be different in every customer's org, and the Name may be different in every customer's org AND for each Running ...


36

Clues came from here: http://sfdciq.com/unable-to-delete-record-type/ The solution is a URL hack. https://xxx.salesforce.com/setup/ui/profilerecordtypeedit.jsp?id={Profile ID}&tid={Custom Object ID}&pn={Profile Name} Eg, As a System Administrator, I go to Setup > Profiles > the profile I'm interested in. Lets say "Chatter External User" The url ...


25

Until now, we used zachelrath's solution, and it worked wonderfully. As of v43.0 (Summer '18), however, the proper way to do this is to simply use getRecordTypeInfosByDeveloperName. It eliminates a good chunk of code, eliminates a database hit (SOQL limit), and preserves the stability of using the RecordType's DeveloperName. Also, there are no longer ...


23

This is possible through Apex, but not SOQL --- and no Metadata API required. To determine whether a given SObject's RecordType is available to a given user's profile, you will need to use the Apex DescribeSObjectResult getRecordTypeInfos() call on that SObject (see the docs here). This returns a list of RecordTypeInfo objects corresponding to all ...


19

Schema.SObjectType.Object__c.RecordTypeInfosByName.get('MyType').RecordTypeId The cached Schema.SObjectType is often my most preferable approach because: no SOQL queries, no describe calls, no function invocations, BUT watch out if your customer will mess with the labels: override labels [...] apply to the Schema.RecordTypeInfo objects They are ...


17

If you are doing this in the trigger it would be something like this: trigger OnOpportunity on Opportunity(before update){ Map<ID,Schema.RecordTypeInfo> rt_Map = Opportunity.sObjectType.getDescribe().getRecordTypeInfosById(); for(Opportunity opp : trigger.new){ if(rt_map.get(opp.recordTypeID).getName().containsIgnoreCase('YOUR ...


16

Actually, that is not quite true. Name is the field that the user sees when they choose it in the screen (or on the Page Layout). Developer Name is the API name for the record. This is very similar to the way the Label and the API Name work for fields and object. Because of this, it is best practice to always use Developer Name, since it is less likely to ...


14

you cant edit the record type of the object in edit mode. If you go to the detail view of the page, you should see a field called record type with the link [change] next to it. If you dont see that, edit the layout to add the record type field to the layout in question:


14

It's RecordType.Name RecordTypes are held in separate reference table so to query the names just treat the RecordTypeId as any other lookup field :) In case you've never used the "dot notation" (the way SOQL handles relationships and things that would be JOINs in regular databases): http://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/...


13

You can use custom setting for this. Keep the record type Id in custom setting and use that in your button code, it will look something like this "{!$Setup.CustomSettingAPI_c.RecordTypeId_c}"


13

Not in one shot. The best I think you can do this via the Force.com Migration Tool and the metadata API. You would need to perform the following steps: Download all of the profiles. This is easy since the wildcard operator works with Profiles. Open each file (they're XML), find the entry, and update it. It will look like this: <recordTypeVisibilities>...


12

You can make use the User Interface API to get picklist values based on record type, https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_picklist_values.htm However, you need to make a REST API call and set Remote Site Settings. Here is the sample code for that, Http http = new Http(); HttpRequest request = new HttpRequest()...


11

getRecordTypeInfosByName() looks for Label. After summer '18 preview, Salesforce is going to support getRecordTypeInfosByDeveloperName() delivered: https://developer.salesforce.com/docs/atlas.en-us.214.0.apexcode.meta/apexcode/apex_methods_system_sobject_describe.htm Example: (Change your record type developer name in below example) system.debug(Case....


11

By querying the recordType object and filtering by the sObjectType select Id,Name from RecordType where sObjectType='Account'


11

Summer'18 update provided a new interface 'lightning:hasPageReference'. You can now access the recordTypeId in your controller as below: var recordTypeId = component.get("v.pageReference").state.recordTypeId; https://developer.salesforce.com/docs/component-library/bundle/lightning:hasPageReference/documentation


10

You can use apex describe to get the record type details of any object. This information will be correct for the running user. Schema.DescribeSObjectResult dsr = Account.SObjectType.getDescribe(); Schema.RecordTypeInfo defaultRecordType; for(Schema.RecordTypeInfo rti : dsr.getRecordTypeInfos()) { if(rti.isDefaultRecordTypeMapping()) { ...


10

Got it.... if (ApexPages.currentPage().getParameters().get('RecordType') == null) { Schema.DescribeSObjectResult describeOpp = Schema.SObjectType.Opportunity; List<Schema.RecordTypeInfo> rtInfos = describeOpp.getRecordTypeInfos(); for(Schema.RecordTypeInfo rtInfo : rtInfos) { if(rtInfo.isDefaultRecordTypeMapping()) { ...


10

While this can be accomplished with SOQL, SOQL queries are a precious resource and we have but a scant few in each transaction. There is a way to get this information without using a single query by using SObjectDescribe. // The general expression to use is // Schema.SObjectType.<your SObject's API name here>.getRecordTypeInfosByName() // I'll be ...


9

The closest I can get is the default record type for the current user: //find all Opportunity record types List<Schema.RecordTypeInfo> infos = Schema.SObjectType.Opportunity.RecordTypeInfos; Id defaultRecordTypeId; //check each one for (Schema.RecordTypeInfo info : infos) { if (info.DefaultRecordTypeMapping) { defaultRecordTypeId = info....


9

You can use the RecordTypeInfo class to get a list of record types without using a query, and select one based on the name of the record type.


9

You need to set the Id not the name. First fetch the Id Id stExam = Schema.SObjectType.Student_Records__c.getRecordTypeInfosByName().get('Student Exam Records').getRecordTypeId(); and then assign it endterm.RecordtypeId= stExam;


8

I have found the solution by using fullName Admin which is got by querying Profile Object using listMetadata() method of MetadataConnection. The list of fullName of Standard Profiles then returned are as follows: SolutionManager Customer Portal Manager Standard StandardAul Standard Chatter Free User Chatter External User ContractManager Customer Portal ...


8

To accomplish a number of date-dependent pieces of work we run a Scheduled Job - a class that implements Schedulable - every night. That job can then kick-off a chain of classes that implement Database.Batchable. These avoid governor limit issues by breaking their work up into multiple batches passed to the execute method, each with its own governor limits. ...


8

Documentation about RecordTypeId field on CampaignMember says: ID of the record type assigned to this object. To change the record type, modify the CampaignMemberRecordTypeId field on the associated Campaign. so you can't assign record type to CampaignMember record in this way. Select related Campaign and change CampaignMemberRecordTypeId field


8

Please recompile all classes in org by using compile all classes link on apex classes page under setup or you can do runAllTest in org which will recompile the covered classes. This will fix the issue. We faced a similar issue after Summer 19 release and got it fixed by recompiling all the classes.


8

I finally found the answer to this after hours of searching. This happens when you have setup a community audience that references the record type you are attempting to deactivate. It seems as though the platform isn't able to route you to the audience as the reference that is invalid, and I couldn't find any documentation on the FieldBasedPAC object, which ...


7

If the "need" (trigger, VF page controller) is relatively simple - I tend to use describes. They're underestimated a bit I think and it's far less likely to hit describes limit vs queries limit. If the scenario is complex, multiple objects inserted at the same time - I'd go for SOQL. Because in worst case scenario you waste only 1 query to fetch them all ...


7

Time based workflow is perfect for this. The workflow turns off automatically when the criteria changes. Scheduled Apex will also work, but isn't needed. Batch Apex would ensure you can scale to large data volumes. From Help & Training Time-dependent actions remain in the workflow queue only as long as the workflow rule criteria are still valid. ...


7

If you have a deep stack of dependent triggers (and some Orgs do) you can save yourself a SOQL by adding a formula field to the opportunity object, with a return type of Text, and a value of RecordType.Name If for example the formula field is called RecordTypeName you can access it directly in the trigger without querying again. for(Opportunity opp : ...


7

Record types are not separate object. Adding extra column in your CSV file with RecordTypeID should work. So while inserting from Test.Load(), record will be created based on record types. Alternately if there is change in recordtypeid use below syntax to get RecordtypeId and logic. Example code: Id RecordTypeIdValue = Schema.SObjectType.Account....


Only top voted, non community-wiki answers of a minimum length are eligible