• DavidPSG
  • NEWBIE
  • 25 Points
  • Member since 2009

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

Please forgive this really simple example trigger which I'm struggling to get working.

 

I have a Contract record with a custom link to create a new Invoice object. Multiple contracts (children) can reference an Invoice. However when I create a new Invoice, I want the Contract field called "Invoice" to be updated with the InvoiceNumbe, I pass the contract number as a string to the Invoice.

 

 

I've written the trigger in Exclipse, it loads in SF and executes when the Invoice is Updated (I think). But the contract is not updated with the invoice number?

 

trigger trgContractInvoiceNum on Invoices__c (after update) { for (Invoices__c inv : Trigger.new) { Contract ctr = [Select c.Id, c.ContractNumber From Contract c where c.ContractNumber = :inv.SourceContract__c]; ctr.SalesInvoice__c = inv.Id; ctr.Billing_Log__c = inv.Id; / for test purposes } }

 

What silly mistake am I making?

 

Thanks

When I created my first project with the Eclipse IDE, it added a class called starthereController.cls.  I didn't pay any attention to it, but now its forcing me to, because it's interfering with test coverage.   I can't delete it, because it is apparently referenced elsewhere in the project (though where I cannot see). 

 

Can someone point me to an explanation of this class?  What is it, why is it needed, can it be gotten rid of and how?

 

Thanks.

I've written a controller that executes Apex code when a custom button is clicked.  I used the example in this article as my base:

http://sfdc.arrowpointe.com/2009/01/08/invoke-apex-from-a-custom-button-using-a-visualforce-page/

 

It works great and does exactly what I wanted. My version of the controller is for the Contract object.  Basically, when the button is clicked, it invokes Apex code that searches for records in a custom object called Time_Entry__c  and updates the contract# to Time_Entry__c records based on a bunch of criteria.

 

The controller:

public class CtrBnController { private final Contract c; public CtrBnController(ApexPages.StandardController stdController){ this.c = (Contract)stdController.getRecord(); } public PageReference UpdateTE(){ String theId = ApexPages.currentPage().getParameters().get('id'); if(theId == Null){ return Null; } Contract c = [select ID, AccountID, StartDate, EndDate, Contract_App__c from Contract where ID = :theID]; { for(Time_Entry__c t : [select Contract__c, Date__c from Time_Entry__c where Contract__c = Null and Case__r.AccountID = :c.AccountID and Case__r.Contract_App__c != Null and Case__r.Contract_App__c = :c.Contract_App__c]){ if(t.Date__c >= c.StartDate && t.Date__c <= c.EndDate) { t.Contract__c = c.ID; try{ Update t; } catch(DMLException D){ t.Reason__c = 'ERROR Hrs <> Work Type'; Update t; } } } } PageReference pageRef = new PageReference ('/' + theID); pageRef.setRedirect(true); return pageRef; } }

 

The problem is the test method:

static testmethod void TestCtrBn(){ Contract c = [select ID from Contract where CustomerSignedTitle = 'CtrBnController']; ApexPages.StandardController sc = new ApexPages.StandardController(c); CtrBnController controller = new CtrBnController(sc); controller.UpdateTE(); Integer t = [Select count() from Time_entry__c where Contract__c = :c.ID]; system.AssertEquals(3, t); }

 

Based on the way I've set up the test data, UpdateTE should update 3 Time Entries, so t should equal 3, but when I run the test method I get "Assertion Failed:  Expected: 3 Actual: 0"  Also, the Code Coverage results shows that none of the code in UpdateTE is being executed after

 

String theId = ApexPages.currentPage().getParameters().get('id'); if(theId == Null) { return Null; }

 

So it looks to me like the test method cannot see the Contract record.  As I said, the controller actually does work correctly from the platform when tested. 

 

Anyone see what I'm doing wrong?

 

I want to add a custom button to the contract object that will execute Apex code.  Based on my research so far this does not seem to be possible, but I'm hoping I missed something.

 

If it is possible, can anyone point me in the right direction on how it is done?

 

Thanks.

Hi All,

 

I want to write TestMethods for Standard salesforce classes XMLDom & Start here controller. Can any one explain me what is the use of those classes? I written testmethods for all my triggers & classes and got 72%, the code not covered is only Xmldom & starthere controller classes.

 

   Can we delete these classes?

 

Thanks,

Aswath.

  • March 22, 2009
  • Like
  • 0

I would like to call an apex script when a user clicks a button. How can I do that without using an S-Control?

I know how it works with defining an apex method as a webservice and call it from a s-control but I would like to avoid using s-controls.

 

thanks for any help

  • March 19, 2009
  • Like
  • 0

I've written a controller that executes Apex code when a custom button is clicked.  I used the example in this article as my base:

http://sfdc.arrowpointe.com/2009/01/08/invoke-apex-from-a-custom-button-using-a-visualforce-page/

 

It works great and does exactly what I wanted. My version of the controller is for the Contract object.  Basically, when the button is clicked, it invokes Apex code that searches for records in a custom object called Time_Entry__c  and updates the contract# to Time_Entry__c records based on a bunch of criteria.

 

The controller:

public class CtrBnController { private final Contract c; public CtrBnController(ApexPages.StandardController stdController){ this.c = (Contract)stdController.getRecord(); } public PageReference UpdateTE(){ String theId = ApexPages.currentPage().getParameters().get('id'); if(theId == Null){ return Null; } Contract c = [select ID, AccountID, StartDate, EndDate, Contract_App__c from Contract where ID = :theID]; { for(Time_Entry__c t : [select Contract__c, Date__c from Time_Entry__c where Contract__c = Null and Case__r.AccountID = :c.AccountID and Case__r.Contract_App__c != Null and Case__r.Contract_App__c = :c.Contract_App__c]){ if(t.Date__c >= c.StartDate && t.Date__c <= c.EndDate) { t.Contract__c = c.ID; try{ Update t; } catch(DMLException D){ t.Reason__c = 'ERROR Hrs <> Work Type'; Update t; } } } } PageReference pageRef = new PageReference ('/' + theID); pageRef.setRedirect(true); return pageRef; } }

 

The problem is the test method:

static testmethod void TestCtrBn(){ Contract c = [select ID from Contract where CustomerSignedTitle = 'CtrBnController']; ApexPages.StandardController sc = new ApexPages.StandardController(c); CtrBnController controller = new CtrBnController(sc); controller.UpdateTE(); Integer t = [Select count() from Time_entry__c where Contract__c = :c.ID]; system.AssertEquals(3, t); }

 

Based on the way I've set up the test data, UpdateTE should update 3 Time Entries, so t should equal 3, but when I run the test method I get "Assertion Failed:  Expected: 3 Actual: 0"  Also, the Code Coverage results shows that none of the code in UpdateTE is being executed after

 

String theId = ApexPages.currentPage().getParameters().get('id'); if(theId == Null) { return Null; }

 

So it looks to me like the test method cannot see the Contract record.  As I said, the controller actually does work correctly from the platform when tested. 

 

Anyone see what I'm doing wrong?

 

Please forgive this really simple example trigger which I'm struggling to get working.

 

I have a Contract record with a custom link to create a new Invoice object. Multiple contracts (children) can reference an Invoice. However when I create a new Invoice, I want the Contract field called "Invoice" to be updated with the InvoiceNumbe, I pass the contract number as a string to the Invoice.

 

 

I've written the trigger in Exclipse, it loads in SF and executes when the Invoice is Updated (I think). But the contract is not updated with the invoice number?

 

trigger trgContractInvoiceNum on Invoices__c (after update) { for (Invoices__c inv : Trigger.new) { Contract ctr = [Select c.Id, c.ContractNumber From Contract c where c.ContractNumber = :inv.SourceContract__c]; ctr.SalesInvoice__c = inv.Id; ctr.Billing_Log__c = inv.Id; / for test purposes } }

 

What silly mistake am I making?

 

Thanks

Hello i know this is very simple but i am bangging my head....please advise..

 

We have a field called Category which is of type Text. Now the type is changed to picklist.

 

I have an s-Control where i used to grab the Category value.

 

var cate = "{!$User.Category__c}";

 

Now that the field type is changed i am getting the following error

Error: Field Category__c is a picklist field. Use it with an ISPICKVAL() or CASE() function instead.
 
i have searched discussion boards.....but did not find the solution....please help... Thanks in advance
  • March 17, 2009
  • Like
  • 0

I want to add a custom button to the contract object that will execute Apex code.  Based on my research so far this does not seem to be possible, but I'm hoping I missed something.

 

If it is possible, can anyone point me in the right direction on how it is done?

 

Thanks.