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
Carlama8Carlama8 

Newbie to APEX... Need to pull formula from X-Objects

I tweeted about this and someone recommended I wrote a post here. I have never wrote APEX code and I am definitely not a developer but I can certainly learn.

 

I am building dashboards for my regional managers and one of the things that I need to report on is "Days since last registration" per account. This needs to appear by Account but the Registration Date information lives in the Assets side. In excel it would be something as simple as "RegistrationDate:MAX-Today". I wanted this as a formula field on the Account Layout, but obviously it won't let me. So in twitter they mentioned I could do that with APEX... Any thoughts?

 

Also if the result is greater than X can it trigger an e-mail?

 

Thanks much!

 

P.S. any APEX pdfs are very much appreciated

bob_buzzardbob_buzzard

Given that account is a lookup from asset rather than a master/detail, I think a trigger is the way to go.

 

There's probably a few ways to do this - here's how I'd approach it:

 

(1) A custom field on account of last registration date

(2) A before insert/update/undelete trigger an Asset that compares the registration date for the Asset with the last registration date of the account and overwrites the value on the account if necessary

(3) An after delete trigger that checks if the registration date of the asset equals the last registration date on the account and if it does, carries out a SOQL query to determine the new latest registration date

(4) A formula field on account specified as TODAY() - last registration date

 

The Apex Developer's Guide is available at:

 

http://wiki.developerforce.com/index.php/Documentation#Apex_and_Visualforce

 

and there are a number of blog posts etc regarding triggers - here's one at random:

 

http://www.crmverse.com/write-your-first-salesforce-com-apex-trigger-overview/