• adreamer
  • NEWBIE
  • 99 Points
  • Member since 2008

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 46
    Questions
  • 60
    Replies

I am seeing a strange behaviour in test methods when moving classes to version 24 of the API.

 

The calss in question is an implementation of a Batch Job.

 

The start method includes a try/catch block.

 

One of the test methods for the class tries to simulate an exception on the start method. To force the exception in the test method I am passing a query that will lead an empty result set. 

 

When the class API version is 19, this works fine in the sense that the test method forces the exeption, and this is caught in the try/catch block as expected. In the catch block I send an email to the system admin to notify the excpetion and its cause.

 

However when the class API version is 24,  I get a test failure (despite that the coverage remains the same). Looking at the debug logs of the test run, I can see that the exception is caught, and that the email is sent.

 

What is strange is that the test method now fails with version 24.

 

Any ideas ?

 

Thanks

Fernando

Hi All,

 

I have a managed-released package that is having an issue with a specific client related to test coverage.

 

The package installs fine in the client's production org (EE). The package works with a server outside Salesforce that uses the Metadata API to create custom fields in one of the package custom objects. This is done by creating the XML deploymet file on the fly, and using the deploy method of the Metadata API. This works works in all orgs with no problem. However for this specific client, the deployment fails with an error that says that there is only 65% code coverage and 75% is required.

 

I have a few questions on this:

1. Does the deployment as described above to create custom fields in one of the package custom objects kicks any test code run ?. Given the error message she gets, it seems it does.

 

2. If a test code run is kicked by the remote deployment, does it run all test code on all the code for that org ?.

 

3. In an attempt to look into the problem I did something that, in retrospect, it does not make sense. I tries the "Run All Tests" button in an EE production org where the package is installed. The results was weird because there were a lot of test failures in test methods of the package that said:"System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Start_Time__c, End_Time__c]: [Start_Time__c, End_Time__c]". All the errors were exactly he same, and this does not make sense because the fields Start_Time__c and End_Time__c are not part of the package and are not part of Salesforce as far as I know. I am inclined to think that using the "Run All Tests" button in a prod org where there are managed-release packages it does not make sense. Is that the case ?

 

4. This client has other packages installed (none custom development) and I suspect that one of these packages might be lacking test coverage perhaps ?. What would be the best way to assert this ?. running all test in a sandbox.

 

Thank you very much in advance.

 

Fernando

Hi All,

 

When deploying a single file/class from a dev org to a production org, does only the test code in that single file runs or the deployment of the single file kicks the test code for all classes in the production org ?.

 

Thank you very much in advance.

 

Fernando

Hi All,

 

We have a managed-released package (passed security review) that is showing some strange behaviour with a particular user - all other users with PE and EE have installed it and are using it fine.

 

This particular user has an EE.

 

After installing the app, he went on to use a part of the app which under the hood connects to an external server, which in turn uses the Metadata API to create a few custom fields in a custom object. The weird thing is that in his case the deployment fails with an error saying that test coverage is xx% and it needs at least 75%.

 

This is strange because:

 

- to create a managed-release package one must have test coverage above 75% which we have (over 90%)

- why a single users is experiencing this issue

- why this happens with a Metadata API call 

 

Has somebody experienced something similar ?

 

Has anything changed recentely ?

 

Btw I tried to reinstall the app in one of our testing EE orgs and cannot reproduce the issue.

 

Thank you very much in advance.

Fernando

Hi All,

 

I am trying to develop testing code for a package that supports using revenue schedules in opportunity products but, as we know, schedules have to be manually enabled and users installing the package may not use it so it will be disabled.

 

The issue I am facing is that when schedules are disabled, the object OpportunityLineItemSchedule is not part of the org. Consequently, any apex code having a reference to the object will fail during installation because the object is not there.

 

In the package logic I use dynamic queries and I check if the org has the OpportunityLineItemSchedule object so there is no issue with the package functionality

regardless of whether the installer user's org has schedules enabled or not.

 

The issue is with writing the testing code. Here I am facing with having to create records of OpportunityLineItemSchedule object to create the test data. And this automatically introduces a reference to the object.

 

Has somebody has a way around this ?.

 

Thank you very much in advance.

Fernando

Hi All,

 

I am dealing with an outbound call from salesforce to an external server that uses HTTPS/SSL.

I understand from the documenation that to be valid the certificate must be issued by a Certificate Authority trusted by Java 2 Platform,. 

 

CA certs cost money and I wonder if there a way to use a self-signed certtificate for testing purposes.

 

Thank you very much in advance.

Fernando

Hi All,

 

I am using a dev org to do the packaging. In this org the test coverage is over the required limit, and I managed to upload the package.

 

When trying to install the package I get a long series of errors during a package (managed-beta) installation, and all the failures share in common the they occur in test methods and are always same problem: System.QueryException: List has no rows for assignment to SObject.

 

The test methods where the installation fails share a common pattern. In each Apex class I have a static method initData where I intialize and insert the records required in the test methods. Then the test methods first of all call this initData() method, and then I fetch records.  For instance:

 

static void initData()

{

   MyObject__c obj = new MyObject__c(Name='Hello');

  insert obj;

}

 

static testmethod void test1()

{

  initData();

 List<MyObject__c> objs = [select Id, Name from MyObject__c where Name='Hello'];

 if(objs.size() > 0)

  {

    .......

  }

}

 

I believe the line in red is the one that is causing the exception System.QueryException: List has no rows for assignment to SObject during the installation of the package.

 

What I don't understand is why this fails during installation but doesn't fail during running of the test methods and package upload.

 

Any ideas ?

 

Thanks,

Fernando

 

 

Hi All,

 

I am seeing a substantial difference in the test coverage between the results in Eclipse and the results of Salesforce online UI.

 

Here is a concrete example. A controller class when running the test for it in Eclipse I get 99% coverage and only 3 lines are not covered.

 

On the other hand, when I run all test from Salesforce online UI (Setup | App Setup | Classes and using the Run All Test button) I get for the same class only 59% coverage. Moreover, if I click on this class and run the test for that class in Salesforce I still get 59%.

 

Has anybody seen something like this ?

 

Regards,

Fernando

Hi All,

 

The SelectOption connstructor is setting the value and label the other way around ?

 

Here is the output of an execute anonymous:

 

Anonymous execution was successful.

20.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO
Execute Anonymous: List<SelectOption> etOpts = new List<SelectOption>();
Execute Anonymous: etOpts.add(new SelectOption('value','label'));
Execute Anonymous: System.debug('options --> '+etOpts);
16:35:46.053 (53364000)|EXECUTION_STARTED
16:35:46.053 (53402000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
16:35:46.054 (54365000)|USER_DEBUG|[3]|DEBUG|options --> (System.SelectOption[value="label", label="value", disabled="false"])
16:35:46.941 (54452000)|CUMULATIVE_LIMIT_USAGE

 

The red line is where I construct the SelectOption following the manual : SelectOption option = new SelectOption(value, label, isDisabled);

 

However when I look at the list with the debug statement, the blue part,  they are the other way around.

 

To make things worse when I look at the actual visualforce page in action, the labels correspond to the labels I expect and the values correspond to the values I expect. I got to the point to look at the execute anonymous because in a test method I am getting the wrong behaviour -i.e. the value and label are the other way around so the assertions fail. But they fail because the option value and label are the other way around.

 

Any ideas ?

 

Thanks,

Fernando

 

Hi All,

 

I am trying to insert folders as part of testing methods and I I get the following compile error: "DML not allowed on Folder" at the insert point.

 

I see the Folder object access includes "creatable".

 

Any ideas would be much appreciated.

 

Thanks,

Fernando

Hi All,

 

Do the test methods have to be written after a namespace has been defined ? If yes, then the test code is specific to the namespace and if I want to reuse the code in a new namespace I need to change all the references to the old one.

 

Let me give you an example of what I mean.

 

Say I am looking at the test code for a Visualforce/Controller. In the test method I need to set the page reference for the test and I need to create an instance of the controller. In both cases I need to prepend the namespace to the page and controller. For example, if my namespace is "abc" then this would lead to:

 

Test.setCurrentPage(Page.abc__MyPage);

 

abc__MyController cont = new abc__MyController();

 

So if I want to reuse the source code, including the test code in with a new namespace -i.e. in a new and different org, I need to change all the references to the namespace in the test code.

 

Is this the case ?

 

Thanks,

Fernando

Hi All,

 

In one of the test methods for a controller extension I am setting the page to the controller using:

 

Test.setCurrentPage(Page.existingOne);

 

Yesterday compiled all day. Today after the first compile I get a compile error: variable does not exist: Page.existingOne .

 

In addition, the line:

 

PageReference p = Page.existingOne;

 

does not compile either and gives the same compilation error.

 

The page existingOne.page exists in the org, and none of the pages has the word "page" in their name.

 

Any ideas ?

 

Thanks,

Fernando

Hi All,

 

Does the API version: 22 include new rules (strictness ?) when generating the pages that might affect the Javascript code ?

 

Using API version:19 I have a Visualforce page that has a button and when the user clicks on it:

- it calls a Javascript function. Whithin the function, it collects some data from the page (DOM) and creates a string wich is basically XML, and assigns this to a controller member (apex:inputText)

- goes back to the controller. In the controller it takes the XML in the momber updated in the page, and parses it.

 

This works fine with API version 19.

 

However, today I've changed the API version of all classes/components/pages via Eclipse from version 19 to version 22, the latest.

 

The same page know generates an exception which corresponds to a parsing exception within the controller. Looking closely, I've noticed that the XML generated in the Javascript  with API version 22 has the wrong mix of upper/lower cases.

 

For instance, if my XML is something like (just an empty element):

 

<MyXml></MyXml>

 

then when the page is with API version 22, the console shows the following:

 

<MyXml></myxml>

 

and this creates a parsing error in Apex and says that <MyXml> must be terminated by a </MyXml>.

 

I reverted back to API version 19 and it is all fine again.

 

Any ideas ?

 

Thanks,

Fernando

 

Hi All,

 

Is it possible to create a custom field of type integer in a custom object ?

 

Using the deploy() method with a zipped manifest I use for the custom field the following:

type: Number

 

The issue is that it fails (Metdata API failure) in the following cases:

- if I don't provide the precison

- if don't provide the scale

- if precison is not larger than scale.

 

So the net result is, when I provide precision and scale, it creates a field of type double always.

 

Any help would be much appreciated.

 

Regards,

Fernando

Hi All,

 

I am using the Metadata API to add custom fields to a custom object.

 

The custom fields created should be identical in terms of field type to existing standard or custom fields in other standard or custom objects. For instance, I need to create a custom field that is of the same type as the Account Shipping Street.

 

The Account.ShippingStreet in salesforce is of type: textarea and length 255

 

When using the Metadata API to create a custom field of the same type, the field created ends up being of type: string and length 255, instead of type textarea.

 

I am using the deploy() method of the Metadata API so I create the package.xml file on the fly and deploy it. The <type> element in the file is textarea, and the <length> is 255.

 

Any ideas what I am missing here would be much appreciated.

 

Fernando

 

 

 

 

Hi All,

 

I am using the Version: Summer '10 (19.0.0) of the Force.com IDE.

 

One of the projects, created a few months ago, includes the object files from salesforce.

 

Up until recentenly I could see the object file's content -i.e. the XML data.

 

Now if I refresh the object file from salesforce server, I only get :

 

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">

Is this associated with any of the new features ?

 

Thank you very much in advance.

 

Fernando

 

Hi All,

 

Is there any restriction in including a class in a managed (beta) package in executing anonymous ?

 

The situations is the following:

 

1. We have a dev org which we use to create the package. In that org we can execute anonumous code that references a class in the package.

2. The package is installed in a different org. The same execute anonymous code does not run. It complains it does not know the class that is in the package (the namespace has been pre-pended to the class name).

 

Thanks in advance.

Fernando

 

Hi All,

 

I would be most grateful for your views on what is the best approach here.

 

The scenario is as follows. I have a trigger that when fires it should update a large number of records of an object related to the one associated with the trigger.

The delicate bit here is that the number of related records is large, of the order of hundreds of thousands.

 

I am considering two approaches. One based on Batch Apex and the other based on @future call.

 

In the case of Batch Apex I would in the trigger kick a Batch Apex job using a query locator that fetches all the related records that need to be updated. In the Batch Apex implementation (execute method) I would then process the related records and update them.

 

In the approach using @future I would in the trigger collect the records of the object associated with the trigger,and pass them to an @future call. Within the @future call implementation I would fetch the related records with an SOQL for loop (so it does it in batches), loop over the related objects, process them and when done with the batch, update them.

 

In neither case I see running into issues with governor limits but I might be wrong.

 

Any views on what would be the best approach ?

 

Thank you very much in advance,

Fernando

 

Hi All,

 

I am experiencing a strange behaviour with a StandardSetController where calls to its methods getRecords() and getResultSize() are inconsistent. Moreover, this is a function of the StandardSetController page size.

 

More in detail now.

 

I have a Visualforce page with a custom controller. The page displays a table of items that are associated with a custom anonymous class defined in the controller.

 

Internally the controller uses a StandardSetController to manage a list of records from which I derive some of the information displayed in the page table.

 

From the UI pespective it is possible to change the page size i.e. how many records the table displays, and navigate through the results in the StandardSetController record set. Internally I use the StandardSetController methods setPageSize(), previous(), etc.

 

When the page size is set to 10, the query used to instantiate the StandardSetController gives 4 records. The StandardSetController

methods in turn give:

- getResultSize() --> 4 records

- getRecords() --> 3 records, so is missing one !

 

However, if the page size changes to 25 or something above, the StandardSetController methods give:

- getResultSize() --> 4 records

- getRecords() --> 4 records, so it is consistent

 

Has somebody seen this type of behaviour ?. 

 

Thanks very much in advance.

Fernando


Hi All,

 

While checking out a Force.com project from an SVN repository and creating a new project, the IDE notified me that the project was created with a version of the IDE prior to Summer 10, so the project had to be upgraded. I said yes.

 

The upgrade consited on changing the objects, layout, and profiles files. Specifically, the old object files with all the metadata content regarding fields, etc, where replaced by new files that only have the XML declaration and just one tag for the object name; all the data on fields etc. dissapeared.

 

Is this a new feature ?. Does this mean we can't see anymore the XML representation of objects ?

 

Thanks in advance !

Fernando

Hi All,

 

When deploying a single file/class from a dev org to a production org, does only the test code in that single file runs or the deployment of the single file kicks the test code for all classes in the production org ?.

 

Thank you very much in advance.

 

Fernando

Hi All,

 

I am dealing with an outbound call from salesforce to an external server that uses HTTPS/SSL.

I understand from the documenation that to be valid the certificate must be issued by a Certificate Authority trusted by Java 2 Platform,. 

 

CA certs cost money and I wonder if there a way to use a self-signed certtificate for testing purposes.

 

Thank you very much in advance.

Fernando

Hi All,

 

I am using a dev org to do the packaging. In this org the test coverage is over the required limit, and I managed to upload the package.

 

When trying to install the package I get a long series of errors during a package (managed-beta) installation, and all the failures share in common the they occur in test methods and are always same problem: System.QueryException: List has no rows for assignment to SObject.

 

The test methods where the installation fails share a common pattern. In each Apex class I have a static method initData where I intialize and insert the records required in the test methods. Then the test methods first of all call this initData() method, and then I fetch records.  For instance:

 

static void initData()

{

   MyObject__c obj = new MyObject__c(Name='Hello');

  insert obj;

}

 

static testmethod void test1()

{

  initData();

 List<MyObject__c> objs = [select Id, Name from MyObject__c where Name='Hello'];

 if(objs.size() > 0)

  {

    .......

  }

}

 

I believe the line in red is the one that is causing the exception System.QueryException: List has no rows for assignment to SObject during the installation of the package.

 

What I don't understand is why this fails during installation but doesn't fail during running of the test methods and package upload.

 

Any ideas ?

 

Thanks,

Fernando

 

 

Hi All,

 

I am seeing a substantial difference in the test coverage between the results in Eclipse and the results of Salesforce online UI.

 

Here is a concrete example. A controller class when running the test for it in Eclipse I get 99% coverage and only 3 lines are not covered.

 

On the other hand, when I run all test from Salesforce online UI (Setup | App Setup | Classes and using the Run All Test button) I get for the same class only 59% coverage. Moreover, if I click on this class and run the test for that class in Salesforce I still get 59%.

 

Has anybody seen something like this ?

 

Regards,

Fernando

Hi All,

 

The SelectOption connstructor is setting the value and label the other way around ?

 

Here is the output of an execute anonymous:

 

Anonymous execution was successful.

20.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO
Execute Anonymous: List<SelectOption> etOpts = new List<SelectOption>();
Execute Anonymous: etOpts.add(new SelectOption('value','label'));
Execute Anonymous: System.debug('options --> '+etOpts);
16:35:46.053 (53364000)|EXECUTION_STARTED
16:35:46.053 (53402000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
16:35:46.054 (54365000)|USER_DEBUG|[3]|DEBUG|options --> (System.SelectOption[value="label", label="value", disabled="false"])
16:35:46.941 (54452000)|CUMULATIVE_LIMIT_USAGE

 

The red line is where I construct the SelectOption following the manual : SelectOption option = new SelectOption(value, label, isDisabled);

 

However when I look at the list with the debug statement, the blue part,  they are the other way around.

 

To make things worse when I look at the actual visualforce page in action, the labels correspond to the labels I expect and the values correspond to the values I expect. I got to the point to look at the execute anonymous because in a test method I am getting the wrong behaviour -i.e. the value and label are the other way around so the assertions fail. But they fail because the option value and label are the other way around.

 

Any ideas ?

 

Thanks,

Fernando

 

Hi All,

 

I am trying to insert folders as part of testing methods and I I get the following compile error: "DML not allowed on Folder" at the insert point.

 

I see the Folder object access includes "creatable".

 

Any ideas would be much appreciated.

 

Thanks,

Fernando

Hi All,

 

Do the test methods have to be written after a namespace has been defined ? If yes, then the test code is specific to the namespace and if I want to reuse the code in a new namespace I need to change all the references to the old one.

 

Let me give you an example of what I mean.

 

Say I am looking at the test code for a Visualforce/Controller. In the test method I need to set the page reference for the test and I need to create an instance of the controller. In both cases I need to prepend the namespace to the page and controller. For example, if my namespace is "abc" then this would lead to:

 

Test.setCurrentPage(Page.abc__MyPage);

 

abc__MyController cont = new abc__MyController();

 

So if I want to reuse the source code, including the test code in with a new namespace -i.e. in a new and different org, I need to change all the references to the namespace in the test code.

 

Is this the case ?

 

Thanks,

Fernando

Hi All,

 

I am using the Metadata API to add custom fields to a custom object.

 

The custom fields created should be identical in terms of field type to existing standard or custom fields in other standard or custom objects. For instance, I need to create a custom field that is of the same type as the Account Shipping Street.

 

The Account.ShippingStreet in salesforce is of type: textarea and length 255

 

When using the Metadata API to create a custom field of the same type, the field created ends up being of type: string and length 255, instead of type textarea.

 

I am using the deploy() method of the Metadata API so I create the package.xml file on the fly and deploy it. The <type> element in the file is textarea, and the <length> is 255.

 

Any ideas what I am missing here would be much appreciated.

 

Fernando

 

 

 

 

Hi All,

 

I am using the Version: Summer '10 (19.0.0) of the Force.com IDE.

 

One of the projects, created a few months ago, includes the object files from salesforce.

 

Up until recentenly I could see the object file's content -i.e. the XML data.

 

Now if I refresh the object file from salesforce server, I only get :

 

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">

Is this associated with any of the new features ?

 

Thank you very much in advance.

 

Fernando

 

Hi All,

 

I am here below copying a paragraph from the Metadata API user guide that it is confusing me and I wonder if someone could shed some light.

 

You can modify metadata in test organizations on Developer Edition or sandbox, and then deploy tested changes to production organizations on Enterprise Edition or Unlimited Editions. You can also create scripts to populate a new organization with your custom objects, custom fields, and other components.

 

Does this means that the create(), update() and delete() calls of the Metadata API in a client running elsewhere outside salesforce would only work when calling a test/sandbox or developer orgs, and will not work for an Enterprise and Unlimited orgs ?.

 

Thank you very much in advance.