• wsmith
  • NEWBIE
  • 90 Points
  • Member since 2008
  • Developer

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 9
    Replies

I am trying to invoke system.schedule method. The first parameter is name of the schedule, second is the schedule string and third is the instance of the apex class that implements Schedulable interface.

 

The schedule string is the following

 

'58 0 20 12 5 ? 2010'

 

I get an exception saying System.Exception: trigger must be associated with a job detail

 

Has anyone encountered this exception before? Any idea where i could be missing? Any help would be appreciated.

 

3:0:57.407|METHOD_ENTRY|[109,32]|system.schedule(String, String, scheduleActiveQChecker)
3:0:57.450|EXCEPTION_THROWN|[109,32]|System.Exception: trigger must be associated with a job detail
3:0:57.450|METHOD_EXIT|[109,32]|schedule(String, String, APEX_OBJECT)

Well Not sure if anybody else has faced this isuse ...

 

I'm facing it right now ... 

 

I'm using this kind statement to Populate StandardSetController instance:

 

ApexPages.StandardSetController setCtrl = new ApexPages.StandardSetController(Database.getQueryLocator([Select ID, Account__c, Contact__c, Contact__r.AccountID From Matter__c]));
setCtrl.setPageSize(400);

 

Now if Query Returned records then it works fine. But if Query doesn't return records then when i access records using this statement:

 

setCtrl.getRecords() - This returns ALL records, if QueryLocator is Empty from the query used. Why is this So happening, I think If it is Empty then It Should return 0 records not All records ... :( ...

 

  • October 06, 2009
  • Like
  • 0
Using a RestResource with a @HttpPost method with parameters, the RestContext.request.requestBody is null compared to a methods without parameters. Is this a bug?

1) Without parameters, RestContext.request.requestBody is not null
@RestResource(urlMapping='/TestRestA/*')
global class WS_TestRestA {
    global class TestIt {
        global String Error;
        global Boolean IsSuccess;
    }

    @HttpPost
    global static void createTestIt() {
        String jsonStr = null;
        if (null != RestContext.request.requestBody) {
            jsonStr = RestContext.request.requestBody.toString();
        }
        System.debug(LoggingLevel.ERROR, 'jsonStr ===> ' + jsonStr);
    }
}

Using Workbench: REST Explorer with JSON {"testItRec" : {"Error" : "An error", "IsSuccess" : false}}
Output:
...
USER_DEBUG|[24]|ERROR|jsonStr ===> {
  "testItRec" : {
     "Error" : "An error",
     "IsSuccess" : false
  }
}
...  

2) With parameter, RestContext.request.requestBody is null
@RestResource(urlMapping='/TestRestA/*')
global class WS_TestRestA {
    global class TestIt {
        global String Error;
        global Boolean IsSuccess;
    }

    @HttpPost
    global static void createTestIt(TestIt testItRec) {
        String jsonStr = null;
        if (null != RestContext.request.requestBody) {
            jsonStr = RestContext.request.requestBody.toString();
        }
        System.debug(LoggingLevel.ERROR, 'jsonStr ===> ' + jsonStr);
    }​
}

Using Workbench Rest Explorer with JSON {"testItRec" : {"Error" : "An error", "IsSuccess" : false}}
Output:
...
USER_DEBUG|[34]|ERROR|jsonStr ===> null
... 
  • January 26, 2015
  • Like
  • 0

I have 5 years extensive experience in Salesforce Development and 15 Years in Java,C/C++ web development.

Summary:

Experienced with a variety of languages systems and methodologies that include Ajax, Apex,Visualforce, Java, C/C++, SQL, HTML, Javascript, CSS, jQuery, PL/SQL, XML, JEE, Java Swing, Struts, Relational Databases, Java Application Servers, Agile, Scrum, Big Machines, etc.

 

 

I can be reached by replying or

wsmithsfe at gmail dot com

 

In my code I want to replace the following where I am checking the value of a formula field (of type text) that refers to a checkbox field. The fomula field returns 'true' or 'false' based on the checkbox being checked or unchecked.

 

Replace:

if ('true' == <MysObject>.Is_Range_Constrained__c) {...}

with:

if (Boolean.valueOf(<MysObject>.Is_Range_Constrained__c)) {...}

 

The problem is the API docs do not explicitly say what is valid arguments for Boolean.valueOf(...) and the expected return values and I do not want to use something that is not documented in case the behavior changes or is specified in a future release.

 

Does anyone know if the code below is the expected behavior of Boolean.valueOf(...) on SFDC and is it documented somewhere? The behavior I get by trial and error is roughly in line with what Java would return.

 

By trial and error I get the following:

System.debug('=======> ' + Boolean.valueOf('true')); .. returns true

System.debug('=======> ' + Boolean.valueOf('True')); .. returns true

System.debug('=======> ' + Boolean.valueOf('TRUE')); .. returns true

System.debug('=======> ' + Boolean.valueOf('false')); .. returns false

System.debug('=======> ' + Boolean.valueOf('False')); .. returns false

System.debug('=======> ' + Boolean.valueOf('FALSE')); .. returns false

System.debug('=======> ' + Boolean.valueOf('')); .. returns false

System.debug('=======> ' + Boolean.valueOf('nnnn')); .. returns false

System.debug('=======> ' + Boolean.valueOf(0)); .. System.TypeException: Invalid boolean or String: 0

System.debug('=======> ' + Boolean.valueOf(1)); .. System.TypeException: Invalid boolean or String: 1

System.debug('=======> ' + Boolean.valueOf(10)); .. System.TypeException: Invalid boolean or String: 10



The following code sample has been throwing an error (by testMethod, execute anonymous, etc.) since the weekend of June 9, 2012. The error is a java.lang.NullPointerException which does not produce a stacktrace.  The code has a parameterized interface which has a method to get a list of another parameterized type. Has anyone seen this error lately?

 

public without sharing class HTTree2 {

    public interface INode<TYPE_> {
        TYPE_ getValue();
        void setValue(TYPE_ value);
        INode<TYPE_> getParent();
        void setParent(INode<TYPE_> parent);
        List<INode<TYPE_>> getChildren();
    }

    public class SObjectNode implements INode<sObject> {

        private sObject value;
        private INode<sObject> parent;
        private List<INode<sObject>> children;

        public SObjectNode() {
            children = new List<INode<sObject>>();
        }

        public sObject getValue() {
            return this.value;
        }

        public void setValue(sObject value) {
            this.value = value;
        }

        public INode<sObject> getParent() {
            return this.parent;
        }

        public void setParent(INode<sObject> parent) {
            this.parent = parent;
        }

        public List<INode<sObject>> getChildren() {
            System.debug('getting children');
            return this.children;
        }

    }

    public static void test1() {
        SObjectNode n0 = new SObjectNode();
        System.debug('log0===>' + n0.getChildren().size());
        INode<sObject> n1 = new SObjectNode();
        System.debug('log1.begin===> the line below throws an error');
        // the line below throws an error
        System.debug('log1===>' + n1.getChildren());
    }

    public static testmethod void test2() {
        SObjectNode n0 = new SObjectNode();
        System.debug('log0===>' + n0.getChildren().size());
        INode<sObject> n1 = new SObjectNode();
        System.debug('log1.begin===> the line below throws an error');
        // the line below throws an error
        System.debug('log1===>' + n1.getChildren());
    }

}

Exception type: class common.apex.runtime.impl.ExecutionException
Exception msg: Attempt to de-reference a null object
Stack trace:
common.apex.runtime.impl.ExecutionException: Attempt to de-reference a null object

 

Above is a exception I am seeing thrown from a Visualforce Controller class.  I have narrowed down, in the Apex code, the code block area it occurs but I cannot find the error that causes it.  It makes me believe this is a runtime bug in the Apex runtime engine.

 

Has anyone else seen this exception and have a suggestion on how to debug or fix it.

 

  • August 27, 2009
  • Like
  • 0

I want to create a method that handles null enum values.  Do I have to create a handler method for each enum data type I want to check or is there a base enum type that enums derive from which the "instanceof" operator will work?

 

i.e.

enum A {ONE, TWO}

enum B {THREE, FOUR}

 

void checkEnum(<DataType> value) {

    if (value == null)

    // log error, etc.

}

 

However, A and B are not an "instanceof" Object nor sObject so what can "<DataType>" be?

In the example below I am using the Opportunity object and a Date/Time field.


The Date/Time field type is not converted into a Datetime data typeIs this a bug?

Opportunity o = ...;
Map opportunityFieldMap = Schema.SObjectType.Opportunity.fields.getMap();
Schema.DescribeFieldResult currentStageDFR = opportunityFieldMap.get('mydatetimefield__c').getDescribe();
Object currentStageValue = o.get(currentStageDFR.getName());

Examining the field object I get the following values:

(currentStageValue instanceOf Datetime) == false
(currentStageValue instanceOf Date) == true
(currentStageValue instanceOf Time) == false
String.valueOf(currentStageValue) == '2009-03-20 22:34:00' // GMT time and seconds are truncated/lost

((Date) currentStageValue).format() == '3/20/2009'

 

If I try to convert it into a Datetime using a Strings (since I cannot access time info on a Date data type) it loses the correct time by ignoring AM/PM info and loses the seconds.


Datetime myDateTime = Datetime.valueOf(String.valueOf(currentStageValue)) == '2009-03-21 05:34:00' //added hours

Datetime myDateTime = Datetime.valueOfGmt(String.valueOf(currentStageValue)) == '2009-03-20 22:34:00'

Is there a way to get a correct Datetime data type using sObject.get(...) for a Date/Time field types that keeps seconds?

  • March 25, 2009
  • Like
  • 0

Does anyone know what table or field links Holiday records to BusinessHours records?  It is not apparant how they are linked by looking at the Enterprise WSDL or Apex Explorer.

 

As an example, where multiple BusinessHours may exist (i.e. for offices in other countries) and each office has local holidays for that office.

 

 

Thanks

  • March 19, 2009
  • Like
  • 0
Is it legal or not to hard code a RecordId in a unit test (i.e. instead of querying the RecordType by name at runtime).  To me is seems a bad practice since the RecordId may be different on Prduction then the Sandbox.

If I deploy the sandbox to production and later create a new sandbox from production, will the recordid of the same objects (by name) be the same on Production and the Sandboxes?

In practice I have seen hard coded Record IDs in Sandbox unit test that seems to be deployable to Production.


  • October 24, 2008
  • Like
  • 0
How can I get code coverage in the follow DMLException?
 
Code:
try {
  insert oppList;
}
catch (DmlException e) {
    for (Integer i = 0, leni = e.getNumDml(); i < leni; ++i) {
        Opportunity o = oppList.get(e.getDmlIndex(i));
        o.addError(e.getDmlMessage(i));
    }
}

 Do I have to explicitly create a object that will fail in the insert even though it has nothing to do with the logic I really want to test.
 
In another example; from the Cookbook, there is:
 
Code:
if ((updatedContacts.size() + Limits.getDMLRows()) > Limits.getLimitDMLRows()) {

...
...

}

 
Does that mean I have to create up to 100 (more or less depending on the governor limit of the environment)  test objects to get past the "if' statement and test the code in the block?
 
It seems that best practices does not allow code coverage for those areas; unless it is expected these areas will be a small amount of code in a class and it is ok not to test them?
  • September 12, 2008
  • Like
  • 0
This post is based on the post "Changing Owner to something else (when owner is being changed)" http://community.salesforce.com/sforce/board/message?board.id=apex&thread.id=7847.  Thus also happens on Account objects.
There seems to be a workaround but I am not sure if this is a best practice or something may change, in a future Apex release, that breaks this.
The workaround is in the afterUpdate trigger:section
1) Query for the same sObject
2) Set the sObject field
3) Set a do not be a recursive trigger flag
4) Update the sObject

Pseudo code ..

1) Assume only one record at a time

2) Assume The user will use the Account UI to change the Account Owner

Code:
class TriggerHelper {
    public static Boolean ALLOWRECURSION = true;
}

trigger Accounts on Account (before update, after update) {

    if (!TriggerHelper.ALLOWRECURSION) {
        return;
    }

    if (
        (Trigger.isBefore) &&
        (Trigger.old[0].OwnerId != Trigger.new[0].OwnerId)
    ) {

        User u =
            [select MyFieldId__c from User where Id = :Trigger.new[0].OwnerId];
        Trigger.new[0].MyExecutive__c = u.MyFieldId__c;
        Trigger.new[0].OwnerId = u.MyFieldId__c;

    }

    if (
        (Trigger.isAfter) &&
        (Trigger.new[0].OwnerId != Trigger.new[0].MyExecutive__c) 
    ) {

       // Here we find that setting the Owner with the standard UI
       // retains the explicitly picked record Owner instead of what
       // was set in the isBefore section

       // Query for the record we are updating
       Account acct =
           [select OwnerId, Executive__c from Account where Id =
            Trigger.new[0].Id];

       // Set the field
       acct.OwnerId = acct.MyExecutive__c;

       TriggerHelper.ALLOWRECURSION = false;
       try {
           update acct;
       }
       finally {
           TriggerHelper.ALLOWRECURSION = true;
       }

    }

}

 Any thoughts?


Message Edited by wsmith on 09-11-2008 10:46 AM
  • September 11, 2008
  • Like
  • 0
Apex arrays have a Governor limit of 1000 elements.  If I have a web service that returns an array of objects, is there a best practice for allowing a web service to return more then 1000 objects/  Perhaps a query more type API where the array returns objects in a range specified by the user.

Is there a best practice for allowing a web service to return more then 1000 objects?
  • September 09, 2008
  • Like
  • 0
Any idea how to create test users in Apex and modify their fields where preferences are kept

Since Summer08 the ability to modify users in unit test methods was removed.
  • September 09, 2008
  • Like
  • 0

I am planning to give a talk about Apex.  Most people outside the Salesforce.com world have even heard of Apex.  The talk will be about 60 minutes.

This will be introduction to Apex in terms of what it looks like, what it can do and its strengths and weaknesses.  I plan to point out what is great, what needs improvement and what is uncertain (don't know what is really happening or is it efficient).  Most of the audience are developers who do not need to be bothered with a 'Hello World" example.

Does anyone have a  suggestion as to what likes, dislikes they have about Apex that they think is important?

For example, I am currently thinking about:

1) The lack of transparency of the runtime.

2) No debugging besides System.debug(...).

3) No idea how efficient or inefficient list to array conversions is:

i.e. sObjs[0] = ...;
      sObjs[4] = ...;
      List<sObject> lObjs = sObjs;
      sObject tmp = lObjs[0];

    Internally (runtime), did the above convert an array into a list and a list to an array and if so how many times?  By doing the above, did I allocate a few internal data structures and did a lot of copying?  Does the runtime only have a list and the array syntax just syntax sugar?

4) Having to upload to Salesforce.com to compile Apex and see syntax errors.

5) “testmethod” keyword is great

6) “webservice” keyword is great

7) Governor Limits force developers to structure code in a way has to meet SOQL limits, array size limits, etc. compared to using standard practices of structuring code.

8) Reflection by describing and object has a Governor limit problem.  For example, if there are too many items in a picklist you have to make a copy of the picklist in your code.  It would be nice if a picklist can be linked to an Apex object containg an array of values and thus the picklist is defined only once.  The same for constant strings and other data types.

etc.

Any suggestions or disagreements would be welcome.  This is not to start a flame war but to point out what is great, what needs improvement and what is uncertain (don't know what is really happening or is it efficient).

Thanks
  • September 03, 2008
  • Like
  • 0
Using a RestResource with a @HttpPost method with parameters, the RestContext.request.requestBody is null compared to a methods without parameters. Is this a bug?

1) Without parameters, RestContext.request.requestBody is not null
@RestResource(urlMapping='/TestRestA/*')
global class WS_TestRestA {
    global class TestIt {
        global String Error;
        global Boolean IsSuccess;
    }

    @HttpPost
    global static void createTestIt() {
        String jsonStr = null;
        if (null != RestContext.request.requestBody) {
            jsonStr = RestContext.request.requestBody.toString();
        }
        System.debug(LoggingLevel.ERROR, 'jsonStr ===> ' + jsonStr);
    }
}

Using Workbench: REST Explorer with JSON {"testItRec" : {"Error" : "An error", "IsSuccess" : false}}
Output:
...
USER_DEBUG|[24]|ERROR|jsonStr ===> {
  "testItRec" : {
     "Error" : "An error",
     "IsSuccess" : false
  }
}
...  

2) With parameter, RestContext.request.requestBody is null
@RestResource(urlMapping='/TestRestA/*')
global class WS_TestRestA {
    global class TestIt {
        global String Error;
        global Boolean IsSuccess;
    }

    @HttpPost
    global static void createTestIt(TestIt testItRec) {
        String jsonStr = null;
        if (null != RestContext.request.requestBody) {
            jsonStr = RestContext.request.requestBody.toString();
        }
        System.debug(LoggingLevel.ERROR, 'jsonStr ===> ' + jsonStr);
    }​
}

Using Workbench Rest Explorer with JSON {"testItRec" : {"Error" : "An error", "IsSuccess" : false}}
Output:
...
USER_DEBUG|[34]|ERROR|jsonStr ===> null
... 
  • January 26, 2015
  • Like
  • 0

In my code I want to replace the following where I am checking the value of a formula field (of type text) that refers to a checkbox field. The fomula field returns 'true' or 'false' based on the checkbox being checked or unchecked.

 

Replace:

if ('true' == <MysObject>.Is_Range_Constrained__c) {...}

with:

if (Boolean.valueOf(<MysObject>.Is_Range_Constrained__c)) {...}

 

The problem is the API docs do not explicitly say what is valid arguments for Boolean.valueOf(...) and the expected return values and I do not want to use something that is not documented in case the behavior changes or is specified in a future release.

 

Does anyone know if the code below is the expected behavior of Boolean.valueOf(...) on SFDC and is it documented somewhere? The behavior I get by trial and error is roughly in line with what Java would return.

 

By trial and error I get the following:

System.debug('=======> ' + Boolean.valueOf('true')); .. returns true

System.debug('=======> ' + Boolean.valueOf('True')); .. returns true

System.debug('=======> ' + Boolean.valueOf('TRUE')); .. returns true

System.debug('=======> ' + Boolean.valueOf('false')); .. returns false

System.debug('=======> ' + Boolean.valueOf('False')); .. returns false

System.debug('=======> ' + Boolean.valueOf('FALSE')); .. returns false

System.debug('=======> ' + Boolean.valueOf('')); .. returns false

System.debug('=======> ' + Boolean.valueOf('nnnn')); .. returns false

System.debug('=======> ' + Boolean.valueOf(0)); .. System.TypeException: Invalid boolean or String: 0

System.debug('=======> ' + Boolean.valueOf(1)); .. System.TypeException: Invalid boolean or String: 1

System.debug('=======> ' + Boolean.valueOf(10)); .. System.TypeException: Invalid boolean or String: 10



We are doing a POC to integrate the ERP with SFDC, there are some exceptions while making a basic authentication to SFDC. Please find the details below.

  1. Registered at salesforce.com for developer forum
  2. Downloaded the enterprise WSDL which is provided by the salesforce for developers.
  3. Downloaded the client certificates for the same to make a secure call.
  4. Created a project in TIBCO imported the WSDL file and created a webservice using the same.
  5. Created HTTP Connection activity with the following details
    1. Host name as login.salesforce.com
    2. Port as 80
    3. There is already a process called Soaplogin with start and end activity, we have added SOAP Request Reply and configured the details, including SSL.
      1. Provided the user name and password
      2. When we are running the application, it’s not able to do the basic authentication and it’s throwing the error Server certificate rejected by ChainVerifier 

Please make a note in the salesforce.com for the developer edition, they didn’t provided the identity files for the same. I have created my own certificate for the same. But still I am getting the same error.

I am trying to invoke system.schedule method. The first parameter is name of the schedule, second is the schedule string and third is the instance of the apex class that implements Schedulable interface.

 

The schedule string is the following

 

'58 0 20 12 5 ? 2010'

 

I get an exception saying System.Exception: trigger must be associated with a job detail

 

Has anyone encountered this exception before? Any idea where i could be missing? Any help would be appreciated.

 

3:0:57.407|METHOD_ENTRY|[109,32]|system.schedule(String, String, scheduleActiveQChecker)
3:0:57.450|EXCEPTION_THROWN|[109,32]|System.Exception: trigger must be associated with a job detail
3:0:57.450|METHOD_EXIT|[109,32]|schedule(String, String, APEX_OBJECT)

I have researched the code to set up the approval process trigger but I keep getting the following error:

 

Severity and Description Path Resource Location Creation Time Id
Save error: Variable does not exist: req1 Update Case Triggers/src/triggers Approval_Process.trigger line 12 1256322606703 445

This is my code:

 

trigger Approval_Process on Case (after insert, after update) { for(Case cs: Trigger.new) { cs = [ select ID from Case where id in :Trigger.new ]; if(cs.Agree_to_Submit_for_Approval__c == 'true') Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setComments('Submitting request for approval.'); req1.setObjectId(cs.id); Approval.ProcessResult result = Approval.process(req1); System.assert(result.isSuccess()); System.assertEquals('Pending', result.getInstanceStatus(), 'Instance Status'+result.getInstanceStatus()); } }

The line the code is referring too is:

Approval.ProcessResult result = Approval.process(req1);

 

Please help

Well Not sure if anybody else has faced this isuse ...

 

I'm facing it right now ... 

 

I'm using this kind statement to Populate StandardSetController instance:

 

ApexPages.StandardSetController setCtrl = new ApexPages.StandardSetController(Database.getQueryLocator([Select ID, Account__c, Contact__c, Contact__r.AccountID From Matter__c]));
setCtrl.setPageSize(400);

 

Now if Query Returned records then it works fine. But if Query doesn't return records then when i access records using this statement:

 

setCtrl.getRecords() - This returns ALL records, if QueryLocator is Empty from the query used. Why is this So happening, I think If it is Empty then It Should return 0 records not All records ... :( ...

 

  • October 06, 2009
  • Like
  • 0

Hi I am using wsdl 2 java to get java source for the specified WSDL.Iam  using axis-2 1.4 and JDK 1.6 as my environment.

When i used to generate the java code from enterpriseWSDL for the example given in Force.com (QuickStat) I am only getting the 11 classes.Not able to get all the classes. Is i am missing something ? please help.

Apex arrays have a Governor limit of 1000 elements.  If I have a web service that returns an array of objects, is there a best practice for allowing a web service to return more then 1000 objects/  Perhaps a query more type API where the array returns objects in a range specified by the user.

Is there a best practice for allowing a web service to return more then 1000 objects?
  • September 09, 2008
  • Like
  • 0
No one can answer to this question?
 
 
 
Is it possible to update a field in an existing opportunity using an after update trigger?  I'm trying to get the id of the new owner of the opportunity, but I get read only when executing the trigger after update.  If I use before update, the id of the owner is the old owner and not the new one.
 
Here is the code to my trigger and class:
 
Code:
trigger UpdateOpportunityOwnerRole on Opportunity (before update) {
 OpportunityOwnerRole.UpdateOwnerRole(Trigger.new);
}

public class OpportunityOwnerRole {

public static void UpdateOwnerRole(Opportunity[] opps) {
  
  Opportunity opp = [select ownerid from Opportunity where id in :opps];
  
  Id oid = opp.ownerid;
  
  User role = [select userroleid from User where id = :oid];
  
  Id urid = role.userroleid;
  
  UserRole userrole = [select name from UserRole where id = :urid];
  
  String strownerrole = userrole.name;
  
  for (Opportunity op: opps) {
   op.owner_role__c = strownerrole;
  }
 }
}

 
I need to get the owner id that has changed?  How can I do this?
 
Thanks for any help.


Message Edited by Dman100 on 08-21-2008 07:10 PM