I have a several Grails services that are invoked from Flex code using Spring BlazeDS integration. I wanted to add some general debug logging using the groovy metaClass. I have the following in a bootstrap class:  class MyBootStrap {  def grailsApplication  def init = { servletContext -&gt;         initServiceCallLogging() }  def destroy = { }  private def initServiceCallLogging() {     grailsApplication.serviceClasses.each { serviceClass -&gt;         serviceClass.metaClass.invokeMethod = { name, args -&gt;             log.debug "Method $name invoked"             def metaMethod = delegate.metaClass.getMetaMethod(name, args)             def result = metaMethod.invoke(delegate, args)             return result          }     } } }   This works fine as long as the Service method is called from e.g. a Grails Controller or Service but when directly called from Flex (via BlazeDS), the method calls are not intercepted.  Anyone an idea how this can be solved or is this not possible via metaprogramming and should Spring AOP be used?  Thx
29653
I know Googling I can find an appropriate answer, but I prefer listening to your personal (and maybe technical) opinions. What is the main reason of the difference between Java and C# in throwing exceptions? In Java the signature of a method that throws an exception has to use the "throws" keyword, while in C# you don't know in compilation time if an exception could be thrown.
95871
I have a class which has a method that is receiving an object as a parameter.  This method is invoked via RMI.  public RMIClass extends Serializable {     public RMIMethod(MyFile file){         // do stuff     } }   MyFile has a property called "body", which is a byte array.   public final class MyFile implements Serializable {      private byte[] body = new byte[0];     //....       public byte[] getBody() {         return body;     }     //.... }   This property holds the gzipped data of a file that was parsed by another application.  I need to decompress this byte array before performing further actions with it.   All the examples I see of decompressing gzipped data assume that I want to write it to the disk and create a physical file, which I do not.  How do I do this?  Thanks in advance.
9169
I want to see the stack trace in any function of my code, so i made somthing like this to call it and print the stack trace:  public function PrintStackTrace() {     try {         throw new Error('StackTrace');     } catch (e:Error) {         trace(e.getStackTrace());     } }   I like to know if there are other way to do this. In some place, the Error class creates the stack trace, but maybe it didn't do it with ActionScript 3.0 so maybe it's not posible, but i want to know.  Thanks!
8856
I'd like to avoid logging some missing files (that gives a 404) into the Apache2 error log.  I want to do this on an Eclipse update site for my plugin. Problem is that the Eclipse P2 code tries to access its metadata files like content.xml, content.jar, digest.zip and a few others, which are not available on my site. When P2 finds this out, it finally reaches for site.xml, which I provide. All in all, everything works fine ... but I have tons of lines like:  [Mon Jul 06 21:46:46 2009] [error] [client 195.91.79.90] File does not exist: ...htdocs/stable/content.jar   in my error.log file, which doesn't help me very much.  One solution that comes to my mind is to let Apache log through grep (via pipe-logging), but I am looking for a better solution.  I was thinking about tagging these requests with SetEnvIf directive, and skipping error log for tagged requests, but the ErrorLog directive doesn't support that.  Any other ideas?
86373
Groovy adds the execute method to String to make executing shells fairly easy;  println "ls".execute().text   but if an error happens, then there is no resulting output.  Is there an easy way to get both the standard error and standard out?  (other than creating a bunch of code to; create two threads to read both inputstreams, then using a parent stream to wait for them to complete then convert the strings back to text?)  It would be nice to have something like;   def x = shellDo("ls /tmp/NoFile")  println "out: ${x.out} err:${x.err}"
109534
I am trying to write a test class.  My Apex class has the following constructor:  public NController(ApexPages.StandardController controller) {      cas =  (Case) controller.getRecord();     csId = cas.Id;     owner = cas.OwnerId;      N_SSettings__c nhdsms = N_SSettings__c.getValues('Int');     rate=nhdsms.Rate_Code__c;     accId=nhdsms.Acc_Id__c;  }   Here N_SSettings__c is a custom settings which has two fields Rate_Code__c and Acc_Id__c. It has a record called 'Int' with both Rate_Code__c and Acc_Id__c field values populated.  I am using the following test class method:  @isTest public class NHSsendSMSController_Test {     public static testMethod void NHSsendSMSControllerTest()     {         Case caseObj = new Case();         insert caseObj;         ApexPages.StandardController sc = new ApexPages.standardController(caseObj);         NController nControllerObj = new NController(sc);         nControllerObj.methodName();     } }   When I run the test method, it is throwing a null pointer exception on the line :  rate = nhdsms.Rate_Code__c;   The custom setting is definitely present with the required values of both the fields of Int.
56738
In Field Service Lightning I have a Trigger on ServiceReport which sends an email with attachment coming from ContentVersion.   This is the Test class I have written.  @isTest  private class testCreateServiceReport{       static testMethod void validateWO() {       WorkOrder wo = new WorkOrder();       wo.subject = 'Testing';       insert wo;       ServiceAppointment sa = new ServiceAppointment();       sa.ParentRecordId = wo.Id;       sa.EarliestStartTime = DateTime.now();       sa.DueDate = DateTime.now();       insert sa;       List&lt;ServiceReportLayout&gt; srl = [Select Id FROM ServiceReportLayout];       ServiceReport sr = new ServiceReport();       sr.ParentId = sa.Id;       sr.Template = srl[0].Id; //Need to check if there is a way to avoid srl[0] notation       insert sr; //If I comment this the text result is pass. When I enable it I get too see the below mentioned error.  }  }   This is the error Methods defined as TestMethod do not support Web service callouts I know that we need to write Test Classes for code that involves web service callouts using setMock() but I dont understand in what way inserting ServiceReport is related to making a callout.  Any help on this will be really helpful.
59367
I got a situation where i need to invoke future method from batch class. And i know that it is not possible to do. But there might be some workarounds to achieve it, right? And i dont want to invoke future method using shedule apex as my requirement will hit governor limits of "Total number of schedule jobs exceed". So i tried in below ways, but still fighting with same issue.  My design is  Scenario 1 :   Schedule Apex ===> 2. BatchClass (Runs every hour) (Generates a map with "N" records for every batch context, and passes it to Future method in an apex class)  ===> 3. Future method ( then it will login to a salesforce account and generates an attachment and sends an email to a corresponding email address) .   Scenario 2 :  Since, It is not possible to invoke future method from batch, i tried implementing an apex class with a normal static method  invoking future method and in a batch class, for every context i.e., execute() method, it will invoke a normal method which in turn invokes future method, but still got the same error      FATAL ERROR: Future method cant be called from future or Batch   ie.,   global class BatchClass implements Database.batachable&lt;Sobject&gt; {    global Iterable&lt;ScheduledReport__c&gt; start(Database.BatchableContext BC)  {         query=[];        return query;  }  global void execute(Database.BatchableContext BC, List&lt;ScheduledReport__c&gt; scope) {      FutureClass.normalMethod(mapRecords);   }    global void finish(Database.BatchableContext BC){   }  }   Future Class:   global class FutureClass {  global static void normalMethod(Map&lt;&gt; mapR) {      futureMethod(mapR);  }  @future(callout=true)  global static void futureMethod(Map&lt;&gt; m) {      //some code;   }  }   Scenario 3 :  Instead of invoking future class method from batch i tried updating list of records and done checkbox value to true and i've implemented after update event trigger to get the all the records in which checkbox values are true and from trigger i tried invoking future method , still didnt work , i got an error      FATAL ERROR: Future method cant be called from future or Batch   Please help me out.   Thanks !
45541
When you have a dedicated Visualforce Page and can use modern JavaScript Remoting techniques, this is seldom an issue. But I'm looking at some historical code in a managed package like this:  {!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}  var result = sforce.apex.execute(     "ns.WebServiceClass",     "someWebServiceMethod",     {"arg1": "foo", "arg2": "bar"} );  alert(result);   The ns is baked in. While this JavaScript can be deployed to another development org, the web service invocation will not execute as the class doesn't have a namespace prefix in this environment.  Same problem applies to Custom Button or Link URLs. Surely URLFOR('/apex/PageName') would resolve the namespace prefix; after all the button is a managed component with the namespace on it. But it doesn't work the same magic that new PageReference('/apex/PageName') does in Apex.  I've seen a few approaches including (but not limited to):   maintaining a list of manual deployment steps, using some precompile task (eg Ant) to tokenize the namespace prefix,   Can you gurus share any other techniques?
66803
I am trying to call my Apex class from a trigger:  trigger newCrossSellAccounts on Account (before insert) {    crossSellModule.insertAfterAccount2(trigger.new); }   On the class I have:  public void insertAfterAccount2(list&lt;account&gt; accountList){   When I try to save trigger I get error:  Method does not exist or incorrect signature: crossSellModule.insertAfterAccount2(LIST&lt;Account&gt;) at line 2 column 4    Now from  it says .new "Returns a list of the new versions of the sObject records." I tried to change the function on class to:  public void insertAfterAccount2(sObject&lt;account&gt; accountList){   But I get error:  Invalid type: sObject&lt;account&gt;    Should I loop thru and create a list in trigger first? Or is there are workaround. Also, how one would test such trigger/class combination?
76771
Are there any governor limits, or considerations that I should be aware of when using Apex Describe methods?  So for example, the author of this blog post uses the structure below to get the record type instead of doing a soql query.     //Generate a map of tokens for the sObjects in your organization Map gd = Schema.getGlobalDescribe();  //Retrieve the describe result for the desired object DescribeSObjectResult result = gd.get('Account').getDescribe();  //Generate a map of tokens for all the Record Types for the desired object Map recordTypeInfo = result.getRecordTypeInfosByName(); system.debug('RECORD TYPES:' + recordTypeInfo);  //Retrieve the record type id by name String recordTypeId = recordTypeInfo.get('RECORDTYPE_NAME').getRecordTypeId();
93403
Is there any way to access the Windows Event Log from a java class. Has anyone written any APIs for this, and would there be any way to access the data from a remote machine?  The scenario is:  I run a process on a remote machine, from a controlling Java process. This remote process logs stuff to the Event Log, which I want to be able to see in the controlling process.  Thanks in advance.
117234
I'm an end-user of one of my company's products. It is not very suitable for integration into Spring, however I am able to get a handle on the context and retrieve the required bean by name.  However, I would still like to know if it was possible to inject a bean into this class, even though the class is not managed by Spring itself.  Clarification: The same application which is managing the lifecycle of some class MyClass, is also managing the lifecycle of the Spring context. Spring does not have any knowledge of the instance of MyClass, and I would like to some how provide the instance to the context, but cannot create the instance in the context itself.
44001
I want to do some functional testing on a (restful) webservice. The testsuite contains a bunch of test cases, each of which performs a couple of HTTP requests on the webservice.  Naturally, the webservice has to run or the tests will fail. :-)  Starting the webservice takes a couple of minutes (it does some heavy data lifting), so I want to start it as infrequently as possible (at least all test cases that only GET resources from the service could share one).  So is there a way to do set up me the bomb in a test suite, before the tests are run like in a @BeforeClass method of a test case?
66464
I don't think this is possible, but if is then I need it :)  I have a auto-generated proxy file from the wsdl.exe command line tool by Visual Studio 2008.  The proxy output is partial classes. I want to override the default constructor that is generated. I would rather not modify the code since it is auto-generated.  I tried making another partial class and redefining the default constructor, but that doesn't work. I then tried using the override and new keywords, but that doesn't work.  I know I could inherit from the partial class, but that would mean I'd have to change all of our source code to point to the new parent class. I would rather not have to do this.  Any ideas, work arounds, or hacks?   //Auto-generated class namespace MyNamespace {    public partial class MyWebService : System.Web.Services.Protocols.SoapHttpClientProtocol {       public MyWebService() {          string myString = "auto-generated constructor";          //other code...       }    } }  //Manually created class in order to override the default constructor namespace MyNamespace {    public partial class MyWebService : System.Web.Services.Protocols.SoapHttpClientProtocol {       public override MyWebService() { //this doesn't work          string myString = "overridden constructor";          //other code...       }    } }
112948
The Apex class is not in a package, has global visibility, is Active, has passing tests with 86% coverage, and the method has the @InvocableMethod tag but it is still not showing up in the picklist when trying to add an Apex Action to a flow.  I'm wondering if there's anything I'm missing.
22440
I want to declare two beans and instantiate them using Spring dependency injection?  &lt;bean id="sessionFactory" class="SessionFactoryImpl"&gt;  &lt;property name="entityInterceptor" ref="entityInterceptor"/&gt; &lt;/bean&gt;  &lt;bean id="entityInterceptor" class="EntityInterceptorImpl"&gt;  &lt;property name="sessionFactory" ref="sessionFactory"/&gt; &lt;/bean&gt;   But Spring throws an exception saying "FactoryBean which is currently in creation returned null from getObject"  Why is inter-dependent bean wiring not working here? Should i specify defferred property binding anywhere?