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
davidjbbdavidjbb 

Test Method

Hi Guys,

 

I need help writing a test method without using "delete,insert, or update" in the test method. 

 

The trigger activates another trigger that does a web call out so I want to make sure it doesn't

 

trigger AccToFieldworkerBD on Account (before delete) {

set<String> setAccUser = new set <String> ();

for (Account a :trigger.old){ 
if (a.teamlead__c==true)  { 
setAccUSER.add(a.username__c); 
}
}
list <jbbfc2__Fieldworker_name__c> toDel = new list <jbbfc2__Fieldworker_name__c> ([select jbbfc2__username__c from jbbfc2__Fieldworker_name__c where jbbfc2__username__c in :setAccUser]);

if (toDel.isEmpty() == false){
delete toDel;   
}
}

 

bob_buzzardbob_buzzard

Web callouts aren't executing when testing - they throw an error - so you don't need to worry about that side of it.  However, this does present a challenge when testing the code.

 

This wiki article gives one approach to testing code that has web callouts:

 

http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

davidjbbdavidjbb

How can I avoid the error when writing the test method for the trigger above. I want to be able i'm able to package the trigger/deploy without any errors.

 

 

bob_buzzardbob_buzzard

The link that I posted gives you a way to work around the error situation.  There's also the IsRunningTest method that allows you to detect you are in a test situation and fake a response rather than executing the callout.