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
djhollingworthdjhollingworth 

Simple Formula Question

Hi

I'm pretty new to SalesForce development so I've a fairly simple question about formula calculations.

Very simple set up - A Job object that stores:

Account
Job Description
Billing Rate

A Task object that stores
Task Description
Start Date
End Date
Charge Amount

The Job object is the master of the Task Object in a master-detail relationship. All very straightforward.

In my Charge field I want to calculate how much to charge for a task. Simple formula:

Charge = (End Date - Start Date) * Billing Rate

But how do I get access to the billing rate on the master record? I simply cannot find a way of doing this. If I were using any sort of programming language it would be a doddle so I must have missed something here.

I also thought of transfering the Billing Rate from the Job to the Task whenever I created a new Task. I would have the Billing Rate as a hidden field on the Task and default it to the Billing Rate from the master Job record. I don't seem to be able to do that either.

Thanks

David
RickyGRickyG
David -

You can't do this with a formula field at this time, but you can access fields in a parent object as part of a field update for a workflow.  So you could simply set up a workflow to update a read-only field, which would give you the same result. (A shout out to Raja, the man!)

I would advise this over any copying of data, which can set up all kinds of integrity problems.

Hope this helps.
djhollingworthdjhollingworth
Hi Rick

Thanks for your reply. That's a solution I hadn't thought of.

Hmmmmm...... Thinking about it that doesn't really give me what I want. I could 'post up' the time taken for each task to it's parent job record and keep a total time spent on the job and so I could calculate to total charge for a job. However what I wanted was to see the charge for each task based on the billing rate stored in the job record.

It seems the only way I can do this is to enter the billing rate against each task when the task is created. Not ideal as what I had hoped to implement eventually was:

An account has a default billing rate

When I create a job for an account it takes the account's default billing rate, unless I enter a new rate

When I create a task it takes the job's billing rate unless I enter a new rate.

There's really no way of doing this in SalesForce?

Thanks

David

RickyGRickyG
David -

I think you missed the point.

The field update specification for the workflow would make the "Charge" field on the task equal to this -

 ( End_date__c - Start_Date__c ) * Job__r.Billing_Rate__c

That is what I thought you wanted.

You can copy a default from the Job to the Task with an Apex trigger or an s-control. But what do you really want to do?  If the billing rate changes on the Job, do you want the charge on the task to reflect that billing rate, or the original billing rate?  Do you want to have the ability to specify a different billing rate for a task, or will it contractually always be the same.  These are important business issues to figure out, and they should point the way to the proper implementation.

Hope this helps.
djhollingworthdjhollingworth
Hi

You're right, I did miss the point and that's exactly what I want to do. I'll take another look at the Apex triggers.

Thanks for your assistance.

Regards

David