dynamic call log popup

  • 1
  • Question
  • Updated 4 years ago
  • (Edited)
Ok. My dynamic click to call with call log popup is working great. Just a few refinements and it's good to go. One of those things will be to add the necessary code to grab the id of the field even if the field is not in the model.

Now to keep things easy to manage on the call log interface, I'm going to keep the page include page. Otherwise I'd put it into the popup XML string. That said, I'd like to be able to dynamically create the necessary models to support wherever the user clicked from on the phone number.
  • OwnerId is no problem
  • Whatid is no problem
  • AccountId could be tricky as can be applicable when whatid is Accout, Opportunity, Contract, any child of the Account, or if whatid any other object but whoid is contact, then the contacts accountid is used
  • Whoid is a lead or contact. If a lead then whatid is null
So, assuming I can gather the appropriate Ids from the click to call side, is it possible to dynamically create the necessary model for the whatid from javascript with nothing more than a id to start with? Would it be necessary to pass in the object api name in too?

Please don't provide any code. If anything just reference the Skuid API. I'd like to do this one where I type it out on my own.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,704 Points 20k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Pat -

I haven't followed the entire chain of events on what you are trying to accomplish.  That said, when you say create dynamic models, are you referring to actually creating a model on the fly via the skuid API?  While this is of course possible, I'm thinking there might be an easier way.  Again, not really sure what you are doing on the popup.  Is it just a log of activities or tasks?  What is involved that requires the models themselves to be generated on the fly?

There is a skuid API (setCondition) that would allow you to build a Task Model on the popup page and then set the condition (e.g. ParentId/Id/etc.) programmatically.  This way you need a small amount of code and can still build your models & page declaratively.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,704 Points 20k badge 2x thumb
I'd agree with you it wasn't too many models to work with. The task object can relate to dozens and sometimes even over 100 models. Every time someone creates an object, the option is provided to include activities. Choosing to creates another reference in the task object assigned through the whatid. Thus activities can be created from practically any object in the system. Then what if someone were to create a new object. The page would be broken if it were attempted to use this page include.

Though not many objects will contain phone numbers, I'd still like to get this done in a way that isn't easily broken. If possible never broken.
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Gotcha on the Tasks being related to one of many different types of objects.  

Can you explain what your popup page will do - features, etc.?  Will it just be focused on tasks themselves (new/update/etc.) or will it offer other capabilities?  Understanding the full picture in more detail should help me get my head around this and potentially offer up some ideas.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,704 Points 20k badge 2x thumb
Well. For the time being, only call log. In the future, I'd like to expand on the objects other functionality in the future. So, I imagine to start we'll use URL parameters to set everything in motion in the page. ie. rendering of call log, new task, etc.

The key though will be to be able to handle every possible whatid via javascript.

What would kinda slick/overkill would be to have a management page for this. There are all sorts of objects that the whatid can point to. This presents an issue in that not all objects use the Name field as the primary identifier. Sometimes the whatid can even point to a junction table where there isn't any identifying fields on the object. So, setup what displays in the page based on the setup page.
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Ok, I think I'm starting to see what you are trying to do.  Let me summarize to make sure I've got it correct.

1) You want to display the call log which comes directly from the Tasks object.  This can be accomplished by providing an 'Id' parameter in the Url.  The popup page can have a Task Model conditioned on the Id in the url parameter using ParentId of the task.  This alone wouldn't require any dynamic models.

2) You want to be able to display some information about the Parent itself (e.g. name).  This is where it gets a little tricky because you don't know what the parent object is within the popup itself and the "Name" might not be the actual "Name" property of the parent object.

Accurate?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,704 Points 20k badge 2x thumb
That is correct. Question is, can an Id alone be used as a starting point in Javascript to dynamically build a model. I'd prefer to not have to pass anything but the Ids and the Type. I'd like the page include page to do the rest.
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
In order to create the model in javascript the minimum requirement is the object type (Account, Contact, etc.) and which fields you want included.  

If you only wanted to pass the Id, you could use SDescribe API calls to get the list of all available objects, iterate the result, get the key prefix for each and then compare that against the Id you have to determine which SObject the Id belongs to.  I don't think this is what you are asking nor would it be very efficient but technically it would be possible hence why I'm mentioning it.

If you pass the Id and the name of the object to the popup, you can create the model within the popup using the techniques at http://help.skuidify.com/m/11720/l/228794-dynamic-creation-of-models-and-components-with-javascript.

This will only get you so far though since you might display the "Name" field of the parent on the page title, but in other cases you might want to display a different field.

If you had a finite number of possible parent objects (let's say a handful) there are some options here but since your parent could be hundreds of potential objects you need something more flexible.

Possibly I'm still mis-understanding the objective or maybe over (or under) thinking it, but here's my thoughts:

1) Create a custom object in salesforce that contains fields for the type of information you will want to display on the logs page
2) Create a popup that has two models - One for tasks (TaskModel) and one for the new custom object (ParentModel)
3) Pass the Id and object name to the popup
4) Set the condition on TaskModel to be the Id in Url parameter for ParentId of task
5) Dynamically create a row in the ParentModel using the following approach
 - Create a model based on the parent object name from the url
- Set the condition on the model to the Id from the url
- load the data for the model
- take the resulting row and create a row for ParentModel based on fields that you know for that object correspond to the ParentModel fields that you are going to display

What this would let you do is standardize fields and still use declarative approach for building the popup page itself.  For example, let's say that if the parent is Account, you want the Page title to use Account.Name but if the parent is Opportunity, you want the page title to display Opportunity.Description.  ParentModel.Name would contain the appropriate "Name" field from the target object because you handled the translation in code.

Hopefully this helps??
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,704 Points 20k badge 2x thumb
Ok. Well, I suppose I could manage to update the custom field renderer to grab the name of the object and throw it into the page include query string. That would everything that is required to dynamically create the necessary whatid model. The call log page will start as only a call log page. It will be modified to also be anything the task object currently handles.

So, the models in the page will be as follows.
  • AccountID (Account object created dynamically using javascript ... I actually think that this field is read only as salesforce manages this field)
  • OwnerID (User object w/ ownerid URL param)
  • Leadwhoid (Lead object w/ lwhoid URL param)
  • Contactwhoid (Contact object w/ cwhoid URL param)
  • WhatId (dynamically created using javascript based on whatid and whatidobject URL params)
  • NewCall (Task object)
  • NewTask (Task object - future dev)
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
If the models on your popup page will always be fixed like you describe here, then it becomes a little simpler since you won't need the custom object to standardize things.

That said, you still need to know what type of object was on the calling page so you can set your conditions properly for the models on the popup page.  Id alone won't let you know what type of model was on the calling page unless you use the SDescribe calls.  That said, you could probably use whatid/whoid/id parameter and then based on which one you get, you could know on the popup page what "style" of object the model was on the calling page.  

Given the nature of what you are trying to do, I think knowing specifically what model was on the calling page increases certainty that the poupup will handle things correctly and decreases risk that you'll spend hours trying to troubleshoot something that ended up being something as simple as passing in the wrong parameter name :)