• Florent
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies

Hello all,

 

Having received invaluable help on this forum to help me finish off my test units, I am now trying to deploy the trigger I've been working on for the opportunity object.

 

PROBLEM #1

Trouble is, in the organization I work for, a entity with multiple companies, there are already 2 existing opportunities' triggers, that were deployed before I took over the admin role (and people left the company…).

 

So, how do I go around this ?

 

- should my test class cover testing for other triggers as well ? But then, shouldn't other triggers' test classes cover my trigger's code as well? So in fact, would I have to deploy them again ?…

 

- should I include, in my trigger, the code from already existing triggers ? And then delete other triggers before deploying mine ?…

 

PROBLEM #2

Also, to make things even more fun, there is a test class for a trigger that is not working properly (anymore?)… I tried to validate my own trigger, to see what was happening, and it fails with the following error message :

 

API NameTypeLineColumnProblem

TESTprojectNUmberBUonOpportunity.myUnitTest()Class2021Failure Message: "System.LimitException: Too many SOQL queries: 101", Failure Stack Trace: "Trigger.ProjectNumberBUonOpportunity: line 202, column 1"

 

Of course, I can't edit this trigger in production…

Hi all,

 

I have a custom formula field in the Opportunity object, which takes value from a field in the Account objet. This value is then checked in a validation rule.

 

But in my unit test, this validation rule always replies FALSE because the formula field value is "null"…

 

How can I update this formula field within my test class so that the trigger I'm trying to test actually runs ?

 

See here for the complete version of my question (watch out, it's very long, and you're most likely to be scared away! ,-)

Hello all,

 

I'm striving to complete my very first deployment of a SF trigger but am stuck in the (very first!!) unit test.

 

Briefly said, I'm creating a fictive account in my test class, then an opportunity.

 

I'm "connecting" (sorry, bad english here) my opportunity to the account but when I test the class, and I insert the opp. in the database (which executes the trigger, right?) I have an error message I wrote myself, from a validation rule, saying that my account does not have an account_code (a required 2-letters code custom field), which is required to create the opportunity number (Opp. number consist of: account code + a 4-digit autonumbering).

 

I hope I'm being clear enough! here's a copy of some of the log's extracts:

 

Line 24 12:15:27.368 (1368862000)|USER_DEBUG|[19]|DEBUG|acc01 = Account:{Name=dsi, Account_type__c=CRO, MC_Account_code__c=AA, Id=001f0000002a3sbAAA}

Line 25 12:15:27.369 (1369440000)|USER_DEBUG|[41]|DEBUG|opp01= Opportunity:{Received_Date__c=2012-06-14 00:00:00, Name=sftest01, MC_Opportunity_filiations__c=PARENT, StageName=RFP Received, NextStep=no next step, Priority__c=Low, Group__c=XXX Consultancy, CloseDate=2012-08-13 00:00:00}

 

Interrestingly, opp01 has no value for the Account (opp01.Account), even though it is defined in my code before the system.debug calls.

 

I verify this explicitely, in the next line from the log

 

Line 26 12:15:27.369 (1369526000)|USER_DEBUG|[42]|DEBUG|opp01.Account.MC_Account_code__c = AA

 

So, it seems, opp01.Account is indeed linked to the account and I have access to its Account_code__c…

 

Just to be sure, I have just added a system.debug message which says:

 

14:16:58.199 (2199397000)|USER_DEBUG|[42]|DEBUG|opp01.Account = Account:{Name=dsi, Account_type__c=CRO, MC_Account_code__c=AA, Id=001f0000002a44XAAQ}

 

Before the execution of the trigger, there is a validation rule that tests the value of opp01.MC_Account_code to be different from null:

 

Line 762 12:15:27.434 (1434787000)|VALIDATION_RULE|03df0000000013E|MC_Check_Account_code
Line 763 12:15:27.435 (1435011000)|VALIDATION_FORMULA|IF( ISPICKVAL( Group__c, "XXX Consultancy"),
Line 764     IF( MC_Account_code__c  = "-1",
Line 765         TRUE,
Line 766         FALSE
Line 767     ),
Line 768     FALSE
Line 769)|Group__c=XXX Consultancy , MC_Account_code__c=-1
Line 770 12:15:27.435 (1435027000)|VALIDATION_FAIL
Line 771 12:15:27.435 (1435551000)|VALIDATION_RULE|03dD0000000MB3g|Project_Type_cannot_be_set_for_this_Opp

 

Trouble is, the field MC_Account_code for the opportunity object is a formula saying:

 

IF(ISBLANK(Account.MC_Account_code__c), "-1", Account.MC_Account_code__c)

 

So it would seem that Account.MC_Account_code__c is "blank" (null indeed). But at the beggining of the test, we didi see the value of Account.MC_Account_code__c for the account acc01, was… AA ! (see ligne 24).

 

So. I don't understand!

 

I have read on multiple occasions that one should update the formula using a SOQL select. Right, ok, fair enough, but how does one do this when this is the very first opportunity created in the (test) database?!

 

How do I update a non existent record so that the required formula field (for its creation) is !null ?!!

Hello all,

 

Having received invaluable help on this forum to help me finish off my test units, I am now trying to deploy the trigger I've been working on for the opportunity object.

 

PROBLEM #1

Trouble is, in the organization I work for, a entity with multiple companies, there are already 2 existing opportunities' triggers, that were deployed before I took over the admin role (and people left the company…).

 

So, how do I go around this ?

 

- should my test class cover testing for other triggers as well ? But then, shouldn't other triggers' test classes cover my trigger's code as well? So in fact, would I have to deploy them again ?…

 

- should I include, in my trigger, the code from already existing triggers ? And then delete other triggers before deploying mine ?…

 

PROBLEM #2

Also, to make things even more fun, there is a test class for a trigger that is not working properly (anymore?)… I tried to validate my own trigger, to see what was happening, and it fails with the following error message :

 

API NameTypeLineColumnProblem

TESTprojectNUmberBUonOpportunity.myUnitTest()Class2021Failure Message: "System.LimitException: Too many SOQL queries: 101", Failure Stack Trace: "Trigger.ProjectNumberBUonOpportunity: line 202, column 1"

 

Of course, I can't edit this trigger in production…

Hi all,

 

I have a custom formula field in the Opportunity object, which takes value from a field in the Account objet. This value is then checked in a validation rule.

 

But in my unit test, this validation rule always replies FALSE because the formula field value is "null"…

 

How can I update this formula field within my test class so that the trigger I'm trying to test actually runs ?

 

See here for the complete version of my question (watch out, it's very long, and you're most likely to be scared away! ,-)

Hello all,

 

I'm striving to complete my very first deployment of a SF trigger but am stuck in the (very first!!) unit test.

 

Briefly said, I'm creating a fictive account in my test class, then an opportunity.

 

I'm "connecting" (sorry, bad english here) my opportunity to the account but when I test the class, and I insert the opp. in the database (which executes the trigger, right?) I have an error message I wrote myself, from a validation rule, saying that my account does not have an account_code (a required 2-letters code custom field), which is required to create the opportunity number (Opp. number consist of: account code + a 4-digit autonumbering).

 

I hope I'm being clear enough! here's a copy of some of the log's extracts:

 

Line 24 12:15:27.368 (1368862000)|USER_DEBUG|[19]|DEBUG|acc01 = Account:{Name=dsi, Account_type__c=CRO, MC_Account_code__c=AA, Id=001f0000002a3sbAAA}

Line 25 12:15:27.369 (1369440000)|USER_DEBUG|[41]|DEBUG|opp01= Opportunity:{Received_Date__c=2012-06-14 00:00:00, Name=sftest01, MC_Opportunity_filiations__c=PARENT, StageName=RFP Received, NextStep=no next step, Priority__c=Low, Group__c=XXX Consultancy, CloseDate=2012-08-13 00:00:00}

 

Interrestingly, opp01 has no value for the Account (opp01.Account), even though it is defined in my code before the system.debug calls.

 

I verify this explicitely, in the next line from the log

 

Line 26 12:15:27.369 (1369526000)|USER_DEBUG|[42]|DEBUG|opp01.Account.MC_Account_code__c = AA

 

So, it seems, opp01.Account is indeed linked to the account and I have access to its Account_code__c…

 

Just to be sure, I have just added a system.debug message which says:

 

14:16:58.199 (2199397000)|USER_DEBUG|[42]|DEBUG|opp01.Account = Account:{Name=dsi, Account_type__c=CRO, MC_Account_code__c=AA, Id=001f0000002a44XAAQ}

 

Before the execution of the trigger, there is a validation rule that tests the value of opp01.MC_Account_code to be different from null:

 

Line 762 12:15:27.434 (1434787000)|VALIDATION_RULE|03df0000000013E|MC_Check_Account_code
Line 763 12:15:27.435 (1435011000)|VALIDATION_FORMULA|IF( ISPICKVAL( Group__c, "XXX Consultancy"),
Line 764     IF( MC_Account_code__c  = "-1",
Line 765         TRUE,
Line 766         FALSE
Line 767     ),
Line 768     FALSE
Line 769)|Group__c=XXX Consultancy , MC_Account_code__c=-1
Line 770 12:15:27.435 (1435027000)|VALIDATION_FAIL
Line 771 12:15:27.435 (1435551000)|VALIDATION_RULE|03dD0000000MB3g|Project_Type_cannot_be_set_for_this_Opp

 

Trouble is, the field MC_Account_code for the opportunity object is a formula saying:

 

IF(ISBLANK(Account.MC_Account_code__c), "-1", Account.MC_Account_code__c)

 

So it would seem that Account.MC_Account_code__c is "blank" (null indeed). But at the beggining of the test, we didi see the value of Account.MC_Account_code__c for the account acc01, was… AA ! (see ligne 24).

 

So. I don't understand!

 

I have read on multiple occasions that one should update the formula using a SOQL select. Right, ok, fair enough, but how does one do this when this is the very first opportunity created in the (test) database?!

 

How do I update a non existent record so that the required formula field (for its creation) is !null ?!!

Hi Guys,

 

For some reason, All my the formula value are null in my APEX test method, but works all right if I manually insert some data from user interface. Is it normal?

 

But I really need some formula value for the query condition of APEX SOQL. 

 

Thanks in advance

 

 

 

 

 

 

 

 

I have custom object with Roll Up Summary Fields. In a unit test I create the custom object but the roll up summary fields are always null. Any idea how to set these fields in my unit tests?

 

Thanks

Chaitanya