Skip to main content

Sneak Peek: Salesforce Polymorphic keys

What?
Polymorphic key is a relationship field which can relate to more than one type of object as parent. Unlike Lookup and Master-detail relationships which are related to a single object, Polymorphic keys can refer to multiple objects.

Where?
As of date, Polymorphic keys cannot be created by developers. They are available for specific objects out of the box for e.g. WHOID and WHATID in Task and Event objects.

Why?
Sneak Peak: Salesforce Polymorphic Keys
As we know, Salesforce’s data model is strictly relationship based, and the type of objects at both the ends of the relationship is fixed. So, if an object is to be related with multiple objects, then a separate relationship field has to be created for each relationship. Polymorphic keys are required to maintain relationship with multiple types, for e.g. task/ event might be related with various type of records viz. Account, Contact etc. So, a polymorphic key helps in establishing unique access to such disparate relationships.

How?
Polymorphic keys are hard to handle!! As they are polymorphic the queries/ data manipulation can be tricky, as the related object can be anything, and hence the operations might or might not succeed. For e.g. functionality to update a field on Account may not work with Contact.

In order to implement such functionality, the type of the object is to be determined and hence the operations are to be applied. Further, the objects would need to be retrieved separately.

With Summer ’13 release, Polymorphic keys have become more friendly. They can be used in SOQL queries to filter out specific types, based on type specific filter criteria. Following are few ways of handling polymorphic keys in SOQL:-

SOQL TYPEOF Clause
List = [SELECT TYPEOF What WHEN Account THEN Phone WHEN Opportunity THEN Amount END FROM Event];
This would conditionally return value of field "Phone" if event is related to Account and value of field "Amount" if event is related to Opportunity


Note: TYPEOF is currently available as a Developer Preview as part of the SOQL Polymorphism feature.

Filter results by Type
List = [SELECT Description FROM Event WHERE What.Type IN ('Account', 'Opportunity')];
This would return only those events which are related with an Account or Opportunity.


For more details refer http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_relationships.htm?SearchType=Stem&Highlight=whatId#soql_polymorph_keys

Comments

  1. Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
    mobile application development course | mobile app development training | mobile application development training online
    "web designing classes in chennai | Web Designing courses in Chennai "
    Web Designing Training and Placement | Best Institute for Web Designing
    Web Designing and Development Course | Web Designing Training in Chennai
    mobile application development course | mobile app development training

    ReplyDelete
  2. Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
    Web Designing and Development Course | Web Designing Training in Chennai

    ReplyDelete
  3. I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
    web designer courses in chennai | best institute for web designing Classes in Chennai
    web designing courses in chennai | web designing institute in chennai | web designing training institute in chennai
    web designing training in chennai | web design and development institute

    ReplyDelete
  4. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts.
    Cyber Security Projects for Final Year

    JavaScript Training in Chennai

    Project Centers in Chennai

    JavaScript Training in Chennai

    ReplyDelete

Post a Comment

Popular posts from this blog

Lightning: Generate PDF from Lightning components with in-memory data

I'm sure as everyone is diving into lightning components development, they are getting acquainted with the nuances of the Lightning components framework. As well as, its current limitations. Being a new framework, this is bound to happen. Although we have our users still using salesforce classic, we have started using lightning components framework our primary development platform and Visualforce is considered primarily for rendering lightning components within Classic Service console.
Recently, while re-architecting a critical module, we encountered a problem wherein we needed to generate PDF from lightning components. Now, being Javascript intensive framework, it has limited room for such features (may be included in future roadmap). As of now, there is no native feature within the lightning framework to do so (at least I didn't find anything).

Common Scenario - Create Visualforce page to retrieve data and generate PDF For scenarios where the data exist within Salesforce, it…

Quick Tips: Salesforce default Images

Well, I'm sure a lot of you still rely on using out of the box salesforce images for displaying quick icons within formula fields or even using them within your Visualforce pages. Lately, I realized that a lot of earlier resources are no longer accessible, so I tried to quickly extract all images from Salesforce CSS files and provide a quick reference here.

Please note, I've referenced all images from SF servers directly, so if anything changes, the image should stop rendering here. As these images are completely controlled by Salesforce, and in case they change anything, it might lead to image not being accessible.

Image pathImage/img/func_icons/arrowright10.gif/img/google/gmail_M_icon.gif/img/func_icons/ispan12.gif/img/func_icons/schedReport34.gif/img/func_icons/util/dialogClose16.gif/img/func_icons/util/rescale11.gif/img/overlaypointer.gif/img/msg_icons/confirm16.png/img/msg_icons/confirm24.png/img/msg_icons/confirm32.png/img/msg_icons/securityconfirm48.gif/img/msg_icons/er…

Lightning: Generate PDF within Lightning Experience with Salesforce Data

Some time back I posted a solution to generate PDF from Lightning components using in-memory data.
Post url:http://www.vermanshul.com/2017/07/lightning-generate-pdf-from-lightning.html

It was developed for a specific scenario, wherein we need to generate PDF where:
User interface is Salesforce classicInitiated via Lightning ComponentData doesn't exist within Salesforce and is completely in-memory As complex and tricky this situation was, we did end up finding a stable and equally tricky solution.

However, I realize that there are still lack of solutions (or maybe my search skills are downgrading) to generate and automatically download PDF document from Lightning Experience, without using any lightning components, wherein data exists within Salesforce. You can use the earlier solution in that case, but it will be an overkill.

There are various solutions available to generate PDF from javascript. But, I still think the plain old method of converting HTML to PDF (via visualforce PDF g…