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
fourfourfunfourfourfun 

Automated creation and saving of a record

Got a bizarre concept that I wondered if it can actually be done.

 

Usually in the case of a lookup, you would create a record, save it and have the "Add New X" button appear in a related list down the bottom.

 

Is it possible to do this BACKWARDS?

 

So I go to create an item and it (invisibly) creates the record it would be related to and relates it?

 

It sounds like a ham fisted way of doing things but it may solve a problem I am facing. If anyone wants a break down of the problem to see if I am doing things in a crazy fashion, let me know.

Best Answer chosen by Admin (Salesforce Developers) 
fourfourfunfourfourfun

Attempting to do this via the Roll Your Own Lookup code that is everywhere on the net. It will at least let the user link to the relevant timesheet using a date, plus let them create a timesheet if one does not exist.

All Answers

Vinit_KumarVinit_Kumar

Not sure what you are looking.Could you make it more clear ??

joshbirkjoshbirk

This can be done rather easily with a trigger, if I understand you correctly.  For instance, I have an app where whenever a parent object is created - a set of children are automatically created and associated with it.  Is that the kind of behavior you mean?

fourfourfunfourfourfun

Essentially I am creating an object for the sales team to log calls to. A call is determined as visiting a customer and speaking to them about certain services.

 

This is nice and simple. Object links to Account and Contact, create new available on those screens, click to create and call count is 1.

 

It then gets complex with a different type of call. They also do events, which might have multiple contacts present. An event counts as 1 call, but within the event (if they have in depth discussions) they can get credit for a call there too. So think of it it as having 7 attendees with 3 in depth discussions = 4 calls (3 individual + 1 for the event). Call count never exceeds the amount of attendees.

 

So above the object I have a grouping object for events, where you can add multiple calls via a related list.

 

My issue is that the call counting needs rollups to work. Rollups don't work on lookups (and I haven't managed to find code I can butcher to make it work on a lookup), and I want to retail that ability for the bog standard calls to be created without going in via the grouping object and then via the related list.

 

My hope was I have two buttons: create a call, create an event. Create an event takes you to the grouping object where you can add calls via related list. Create a call automatically creates the grouping object, saves it, and then takes you to the place where you can log the call details - essentially cutting out a piece of admin for the user, letting me use Master/Detail relationship for the rollup so I can report.

 

Does that make sense?

joshbirkjoshbirk

So the structure is:

 

  • Events Object
  • - Call Object (Master Detail)
  • -- Account / Contact Lookup

And you want information on things like Contact lookup to be visible up on the Events Object?  

fourfourfunfourfourfun

More like I want the activities to be visible on the Accounts/Contacts object.

 

The layout will be like this:

 

http://i1281.photobucket.com/albums/a517/fourfourfun/map_zps8f736546.png

(unsure of embedding on here)

 

The workflow is:

 

  1. Single face to face call - click new, fill in details (process takes one screen to complete)
  2. Multiple attendee - click new, goes to grouping object and calls added via related list (process takes two screens to complete)

 

The dilemma is I need to use some logic to roll up call counts for reporting (the criteria about types of discussion happening at large meetings counting to extra call credit). To do this I would need to create a Master/Detail from Grouping Object to Call, meaning that the user has to create one of those records every time they log a call.

 

My aim is to try and retain the simplicity of going to account/contact and logging a call quickly in one screen, bypassing that master grouping record. The relation would only be to one instance of Call, as there would only be one Account/Contact.

 

It isn't a show stopper, I can say "look, you have to do it via two screens as I am limited by system constraints", but it would be excellent if Salesforce could invisibly make a master grouping record, relate it to call and pop up at the Call screen rather than that master grouping screen.

 

Sorry if the explanation sounds bizarre. If I didn't have this crazy instance with the group meetings and call count logic, I'd be able to do it without rollups.

fourfourfunfourfourfun

Another option, but one I don't feel technically able to delve into, is to use Visualforce to tie the two objects together into one page. A bit like Gridbuddy.

 

I wouldn't have a clue though.

 

EDIT:

 

This looks promising:

 

http://www.salesforce.com/docs/developer/cookbook/Content/apex_parent_child.htm

 

Create a child record on creating a parent one. All I have to do is have something that navigates to the child record automatically and I am there.

joshbirkjoshbirk

OK, I think I get it a bit more now.  So your core data point is the call, but sometimes you need to group them and sometimes you don't.  Based on the grouping, there is complex logic that takes place to track information about the group of calls.

 

yeah, this does sound like a Master-Detail relationship to me, even if many of those masters only have on detail.  My litmus test for M-D is often "if I remove the parent, does the child have any reason to exist."  In this case no, even if the group is a group of one.

 

What I'd recommend is:

 

- A before insert trigger on Call that will create and associate a group object if none exists.

- If clone on the Call layout wouldn't suffice, a button on the layout that will automatically create a new call based on the current group relationship.  You can point to a new VF page with a controller that does what you need, and then redirect to the normal edit page.

- Use roll up fields on Group when you can

- Use triggers to calculate the rest (since it sounds like this is the realm of non-simplistic business rules that formulas/workflows would help

 

That way your user can focus on the Call data point, but the system will create, track and maintain the Group data.

 

joshbirkjoshbirk

Re: trigger snippet.  Yeah, something like that - but to warn, I don't know if that is using an M-D example.  I think the M-D version would need to be before, not after, since you can't save the record without a parent.

fourfourfunfourfourfun

"- A before insert trigger on Call that will create and associate a group object if none exists."

 

That sounds like where I am wanting to go.

 

So I create a call, and that creates a group by default where none exists. Is pretty much what I want to do.

 

When creating a call with multiple attendees, I go in via the group way so the issue scenario never arises.

 

Everything else I can handle via checkboxes, roll up and formulae.

 

It is that one step of clicking a "Create Call" button, and having the association to a Master record go unseen.

 

The next step is the how. That final link I made looks like it might do what I want, as long as on save it went to the child record.

fourfourfunfourfourfun

Just had a thought. I could shift a majority of my descriptive fields to the Master Record and have the child record as something that just records attendees.

 

I could have the single attendee meeting created, details are filled in such as a date, description, account and contact. On saving, the Master then creates a child and auto populates the child with the account and contact lookup, and then populates the description, date and a checkbox with a true.

 

Essentially I am mirroring what would be on the child record in hidden fields, and then using those to create the child on save.

 

Creating a multi attendee meeting would just be a simple matter after this.

 

I think.

 

Of course I say "I would just do", I still need to figure out the apex to do all this.

fourfourfunfourfourfun

Ok. Need to draw a line under this. Had a meeting which caused a shifting of requirements. Thanks for all the input so far!

 

 

fourfourfunfourfourfun

Right, I am returning with the FINAL desired solution - and will update the OP as appropriate.


THIS is going to be the object structure. It is easy to create.

 

http://img715.imageshack.us/img715/7389/solutionc.png

 

The top object is "In Field Time Recording" - this is an object that has a number of fields on it, grouped by day of the week, the operative is selecting items from picklists and saving. There is one of these records per week.

 

The object sitting under that is "Call" - this is an object which has a Record Type: Call or Meeting. In the type of Call, the operative is entering some details, linking to an account and contact and saving.

 

The object sitting under "Call" is "Attendees" - in the event of record type Meeting, the fields to attach to a single Account and Contact is replaced with a related list to add multiple contacts and accounts.

 

This is a simple object structure and I can make this without any issue. They are linked with Master/Detail relationships.

 

Where I want to take this into an advanced Apex direction is the method of creating the "Call" record. I want to be able to add the appropriate Call (with either Call or Meeting Record Type) from the Account and Contact screen.

 

The ONLY way I can see this happening is by the following routine:

 

  • User clicks Call or Meeting from related list section on Account/Contact.
  • On click, the user is prompted for a date via the calendar function.
  • Date is entered and *somehow* is used to determine whether the User has an In Field Time Recording entry for that particular.
  • On detection of a record being present: creates a Call in the relevant In Field Time Recording entry and displays ready to be used.
  • On not detecting a record: creates and saves an In Field Time Recording entry for that week, then creates a Call in it ready for the user to use.

and that is the crux of my issue. Making Salesforce search for something, and then be able to create seamlessly.

fourfourfunfourfourfun

Attempting to do this via the Roll Your Own Lookup code that is everywhere on the net. It will at least let the user link to the relevant timesheet using a date, plus let them create a timesheet if one does not exist.

This was selected as the best answer