Friday, August 14, 2015

Breadcrumb in Gridbuddy

I just get to play around with Gridbuddy.While breaking an ice,I got requirement to create breadcrumb in Gridbuddy,I referring to this site and follow the instruction.But somehow I bumped to some errors and manage to fix it.So I would like to rewrite it here so I won't forget.

This is referring to Account breadcrumb because Account can have many children and grandchildren.

Account A  --> Account B -->Account 1
                   --->Account C -->Account 2
                   --->Account D 

So breakcrumb will be look like this Account A >> Account >> B >> Account 1

These are the steps:

  1. Create a number formula field to indicate hierarchy level at Account object.
  2. Create a text formula field to printout breadcrumb link
  3. Create a text formula field for Drill Up URL
  4. Add formula field to Gridbuddy field
  5. Create two actions at GridBuddy ; Drill Up and Drill Down.
  6. Add action to the Grid

Step 1:Create a number formula field to indicate hierarchy level at Account

Go to Setup >> Customize>>Account and create Custom Field with details below:
Data Type: Formula
Field Name :Hierarchy Level
Formula Return Type :Number
At Advanced Formula, paste this formula:

IF(!ISBLANK(ParentId), 2, 1)+

IF(AND(!ISBLANK(ParentId),!ISBLANK(Parent.ParentId)), 1, 0)+

IF(AND(!ISBLANK(ParentId), !ISBLANK(Parent.ParentId), !ISBLANK(Parent.Parent.ParentId )),1, 0)+

IF(AND(!ISBLANK(ParentId), !ISBLANK(Parent.ParentId), !ISBLANK(Parent.Parent.ParentId ), !ISBLANK(Parent.Parent.Parent.ParentId)), 1, 0)+

IF(AND(!ISBLANK(ParentId), !ISBLANK(Parent.ParentId), !ISBLANK(Parent.Parent.ParentId ), !ISBLANK(Parent.Parent.Parent.ParentId), !ISBLANK(Parent.Parent.Parent.Parent.ParentId)), 1, 0)+

IF(AND(!ISBLANK(ParentId), !ISBLANK(Parent.ParentId), !ISBLANK(Parent.Parent.ParentId), !ISBLANK(Parent.Parent.Parent.ParentId), !ISBLANK(Parent.Parent.Parent.Parent.ParentId), !ISBLANK(Parent.Parent.Parent.Parent.Parent.ParentId)), 1, 0)

Step 2:Create a text formula field to printout breadcrumb link

Go to Setup >> Customize>>Account and create Custom Field with details below:
Data Type: Formula
Field Name :Hierarchy Level
Formula Return Type :Text

At Advanced Formula, paste this formula:

CASE(Hierarchy_Level__c, 
1, "",

2, HYPERLINK("/apex/gblite__Grid?gname=Account+Hierarchy&fpf=ParentId&fpv=" + ParentId, Parent.Name,"_self") + " > ",

3, HYPERLINK("/apex/gblite__Grid?gname=Account+Hierarchy&fpf=ParentId&fpv=" + Parent.ParentId, Parent.Parent.Name,"_self") + " > " + 
HYPERLINK("/apex/gblite__Grid?gname=Account+Hierarchy&fpf=ParentId&fpv=" + ParentId, Parent.Name,"_self") + " > ",

HYPERLINK("/apex/gblite__Grid?gname=Account+Hierarchy&fpf=ParentId&fpv=" + Parent.Parent.ParentId, Parent.Parent.Parent.Name,"_self") + " > " + 
HYPERLINK("/apex/gblite__Grid?gname=Account+Hierarchy&fpf=ParentId&fpv=" + Parent.ParentId, Parent.Parent.Name,"_self") + " > " + 
HYPERLINK("/apex/gblite__Grid?gname=Account+Hierarchy&fpf=ParentId&fpv=" + ParentId, Parent.Name,"_self") + " > ") 

+ HYPERLINK("/apex/gblite__Grid?gname=Account+Hierarchy&fpf=ParentId&fpv=" + Id, Name, "_self")

Note:Account+Hierarchy actually is grid name Account Hierarchy.

Step 3 :Create a text formula field for Drill Up URL

Go to Setup >> Customize>>Account and create Custom Field with details below:
Data Type: Formula
Field Name :Parent Account URL
Formula Return Type :Text
At Advanced Formula, paste this formula:


'/apex/gblite__grid?gname=Account Hierarchy&fpf=Id&fpv=' + Parent.Id

Note:Account Hierarchy is a grid name.

Step 4 :Add formula field to Gridbuddy field

Go to Grid Wizard >> Manage Grid.If haven't create any grid yet, create new Grid named Account Hierarchy.If you want to apply breadcrumb to existing Grid, please ensure in previous steps replace Account Hierarchy with .

After Create or Select the grid, click Next.Select Hierarchy Link field from Parent Object and move it to Selected Fields as below.Then Save.


Step 5: Create two actions at GridBuddy (Drill Up and Drill Down)

In this step, we will create to Action which are Drill Up and Drill Down.
Click Manage Action>>New to create new Action.Below are the details to create the Actions

Drill Up Action


Drill Down Action


Note:Content is Account Hierarchy&fpf=ParentId . Replace Account Hierarchy with your grid name if you use different name.

Step 6 : Add action to the Grid

After Save, you can click Manage Grid to go back to the grid.Select your grid name and Click Next.Scroll down to the bottom until you find Select Action.


Check on Drill Down and Drill Up and Save.So now you can Launch Grid.But for my case,because I embed this grid inside Visualforce.So this is my view.


This entry is adapted from Create breadcrumb with formula field

Monday, August 10, 2015

Salesforce Date format conversion

I want to change the format of Date field to M/dd/YYYY so it will be read as 07/30/2014.

The field is Date datatype not Datetime datatype.

Note:
1) In Date class there only format() method that will change the date format using locale.
format()
Returns the Date as a string using the locale of the context user
2) Only in DateTime class offer various of date formatting method.
format()
Converts the date to the local time zone and returns the converted date as a formatted string using the locale of the context user. If the time zone cannot be determined, GMT is used.

format(dateFormatString)
Converts the date to the local time zone and returns the converted date as a string using the supplied Java simple date format. If the time zone cannot be determined, GMT is used.

format(dateFormatString, timezone)
Converts the date to the specified time zone and returns the converted date as a string using the supplied Java simple date format. If the supplied time zone is not in the correct format, GMT is used.

formatGmt(dateFormatString)
Returns a Datetime as a string using the supplied Java simple date format and the GMT time zone.

formatLong()
Converts the date to the local time zone and returns the converted date in long date format.

Let say the existing value is from Date datatype, how we can format it.I want the format to be M/dd/yyyy so it return some like this 08/31/2015.

Note based on the code below, we need to convert our Date value to DateTime value using newInstance method like below:


 Date d = myObject__c.Meeting_Date__c;
 Datetime dt=DateTime.newInstance(d.year(), d.month(), d.day());
 reportDate = dt.format('M/dd/yyyy');

Monday, August 03, 2015

Posting code in WP

Just trying to  post my apex code in WP.

1)Using Gist. Just copy the Gist URL into your WP post.Done.Look nice , but if you delete your file in Gist,the code in post also will be gone which I less prefer.Maybe will use it if I decide not to delete my file in Gist.

 2) Using code based on Posting source code. Because this is from SyntaxHighlighter,it offered quite sophisticated features,but unfortunately I found it not able to remove the scroll bar.It got some solutions but only apply for WordPress.org only.But it nice, maybe for longer and complex code I can use this.

 [code language="java" padlinenumbers="true" highlight="1"] public Map<Id,MyAgenda__c> getAgendaMap(){ agendaMap = new Map<Id,MyAgenda__c>([SELECT Id FROM MyAgenda__c WHERE Id=: this.stdController.getId() ORDER BY Date__c DESC]); return agendaMap; } [/code]

 3)Using hilite.me It look nice for simple and shorter code.
public Map<Id,MyAgenda__c>  getAgendaMap(){
        agendaMap = new Map<Id,MyAgenda__c>([SELECT Id FROM MyAgenda__c WHERE Id=: this.stdController.getId() ORDER BY Date__c DESC]);
        return agendaMap;
    }   
So for free WP user, what tool do you use to post your code?Just note that I am Salesforce developer,so I code with Apex.

In Blogger last time I used Syntaxhighlighter, but now I found out hilite.me also quite convenient.

Note:This is copied from my other blog in wordpress.