Skip to main content

Posts

Showing posts from November, 2013

ReadOnly Annotation

Use Case:- You want to show up to 10000 record on single VF page. Count of records based upon some business requirement where number of records could go up to 1 million. So far, it was not possible to achieve above in VF page because of following limitations:- The maximum number of items in a collection that can be iterated over using components such as <apex:dataTable> , <apex:dataList> , and <apex:repeat> is 1000. Normally, queries for a single Visualforce page request may not retrieve more than 50,000 rows. Solution:- But with API version 23.0 , salesforce has introduced ' ReadOnly ' annotation which has following functionality/restriction:- The @ReadOnly annotation allows you to perform unrestricted queries against the Force.comdatabase. All other limits still apply. It's important to note that this annotation, while removing the limit of the number of returned rows for a request, blocks you from performing the following operations

Error: Function ISNEW may not be used in this type of formula

Today while creating a workflow rule, I wanted to use ISNEW() function to check whether a record has been created or updated. The evaluation criteria I had selected was " created, and any time it’s edited to subsequently meet criteria ". When I clicked on 'Check Syntax' button, it threw error " Error: Function ISNEW may not be used in this type of formula ". I was under impression that it should be available to all criteria, but ' created '. After checking docs, I found that we can use ' ISNEW() ' function only with evaluation criteria " created, and every time it’s edited " and it can't be used with evaluation criteria " created " & " created, and any time it’s edited to subsequently meet criteria ".  Be careful before deciding upon selection of " Evaluation Criteria " and use of function within!

New Objects in API Version 29.0

Today, while working on Event object, I recognized that we can add more than one Lead/Contact to an event using 'Add to Invitees' link. My curiosity to understand how it is being stored in DB took me to ' EventRelation ' & ' UndecidedEventRelation ' objects. I suspected there are many more and it leads me to Winter'14 release doc and I found whole set of new objects in API Version 29.0 These objects are new in API version 29.0. The AcceptedEventRelation object represents invitees with the status Accepted for a given event. The AccountCleanInfo object stores the metadata Data.com Clean uses to determine an account record’s clean status. The AllowedEmailDomain object represents an allowed email domain for users in your organization. The AppMenuItem object represents an item in the app picker, exposing metadata for tab sets, service providers, and Connected Apps. The AttachedContentDocument object contains all ContentDocument objects associat

Bulkify Apex Methods - Using Collections in methods

I am working on an app which we plan to publish on app exchange. As per pre-requisite requirement by salesforce, any app before getting listed on app exchange should go through code review from checkmarx. To comply with this, we submitted our code base to checkmarx. We were surprised to see one of problem reported by checkmarx. The error says " Bulkify Apex Methods - Using Collections in methods ". Code snippet in question is (I have to hide my business logic :) ):- List<Account> lstAccount = new List<Account>(); Integer i = 0; for(Account acct : [Select Id, Name from Account]){ lstAccount.add(acct.Name = 'Test Account' + i); i++; } if(lstAccount.size() > 0) update lstAccount; I was wondering what is wrong with this, as it seems perfect. I went to http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_loops_for_SOQL.htm to understand 'SOQL for Loop Formats'. As per this url, the summary says:- SOQ

Could not run tests on class - Solution

Today while writing a test class, there was some code related bug. After debugging I spotted and fixed it. However, when I tried to run test it gave me strange error saying something like:- Error: Could not run tests on class 01pK00000007EWE As per my blog http://sfdc-know-how.blogspot.in/2013/11/could-not-run-tests-solution.html, I cross checked if 'Disable Parallel Apex Testing' is checked and found that its already unchecked. Next step was to 'Clear Test Results'. After clearing the test results, I did 'Run Test' on my test class and guess what, it executed like charm. Another weird behavior because of Winter'14 release.

Limit Info Header - Possible bug with Chatter REST API

With Winter'14 release, Salesforce has introduced 'Limit Info Header'. The Limit Info header is a response header that’s returned from each call to the REST API. This header returns limit information for the organization. Use this header to monitor your API limits as you make calls against the organization. Same is also available with SOAP API. I was very excited to see this. The very common use case I can think of is to access this header value and decide if we want to show end user some graceful message in case they have exhausted all available number of API calls. I tested it straight away with a simple call get detail of account object as shown in below figure. I was happy to see desired value of 'api-usage' in header. However, when I tried the same on chatter REST API, I couldn't find 'sforce-Limit-Info' field in response header as shown in below figure. Possible salesforce bug!

User Sharing - Winter14 Release

Today, while working on one of our client's organization there was a requirement to get the detail of Owner of a collaboration group. We couldn't use Salesforce UI to get and look into CollaborationGroup because of some reason. I used ID of CollaborationGroup to make a query and get OwnerId field's value. OwnerId was that of a user, since it was starting with '005'. When I run a query on User to get detail of this user, I was surprised that query returned 0 records. I was puzzled, since CollaborationGroup has a user as owner, but query is not returning me detail of this user. After much of exploration, I realised that it is because of one of feature released in Winter14 ' User Sharing '. Following is detail of what it is:- Control who sees who in the organization with standard sharing functionality. User Sharing enables you to show or hide an internal or external user from another user in your organization. Previously, User Sharing for exte
' Push Upgrades ' is a nice feature for Creating & Uploading Patches to customers organization easily. However, there is best practices around this suggested by salesforce which is listed on https://help.salesforce.com/HTViewHelpDoc?id=push_patch_best_practices.htm&language=en_US. However, apart from above best practices, there could be scenario, where you might have created a new component say trigger or class. Now, when you create a new version of package and push it to customers organization there are highly likely chances that your customer forget to add access of these new component(s) to desired profiles (except system administrator, since they will get access automatically).  In case of manually updating package on customer's organization, they get an option where they are asked to who all you want to give access and then admin can make decision. Tip - In case you are using 'Push Upgrade' and if new release is going to have new component, pleas

Batch Job - First error: Future method cannot be called from a future or batch method

Today while working on one of requirement, where we need to schedule a job after every fixed interval of time. During unit testing we found our job stuck. Initially we thought, it may be because of non-availability of resources, since scheduled jobs get queued if resources are not available and runs as soon as resource is free. After waiting for 30 mins, we went to Setup >> Jobs >> Apex Jobs to see what is status of Batch Apex. We found that 'Scheduled Apex' i.e. scheduler was in ' Queued ', while the ' Batch Apex ' i.e. batch was in ' Failed ' status. It was causing job to stay stuck. First error: Future method cannot be called from a future or batch method We need to be careful against such scenario. We may think that our job is running properly, whereas it may be in stuck status because of exception. We need to do follow to avoid such issue:- 1. Properly unit test job, with all possible use case and mass data. Don't test only f

Issue with All Topic Records SystemModStamp field update

We have number of Topic records in one of org created in span of last 2 months. However, we have noticed that if we assign a topic to some FeedItem, it causes SystemModStamp field of all Topic records of org get updated with current datetime value. Our assumption is that, SystemModStamp of only assigned Topic's record should be updated. Looks like potential BUG ! Following with SFDC, will keep you all updated.

Error: Compile Error: Schedulable class has jobs pending or in progress

Today, while working on one of class, when I tried to save my changes I got following error:- Error: Compile Error: Schedulable class has jobs pending or in progress at line 5 column 21 I thought, its coming because there may be some job is running or scheduled. However, when I checked Setup >> Build >> Jobs >> Scheduled Jobs , I couldn't find any scheduled job. Just to be sure that there is not any apex job in running status I checked Setup >> Build >> Jobs >> Apex Jobs . And there were not any job in running status.  Just to be clear, Apex Jobs were listed in descending order of Submitted Date . I just checked first few of Apex Jobs. They were either in Aborted or Completed status. I was wondering what's wrong. After further analysis, I decided to check Setup >> Build >> Jobs >> Apex Jobs in more detail. After scanning status of all Apex Jobs, I found one job which was still in ' Queued ' status. And i

Could not run tests - Solution

Today I have written a test class, having only one test method into it. When I ran the test class to check for code coverage, I got a very strange error saying "could not run tests on <Id of test class>". Whereas it was showing that the test method run successfully with desired result in terms of code coverage. I further tried to update the test class and it again gave very strange error "java.lang.reflect.InvocationTargetException".  Initially I thought there is something wrong with my class and cross checked for syntax, identifier etc. After making sure that there is nothing wrong with class, I went to see if anyone faced same issue before. I found actually quite a few and below is solution to get rid of this:- Go to App Setup >> Develop >> Apex Test Execution and click on "Options". Uncheck 'Disable Parallel Apex Testing' and click on Ok. Go to App Setup >> Develop >> Apex Test Execution and click on "