-
ChatterFeed
-
0Best Answers
-
1Likes Received
-
0Likes Given
-
8Questions
-
5Replies
Need help with test code
First off, I confess to being a complete newbie when it comes to Apex development. So I set up a code consult at Dreamforce, and was thrilled to get the help of two wonderful guys, who were able to show me how to write a really simple, basic trigger that we badly need. They also told me that before I could deploy it, I had to have a test class first. I already had a test class in my Sandbox (and in production, for that matter) written by Astadia for a previous project. It appeared to work fine as a test, so they told me all I needed to do was go home and deploy both the new trigger and the test class. Unfortunately, when I tried to do that, the deployment failed - with four errors. Two were new validation rules that weren't in place the last time my Sandbox had been refreshed (and that only applied to the functions called by the test class, not those in my new trigger), and two others were errors I don't understand, but seem to be telling me that my test code isn't sufficient. Namely:
*OpportunityAfterUpdate - Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
*Deploy Error - Average test coverage across all Apex Classes and Triggers is 20% at least 75% test coverage is required
BTW - I'm trying to deploy the code from the Sandbox using the new Deploy Change Sets function. Maybe the problem is that I have to use a different tool? Honestly, I'm kind of clueless.
So it looks like I need new test code, but I'm at a total loss for where to even start. My trigger is really pretty small and only calls a few functions, so it seems like my test code should only need to be simple too, but like I said - I'm at a total loss for where to even start. I'm hoping one of you can help me out!
My trigger simply creates a new record in a related list whenever a new Opportunity is created with a certain record type. We have 3 record types, and the only one that this should *not* fire for is called "ADM Opportunity", so we used that as a "not equals" instead of specifying two types for "equals". The related object is called shared_sale__c, and only 3 fields need to be filled in with the new record. The opportunity_ss__c field (which is the master-detail relationship), the rep__c field (lookup to user table, populated with the owner of the opportunity) and the percent_share__c field (set to 100). I've copied the full trigger below, if that helps.
What all should I put in the test code? The one created by Astadia actually creates a new account, then a new related opportunity, and then populates a bunch of fields. And apparently that's not sufficient to test my new trigger.
Any help, advice, tips - anything at all - would be welcome!
trigger OpportunitySplitTrigger on Opportunity (after insert) {
list <recordtype> soqlret = [select id from recordtype where name = 'ADM Opportunity'];
id nosplitid = null;
if (soqlret.size()>0){
nosplitid = soqlret[0].id;
}
list<shared_sale__C> listOpportunitysplits = new list<shared_sale__C>();
for (Opportunity o :trigger.new){
if (o.recordtypeid != nosplitid){
shared_sale__C ss = new shared_sale__C();
ss.percent_share__c =100;
ss.rep__c = o.ownerid;
ss.opportunity_ss__c = o.id;
listOpportunitysplits.add(ss);
}
}
insert listOpportunitysplits;
}
-
- Datajunkie
- January 19, 2011
- Like
- 0
- Continue reading or reply
Office Toolkit 4.0 and Excel Connector?
I have a user who just installed the Office Connector from inside SF (in the Desktop Integration section of Personal Setup), and it appears to have installed a version 4.0 of the toolkit.
He's getting the "Can't find project or library" error that others have reported getting as a result of a mismatch between Version 2.0 of the toolkit and Version 6.16 of the Excel Connector.
Has there been an updated version of the Excel Connector that will work with Version 4.0 of the toolkit? If not, how do I downgrade him back to Version 3.0, since the only version that will download from SF setup is version 4.0?
This is not the most technical of users, and I'm supporting him from 200 miles away, so I can't just go to his computer and do it for him. So asking him to go to the Developer Toolkit type sites and figure out what to do is asking for disaster. Please help!
-
- Datajunkie
- December 07, 2009
- Like
- 0
- Continue reading or reply
Need Help with YTD Quota Formula
I need a custom formula field in the User object to calculate YTD Quota per person. So far, every formula I try runs into the "No Formula >5,000 Characters" rule, or it's so simple that too much falls through the cracks. Can anyone think of a way to simplify?
The rules are deceptively simple...
1) Each rep can have a different annual quota, split into a monthly goal.
2) Each rep gets two months "free" after their hire date before quotas start accumulating. If hired after the 15th of the month, they get that month "free" too.
3) Our fiscal year goes from 2/1 to 1/31
4) I've been determining the current fiscal month being reported by extracting the month from today's date, and if it's January, setting the fiscal month # to 11 (December), or if it's February, setting the fiscal month # to 12, otherwise taking the month number - 2.
I've been approaching this by trying to capture the date the quota starts, then using that to determine where in the fiscal year this falls, and then determine how many months they get "free" that year versus the number of months elapsed so far this year. But like I said, that's running into the character limit. Ultimately, I've been trying to find a way to capture the # of months I should multiply by the monthly quota (bold, italic, underlined below). But if someone can think of another way to go about it, I'm all ears.
I'm probably missing something terribly obvious, so I'm hoping a fresh set of eyes will see something that I'm overlooking because I'm trying to be too complicated.
Example:
Rep A
Hire Date 4/1/06
Date Quota Starts 6/1/06 (far prior to current FY)
Annual Quota $500,000
Monthly Quota $41,666.67
Current Reporting Month: November 2009, which is fiscal month #10 of the current year
YTD Quota should be $416,667 or Monthly Quota *10 (same as fiscal month #)
Rep B
Hire Date 5/1/09
Date Quota Starts 7/1/09
Annual Quota $600,000
Monthly Quota $50,000
Current Reporting Month - November, fiscal month #10
YTD Quota should be $500,000 or Monthly Quota *5 (this is where I get complicated, trying to capture the month of the Date Quota Started and adjusting to the fiscal month by -2 if it's March-December, or forcing if it's Jan or Feb)
Rep C
Hire Date 11/28/09
Date Quota Starts 1/28/10
Annual Quota $480,000
Monthly Quota $40,000
Current Reporting Month - November, fiscal month #10
YTD Quota should be $0 or Monthly Quota * 0 , since the Date Quota Starts > the start of the current fiscal month (and this is where I've totally failed, since this goes into another year, and the month has to be forced because it's calendar month #1, but fiscal month #12)
Ideas? Suggestions? Anything? I'm desperate!
-
- Datajunkie
- December 01, 2009
- Like
- 0
- Continue reading or reply
Formula field that can lookup values from another table?
-
- Datajunkie
- December 03, 2008
- Like
- 0
- Continue reading or reply
Close date validation rules using Custom Fiscal Years
OR(
ISNEW(),
ISCHANGED( StageName ),
),
IsClosed = true,
TODAY()>DATE(2008,6,24),
CloseDate <DATE(2008,6,22)
)
Message Edited by Datajunkie on 06-27-2008 10:37 AM
-
- Datajunkie
- June 23, 2008
- Like
- 1
- Continue reading or reply
How to create a new record in a related list with code?
-
- Datajunkie
- June 13, 2008
- Like
- 0
- Continue reading or reply
Need formula that will multiply a field in a related list with a field in the parent
-
- Datajunkie
- April 23, 2008
- Like
- 0
- Continue reading or reply
Duplicating Owner Name (not ownerID) on a page
-
- Datajunkie
- February 20, 2008
- Like
- 0
- Continue reading or reply
Close date validation rules using Custom Fiscal Years
OR(
ISNEW(),
ISCHANGED( StageName ),
),
IsClosed = true,
TODAY()>DATE(2008,6,24),
CloseDate <DATE(2008,6,22)
)
Message Edited by Datajunkie on 06-27-2008 10:37 AM
-
- Datajunkie
- June 23, 2008
- Like
- 1
- Continue reading or reply
Need Help with YTD Quota Formula
I need a custom formula field in the User object to calculate YTD Quota per person. So far, every formula I try runs into the "No Formula >5,000 Characters" rule, or it's so simple that too much falls through the cracks. Can anyone think of a way to simplify?
The rules are deceptively simple...
1) Each rep can have a different annual quota, split into a monthly goal.
2) Each rep gets two months "free" after their hire date before quotas start accumulating. If hired after the 15th of the month, they get that month "free" too.
3) Our fiscal year goes from 2/1 to 1/31
4) I've been determining the current fiscal month being reported by extracting the month from today's date, and if it's January, setting the fiscal month # to 11 (December), or if it's February, setting the fiscal month # to 12, otherwise taking the month number - 2.
I've been approaching this by trying to capture the date the quota starts, then using that to determine where in the fiscal year this falls, and then determine how many months they get "free" that year versus the number of months elapsed so far this year. But like I said, that's running into the character limit. Ultimately, I've been trying to find a way to capture the # of months I should multiply by the monthly quota (bold, italic, underlined below). But if someone can think of another way to go about it, I'm all ears.
I'm probably missing something terribly obvious, so I'm hoping a fresh set of eyes will see something that I'm overlooking because I'm trying to be too complicated.
Example:
Rep A
Hire Date 4/1/06
Date Quota Starts 6/1/06 (far prior to current FY)
Annual Quota $500,000
Monthly Quota $41,666.67
Current Reporting Month: November 2009, which is fiscal month #10 of the current year
YTD Quota should be $416,667 or Monthly Quota *10 (same as fiscal month #)
Rep B
Hire Date 5/1/09
Date Quota Starts 7/1/09
Annual Quota $600,000
Monthly Quota $50,000
Current Reporting Month - November, fiscal month #10
YTD Quota should be $500,000 or Monthly Quota *5 (this is where I get complicated, trying to capture the month of the Date Quota Started and adjusting to the fiscal month by -2 if it's March-December, or forcing if it's Jan or Feb)
Rep C
Hire Date 11/28/09
Date Quota Starts 1/28/10
Annual Quota $480,000
Monthly Quota $40,000
Current Reporting Month - November, fiscal month #10
YTD Quota should be $0 or Monthly Quota * 0 , since the Date Quota Starts > the start of the current fiscal month (and this is where I've totally failed, since this goes into another year, and the month has to be forced because it's calendar month #1, but fiscal month #12)
Ideas? Suggestions? Anything? I'm desperate!
- Datajunkie
- December 01, 2009
- Like
- 0
- Continue reading or reply
Formula field that can lookup values from another table?
- Datajunkie
- December 03, 2008
- Like
- 0
- Continue reading or reply
VLOOKUP problems: field doesn't exist.
As a solution to a question I posted the other day (http://community.salesforce.com/sforce/board/message?board.id=general_development&thread.id=23809) someone suggested using a VLOOKUP (which is a brilliant idea :smileyhappy:)
Now I've been brave and set up a custom object with two fields in it:
Custom object = Membership_Category_for_Lookup (that's the object name)
Fields = Base_Fee and Membership_Category
So looking at the help section, I thought my VLOOKUP formula should be:
VLOOKUP($ObjectType.Membership_Category_for_Lookup.Fields.Base_Fee,
$ObjectType.Membership_Category_for_Lookup.Fields.Name,
Membership_Category__c )
But I'm getting an error that says the field $ObjectType.Membership_Category_for_Lookup.Fields.Base_Fee doesn't exist.
I'm a bit stumped. I've tried several things like using the API name and so on, but no luck.
Anyone got any suggestions?
Thanks
Nicole
- LGSOChair
- December 03, 2008
- Like
- 0
- Continue reading or reply
Need formula that will multiply a field in a related list with a field in the parent
- Datajunkie
- April 23, 2008
- Like
- 0
- Continue reading or reply
Duplicating Owner Name (not ownerID) on a page
- Datajunkie
- February 20, 2008
- Like
- 0
- Continue reading or reply