How to get Record Type Dynamically

How to get Record Type Dynamically

This is one of the common scenarios Salesforce admins wonder "How to get Record Type Dynamically over hard coding Id of the Record type". Well Hardcoding the Id is indeed very simple and it has its own pros and cons.

  • It is not exactly an advantage of hardcoding but you can do it when you want to do a quick demo.
  • The Major con of copying and paste of Id is when you migrate the flow to staging or production environments the record type id will vary, in that case the hardcoded value from sandbox will be different from destination environment which will lead to failure of the flow.

Is there a way to Dynamically get the Record type?

The Answer is Yes!.

In my use case i am getting a record type called "Invoice" from contact.

Here at the Step 1, I am Getting Contact to initiate the flow

No alt text provided for this image

Then i am creating a new variable for storing contact Record type's API name which is "Invoice"

No alt text provided for this image

And then i am doing another Get for Record type object and i am using the previously created variable.

No alt text provided for this image

On record creation i am using RecordTypeId to make the field

No alt text provided for this image


OnDebugging Mode

No alt text provided for this image

So you would ask can i use this method only for RecordTypes?

My Answer is No! you can apply the same solution to get queues etc...

For Getting a Queue, just replace RecordType object in get with Group object.

SATHEESH KUMAR

7X Salesforce Certified | Salesforce Developer at Infosys| Namakkal Salesforce Developer Group Leader | #SFDG_NAMAKKAL

1 年

Hi Deepak, I have one additional requirement record type also needs to select by Sales-user, so we need to show the record type for the user, and they will select the record type. I can able to get all record types, but some record types don't have access for sales users,I need to show records based on user permission, how can we do this? please share your thoughts...

回复
Joseph Nagy

8x Salesforce Certified Expert

2 年

I love this, so many times this was me --> ??♂? when I saw 'CustomerRTID', 'VendorRTId' and so on as separate variables in a flow. Definitely a must use solution if you're using any version control and CI/CD too because without this best practice you're constantly updating IDs after deployments. You should do a post exploring Custom Metadata types and flow. I believe the availability of metadata types in flows is so underutilized and can solve a lot of redundant flow creation as well.

要查看或添加评论,请登录

Deepak Raj的更多文章

  • MIXED_DML_OPERATION

    MIXED_DML_OPERATION

    Ever getting this error "MIXED_DML_OPERATION: DML operation on setup object is not permitted after you have updated a…

  • Email Action

    Email Action

    Create a Link to the Record Are you having any trouble directing a user to a record from the email sent by a flow, here…

    2 条评论
  • 2 ways of sending email from Salesforce

    2 ways of sending email from Salesforce

    Email functionality is one of the main and essential features in Salesforce, it helps the customer to be updated on…

    1 条评论
  • Flow

    Flow

    Understanding Flow elements can be very tricky, I feel that pain because I have been through that. I also purchased a…

    8 条评论

社区洞察

其他会员也浏览了