Wednesday, January 27, 2016

Salesforce - working with large paging sets greater then 2000


The Use Case : You have a visual force page/s that need to display large amounts of data, possible hundreds of thousands of records.

The Problem : SOQL limits and other force.com limits would prevent you from return large amounts of data to a page in one hit.

The Solution : To solve this problem we can make remote calls either synchronously or asynchronously to return the data in smaller chucks. This can be achieved by ensuring the following:

  •  passing your remote method the id of the last record in the last retrieved record set and using that as the starting point to retrieve the next set of records in your where clause.
  • Order the records by Id
  • Setting a limit of the number of records that are returned.


eg

@RemoteAction @ReadOnly
    public static List GetCostDistLines(String projectId, Id offsetId) // projectNum)
    {

        String offsetIdSearch = (offsetId==null)?'0':offsetId;

        return [select id
//, GLDate__c
                //, GLPeriodName__c
                , PADate__c
                , PAPeriodName__c
                , ExpenditureItem__r.Quantity__c
                , Name
                , ExpenditureItem__r.PersonId__c
                , ExpenditureItem__r.ExpenditureType__c, ExpenditureItem__r.Name
                , ExpenditureItem__r.VendorId__c
                , ExpenditureItem__r.UOM__c
                , ExpenditureItem__r.ProjectTask__r.Name
                , ExpenditureItem__r.ProjectTask__r.ProjectTaskNumber__c
                , ExpenditureItem__r.ProjectTask__r.Id
                from CostDistLine__c
                //where ExpenditureItem__r.ProjectTask__r.ProjectNumber__c = :projectNum];
                where ExpenditureItem__r.ProjectTask__r.pse__Project__r.Id = :projectId and
                Id > :offsetIdSearch ORDER BY Id ASC LIMIT 10000];
    }

Tuesday, October 20, 2015

Fix Visualforce Sidebar and Header when using Bootstrap

The Problem

When using Bootstrap on a visualforce page with a sidebar and header showing you will undoubtedly notice that the styling of the sidebar and header will have changed to something rather undesirable. This is because Bootstrap is overriding some of the salesforce styling like the body text size. See the difference below, the left side is the undesirable bootstrap version.


Thankfully there is a way around this issue though it will involve compiling your own version of Bootstrap to use your own custom namespace.

Prerequisites  

There are a few thing you will need for this exercise: 
  • download the Bootstrap source code - you can get this from the bootstrap download page 
  • node.js - You will need to download and install node.js to get and run grunt.
  • Grunt - Grunt is what you need to build/compile and test Bootstrap. To install grunt globally from the node.js command line run the following npm install -g grunt-cli.

Now What

Now that we have bootstrap, node.js and grunt we can alter bootstrap to include a custom namespace so that our visualforce paged can differentiate between when/where to use salesforce css and when/where to use bootstrap css.

Follow the following steps:
  • In node.js command line  navigate to the root /bootstrap/ directory, then run npm install. npm will look at the package.json file and automatically install the necessary local dependencies listed there
  • From the bootstrap source open /less/bootstrap.less
  • wrap the contents of /less/bootstrap.less in a class like .bs{}
eg
  • still in node.js command line and root /bootstrap/ directory run grunt or grunt dist. This  will regenerate the /dist/ directory
  • Zip the contents of  the /dist/ directory and upload to the salesforce static resources.
  • Now you can wrap only the content you want affected by bootstrap style in a tag with a bs class like below.

Friday, October 16, 2015

Using Telerik kendo ui charts in salesforce

Salesforces provides a wide range of reporting and charting capabilities out-of-the-box like Salesforce1 / Lightning Reports and Dashboards for business users and Visaulforce Charts for developers that provide useful tooling in a wide of business cases. For the situations where you find salesforce just can provide what you need  OOB you can fall back on an alternative chart library such as google charts, highcharts, jscharts etc.... to extend salesforces already probabilities. In this case i'm going to show how to use 'Telerik Kendo UI' to extend your charting needs to build a multi axis double line / double bar chart like the following.



Friday, August 9, 2013

SQL Server - Executing Very long querys from a string

We have been linking out SQL servers to oracle lately as a mean of working around a particular issue which I will not go into. We have been needing to run oracle query from the linked server by wrapping the oracle queries in a string then using the 'EXECUTE (@query) AT [LINKED SERVER NAME'.

If the oracle query is less then 4000 characters the following would work:

declare @query as nvarchar(max)  =  '[a smaller then 4000 char oracle SQL] ' + '[Some more parts of the statement]'
EXECUTE (@query) AT [LINKEDSERVER]

Now as soon as the SQL statement is larger then 4000 characters you will begin to see errors when executing the statements. This is because when we concatenated the two strings in the above statement they concatenate into nvarchar(4000) in stead of nvarchar(max). To work around this issue cast all stings into nvarchar(max):

declare @query as nvarchar(max) = CAST('some sql' as nvarchar(max)) + CAST('some other sql' as nvarchar(max))
EXECUTE (@query) AT [LINKEDSERVER]
 

VoilĂ , we can now run excessively long queries from a string using EXECUTE.

Sunday, September 9, 2012

Copy SharePoint Designer workflow 2010



I think of SharePoint designer workflow as more of a end user tool rather then a developer tool, for something a bit more helpful for developers look at K2 or Nintex.  Thou if you need to update a production SharePoint designer workflow here are the steps that would recommend to making the changes off line on a development environment and deploying to production or test.




  1. Do a Database content migration of the  site collection that contain your workflow to you dev environment. Doing this will ensure all of the GUID's in the background are the exact same a production.
  2. Update your workflow and associated infopath form (if any) in Dev
  3. Now, before moving  to your test or prod environment I would highly recommend backing up you SharePoint area that we are updating as a just in case precaution.
  4. Publish your infopath form to production site.
  5. Open dev SharePoint and prod SharePoint in SharePoint designer and copy your workflows  .XOML and .XOML.RULES  files from dev to prod.
  6. Close and reopen the prod SharePoint designer. This forces the designer to pick up the new changes. I find with out this step SharePoint designer shows the old workflow.
  7. Open the workflow and validate that there are no missing action data.
  8. Publish the workflow 
Hey presto,

Wednesday, September 5, 2012

WSP Deployment stuck in "Deploying" state

While updating a wsp package in  noticed the package was stuck in "deploying" state for a few hours. Think this was a little to long i ran the follow command:

 stsadm -o execadmsvcjobs

Its now as happy as Larry

Friday, August 24, 2012

Lightswitch and Left Outer Join


                

Ever needed to do a left outer join in a lightswitch App using linq? Yes, well its pretty simple. Just add  .DefaultIfEmpty() to any join object that requires the left outer.



query = from pp in query
   from pbl in pp.ProjectBusinessLines.DefaultIfEmpty()
   from s in pbl.ProjectBusinessLineServices.DefaultIfEmpty()
   where pp.ProjectSummary.Contains(KeyWordSearch)
   || pp.CompanyName.Contains(KeyWordSearch)
   || pp.ProjectName.Contains(KeyWordSearch)
   || pbl.OurRole.Contains(KeyWordSearch)
   || pp.Location.Contains(KeyWordSearch)
   || s.Service.ServiceName.Contains(KeyWordSearch)  
   select pp;