You need to sign in to do that
Don't have an account?

Apex Code Help - Developer Needed
Hello all! We need to create a reportable field that will count the number of days between opportunities in a single account. This field will need to be placed at the opportunity level and once the number is calculated, it cannot change. We are looking for some help from a developer to help create the code, as we no longer have developer support on payroll (and my knowledge of Apex is only in reading, not practice). Suggestions??
Here is an example of what we need:
Account A has 3 Opportunities, A, B, & C.
Opp A was ordered on 6/24/2014
Opp B was ordered on 7/1/2014
Opp C was ordered on 7/5/2014
Opp B needs a field that will report the number of days between it and Opp A. Opp C needs a field that reports the number of days between it and Opp B. I then need to be able to run a report on said field in the future.
Thanks for your all of your time!!!
Here is an example of what we need:
Account A has 3 Opportunities, A, B, & C.
Opp A was ordered on 6/24/2014
Opp B was ordered on 7/1/2014
Opp C was ordered on 7/5/2014
Opp B needs a field that will report the number of days between it and Opp A. Opp C needs a field that reports the number of days between it and Opp B. I then need to be able to run a report on said field in the future.
Thanks for your all of your time!!!
1. On Account, create a rollup summary field with
- Label: Last Opportunity Date,Summarized object: opportunity,Summarize Type : MAX,Field to Aggregate: Created Date
2. Create an number field on Opportunity- Label: Days since Last Opportunity,Length: 5
3. Create a workflow rule on Opportunity- Evaluation Criteria: Created,Rule criteria : Account: Last Opportunity Date NOT EQUAL TO (leave the value blank - it will consider as null)
4. Create Field update workflow action- Field to update : Opportunity: Days Since Last Opportunity,Formula: NOW() - Account.Last_Opportunity_Date__c
5. Activate Workflow ruleReplace field names with the names you created. For existing opportunities, you can do a data load or write a batch job.
Hope it helps!
All Answers
- Create a lookup field on the Opportunity object that will lookup another Opportunity
- Create a formula field that calculates days between Opportunities via the lookup relationship.
- Formula would look something like this: CreatedDate - Link_Opportunity__r.CreatedDate
For example, a Opportunity lookup field called Linked Opportunity (Linked_Opportunity__c) is created.Opp B would have the Linked Opportunity Field populated with Opp A
Opp C would have the Linked Opportunity Field populated with Opp B.
There are a few manual steps for this to work, but it would be a start.
1. On Account, create a rollup summary field with
- Label: Last Opportunity Date,Summarized object: opportunity,Summarize Type : MAX,Field to Aggregate: Created Date
2. Create an number field on Opportunity- Label: Days since Last Opportunity,Length: 5
3. Create a workflow rule on Opportunity- Evaluation Criteria: Created,Rule criteria : Account: Last Opportunity Date NOT EQUAL TO (leave the value blank - it will consider as null)
4. Create Field update workflow action- Field to update : Opportunity: Days Since Last Opportunity,Formula: NOW() - Account.Last_Opportunity_Date__c
5. Activate Workflow ruleReplace field names with the names you created. For existing opportunities, you can do a data load or write a batch job.
Hope it helps!