Tuesday, December 01, 2015

Removing RecordType from Profile using Metadata

I thought that this is going to be my worst experiment ever!!I should not done this especially when I have other important task to do.

I tried to figure out how to embed inline visualforce in Page Layout for Standard Edit, so I creating RecordType and hope it will help.But it won't;there seem no choice to embed inline visualforce based on the Answer here.

Anyway,back to accident RecordType.I am not able to delete it because it prompt me to deactivate it first.Again when I tried to deactivate it,it prompt error because it said it being used by these profiles.

This record type Common Component cannot be deactivated because the following profiles use this record type as default.

These profiles are more that 200(Actually to be exact 243).How I am going to navigate each profiles through browser and change the setting--it's going to take me forever.

*just normal office chat*

After few tries,it works.Nah,here the metadata that I append in my package.xml .So as you can see , I retrieved all.
<types>
   <members>*</members>
   <name>Profile</name>
</types>
<types>
  <members>*</members>
  <name>RecordType</name>
</types>
*Note:You can select recordtype specific of the object that you want to choose by putting it .

The reason to only retrieve the specific recordtype is to avoid any unnecessary error that might related to  other recordtype.Well,based on my experience :messing with recordtype is not fun.


    <recordTypeVisibilities>
        <default>false</default>
        <recordType>RM_Common_Components__c.Common_Component</recordType>
        <visible>false</visible>
    </recordTypeVisibilities>
Change default true to false and visibility true to false as code above.Copy paste it to every Profile that you want to change.Then commit to server.

You can see it change in the Salesforce like below:


After this,I am positively can deactivate and delete the record type easily

Thursday, October 22, 2015

Reading JSON file in GitHub from JSFiddle

I am experimenting with HighChart, digging out the code.I create sample JSON  resided in GitHub.Then in JSFiddle, I use Raw url to read JSON file,but it does not work and prompt me this error.

Uncaught SecurityError: Blocked a frame with origin "xxxx" from accessing a frame with origin "http://jsfiddle.net". Protocols, domains, and ports must match.

Then I googling and found out that we can paste Github URL at http://rawgit.com/ ,so it will generate url that accessible.

Wednesday, October 07, 2015

Help Text oh Help Text

I am quite piss off for few day.I have standard page layout that already fulfill the requirement except :
I want explanation in the form that also hyperlink point to  complete guideline URL on certain field. 

This is pieces of cake but I could not find it doable in Salesforce.I just need to put some instruction something like bleh bleh bleh please click here.

But it is not supported in Salesforce,even static text also not doable in Pagelayout. So I have to go for customize instead of using standard just because of one field requirement.

Try to put hyperlink either using a href or hyperlink() == FAIL


Please vote the idea here:
Help Text with hyperlink
Also it is good if we can have static text embedded in Page Layout : Allow Text Labels within Section columns on page layouts

Because of this lackness, there appexchange developed just to support this Improved Help , which I am not sure what is it doing.Maybe will explore later.

Friday, September 11, 2015

Implementation restriction: TopicAssignment only allows security evaluation for non-admin users when either (1) LIMIT is specified and at most 1000 or (2) WHERE is specified and filter on Id or Entity

The error of today

Implementation restriction: TopicAssignment only allows security evaluation for non-admin users when either (1) LIMIT is specified and at most 1000
or (2) WHERE is specified and filter on Id or Entity

Rootcause:Query to TopicAssignment  no limit clause.

List<TopicAssignment> topicAssigList = new List<TopicAssignment>([SELECT EntityId,TopicId FROM TopicAssignment]);


No SOQL limit if logged-in user has “View All Data” permission. If not, do one of the following:
Specify a LIMIT clause of 1,100 records or fewer.
Filter on Id or Entity when using a WHERE clause with "=".
If there no Where clause, then just include the LIMIT
List<TopicAssignment> topicAssigList = new List<TopicAssignment>([SELECT EntityId,TopicId FROM TopicAssignment LIMIT 1000]);
TopicAssignment

Tuesday, September 01, 2015

Lightning Quickstart

The quick tutorial can be found here : Lightning Quick Start (PDF)

Error that you might face:

FIELD_INTEGRITY_EXCEPTION

Note that your code is something like this


<aura:application >
     <jam:hello />
</aura:application>
Note jam is namespace.In my case my namespace is unid.Replace jam with unid.

After that click Preview, you may get URL No Longer Exist--I close my browser and reopen it.It works fine.

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.

Friday, July 31, 2015

Deploy salesforce component using ANT

*damnn... I missed one html tag , it prompt error then I click undo all my entries gone.blogger autosave seem not working.i have no luck.this is my third time entry*

Why you need this?


Imagine that you want to move many new component that not yet exist in the other sandbox.Instead of creating component one by one ,it is better to use ANT.But if the component is already exist in the target sandbox,it is advisable to have backup.Because you might overwrite other people code in target sandbox.

Steps:(green color only apply for one time)

1. Install JAVA
2. Install ANT
3. Setup environment variables (PATH etc)
4. Download Force.com Migration Tool by go to Setup -> Develop ->Tools
5. Unzip the downloaded folder.Inside the folder contains directory/file such as:
sample  > codepkg,mypkg,removecodepkg,unpackaged,build.properties,build.xml.
ant-salesforce.jar
Readme.html

6. Copy the component that you want to deploy into codepkg folder.

7. Open sample folder and update build.properties with your salesforce  username,password and URL(either sandbox/production)
8. I don't want to run test because I just want to deploy in sandbox.So I update build.xml at deployCode portion,in sf:deploy tag with runalltests="false" ,so it will skip the test method execution.


 <target name="deployCode">
      <!-- Upload the contents of the "codepkg" directory, running the tests for just 1 class -->
      <sf:deploy username="${sf.username}" password="${sf.password}"  runalltests="false" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="codepkg">
      </sf:deploy>
 </target>
9. Open command window.Short click Run and Type cmd .
10. Make sure your command point in sample directory by using command : cd sample
11. Then just type : ant deployCode . I got message as below.

deployCode:
[sf:deploy] Request for a deploy submitted successfully.
[sf:deploy] Request ID for the current deploy task: 0Afn0000003IcQeCAK
[sf:deploy] Waiting for server to finish processing the request...
.
.
.
BUILD FAILED
C:\salesforce_ant_30.0\sample\build.xml:54: Failed to obtain result from server
within specified time of 200sec.
Execute following command to obtain the results later: ant deployCode -Dsf.as
yncRequestId=0Afn0000003IcQeCAK

Because it failed to status,I paste at command window
ant deployCode -Dsf.asyncRequestId=0Afn0000003IcQeCAK

deployCode:
[sf:deploy] Checking the results from server for request ID=0Afn0000003IcQeCAK
[sf:deploy] Waiting for server to finish processing the request...
[sf:deploy] Request Status: Succeeded
[sf:deploy] *********** DEPLOYMENT SUCCEEDED ***********
[sf:deploy] Finished request 0Afn0000003IcQeCAK successfully.

So it pass.

References:
https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/forcemigrationtool_install.htm
https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/meta_development.htm

Salesforce Recycle Bin


No shortcut to find Recycle Bin.
Replace highlighted  instance with your instance.

https://my_instance/search/UndeletePage

*Deleted objects also can be found in Setup -->Create -->Objects.Scroll to the bottom of the page.