2015年12月24日 星期四

將Html Table匯出成Excel file


使用以下JavaScript

<script type="text/javascript">
function ExportToExcel(mytblId){
       var htmltable= document.getElementById('my-table-id');
       var html = htmltable.outerHTML;
       window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));
    }
</script>

參考網址:http://stackoverflow.com/questions/22317951/export-html-table-data-to-excel-using-javascript-jquery-is-not-working-properl

2015年12月15日 星期二

Date Functions in SOQL

This table lists all the date functions supported by SOQL.
Date FunctionDescriptionExamples
CALENDAR_MONTH()Returns a number representing the calendar month of a date field.
  • 1 for January
  • 12 for December
CALENDAR_QUARTER()Returns a number representing the calendar quarter of a date field.
  • 1 for January 1 through March 31
  • 2 for April 1 through June 30
  • 3 for July 1 through September 30
  • 4 for October 1 through December 31
CALENDAR_YEAR()Returns a number representing the calendar year of a date field.2009
DAY_IN_MONTH()Returns a number representing the day in the month of a date field.20 for February 20
DAY_IN_WEEK()Returns a number representing the day of the week for a date field.
  • 1 for Sunday
  • 7 for Saturday
DAY_IN_YEAR()Returns a number representing the day in the year for a date field.32 for February 1
DAY_ONLY()Returns a date representing the day portion of adateTime field.2009-09-22 for September 22, 2009
You can only useDAY_ONLY() with dateTime fields.
FISCAL_MONTH()Returns a number representing the fiscal month of a date field. This differs from CALENDAR_MONTH() if your organization uses a fiscal year that does not match the Gregorian calendar.
Note
This function is not supported if your organization has custom fiscal years enabled. See "About Fiscal Years" in the Salesforce Help.
If your fiscal year starts in March:
  • 1 for March
  • 12 for February
See “Set the Fiscal Year” in theSalesforce online help.
FISCAL_QUARTER()Returns a number representing the fiscal quarter of a date field. This differs from CALENDAR_QUARTER() if your organization uses a fiscal year that does not match the Gregorian calendar.
Note
This function is not supported if your organization has custom fiscal years enabled. See "About Fiscal Years" in the Salesforce Help.
If your fiscal year starts in July:
  • 1 for July 15
  • 4 for June 6
FISCAL_YEAR()Returns a number representing the fiscal year of a date field. This differs from CALENDAR_YEAR() if your organization uses a fiscal year that does not match the Gregorian calendar.
Note
This function is not supported if your organization has custom fiscal years enabled. See "About Fiscal Years" in the Salesforce Help.
2009
HOUR_IN_DAY()Returns a number representing the hour in the day for a dateTime field.18 for a time of 18:23:10
You can only useHOUR_IN_DAY() withdateTime fields.
WEEK_IN_MONTH()Returns a number representing the week in the month for a date field.2 for April 10
The first week is from the first through the seventh day of the month.
WEEK_IN_YEAR()Returns a number representing the week in the year for a date field.1 for January 3
The first week is from January 1 through January 7.


2015年12月11日 星期五

Formatting Time in APEX

Formatting Time in APEX

Here’s a table of format characters and what piece of the Date/Time object they display:
LetterDate or Time PieceExamples
GEraG = AD
yYearyy = 09, yyyy = 2009
MMonthMM = 08, MMM = Aug, MMMMM = August
wWeek in yearw = 35
WWeek in monthW = 3
DDay in yearD = 235
dDay in monthdd = 27
FDay of week in monthF = 2
EDay in weekE = Thu, EEEEE = Thursday
aAM/PMa = AM or PM
HHour in day (0-23)HH = 23
kHour in day (1-24)kk = 24
KHour in am/pm (0-11)KK=11
hHour in am/pm (1-12)hh = 12
mMinutes in hourmm = 30
sSecond in minutess = 55
SMillisecond in secondSSS = 888
zTime zonez = EDT, zzzzz = Eastern Daylight Time
ZTime zone offsetZ = -0400
So all that leaves to show is an example:
DateTime d = datetime.now();
timeStr = d.format(‘MMMMM dd, yyyy hh:mm:ss a’);

參考連結:https://paulforce.wordpress.com/2009/08/27/formatting-time-in-apex/

Formula 補充: https://help.salesforce.com/HTViewHelpDoc?id=formula_examples_dates.htm

2015年12月8日 星期二

Creating your very own Salesforce WAVE application

Creating your very own Salesforce WAVE application

在Apple Device上安裝Wave Analytics卻無法連線至develop org 可照以下作法開通
此網頁有基礎教學

參考網頁連結: Creating your very own Salesforce WAVE application



2015年11月18日 星期三

Validation Rule Formula Functions


判斷欄位是否被修改
ISCHANGED( field)

取得修改前value
PRIORVALUE(field)

判斷New Record
ISNEW()


參考連結 : Formula Operators and Functions
                         Validation Rule Not Running When Saving New Record
                     





2015年11月16日 星期一

Winter '16 Release - Overview and Highlights

Winter '16 Release - Overview and Highlights

除了Lightning大改版外...
中間有些東西還是挺期待的...
像是IDE終於有Debuger設定中斷點的功能,可以觀看即時value...以後不用在system.debug了 ..
Apex Code 也可以針對Approval Process設定Lock & UnLock也是方便了許多...

2015年11月13日 星期五

將數字轉為英文組合

將數字轉為英文組合

public with sharing class ext_NumberToWord {
static String[] to_19 = new string[]{ ' ', 'one',  'two', 'three', 'four',  'five',  'six',
    'seven', 'eight', 'nine', 'ten',  'eleven', 'twelve', 'thirteen',
    'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen' };
    static String[] tens = new string[]{ 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'};
    static String[] denom = new string[]{ '',
      'thousand',   'million',     'billion',    'trillion',    'quadrillion',
      'quintillion', 's!xtillion',   'septillion',  'octillion',   'nonillion',
      'decillion',  'undecillion',   'duodecillion', 'tredecillion',  'quattuordecillion',
      's!xdecillion', 'septendecillion', 'octodecillion', 'novemdecillion', 'vigintillion' };
    // convert a value < 100 to English.  
   public static String convert_nn(decimal input) {
      decimal Deci_val = input - integer.valueOf(input);
      integer val = integer.valueof(input);
      if(Deci_val == 0){
          if (val < 20)
            return to_19[val];
          if(val == 100)
              return 'One Hundred';
          for (integer v = 0; v < tens.size(); v++) {
            String dcap = tens[v];
            integer dval = 20 + 10 * v;
            if (dval + 10 > val) {
              if (Math.Mod(val,10) != 0)
                return dcap + ' ' + to_19[Math.Mod(val,10)];
              return dcap;
            }    
          }
      }
      else{
          string CENTS;
          if(integer.valueOf(Deci_val * 100)<20)
          {
              CENTS = to_19[integer.valueOf(Deci_val * 100)];
          }
          else
          {
              CENTS = tens[integer.valueOf(integer.valueOf(Deci_val * 100)/10)-2] + ' ' + to_19[Math.Mod(integer.valueOf(Deci_val * 100),10)];
          }
          if (val <= 10)
            return 'and ' + to_19[val] + ' and ' + CENTS + ' cents';
          if (val < 20)
            return to_19[val] + ' and ' + CENTS + ' cents';
          if(val == 100)
              return 'One Hundred'+ ' and ' + CENTS + ' cents';
          for (integer v = 0; v < tens.size(); v++) {
            String dcap = tens[v];
            integer dval = 20 + 10 * v;
            if (dval + 10 > val) {
              if (Math.Mod(val,10) != 0)
                return dcap + ' ' + to_19[Math.Mod(val,10)] + ' and ' + CENTS + ' cents';
              return dcap + ' and ' + CENTS + ' cents';
            }    
          }    
      }
      return 'Should never get here, less than 100 failure';
    }
    // convert a value < 1000 to english, special cased because it is the level that kicks  
    // off the < 100 special case. The rest are more general. This also allows you to
    // get strings in the form of "forty-five hundred" if called directly.
    public static String convert_nnn(decimal input) {
      decimal Deci_val = input - integer.valueOf(input);
      integer val = integer.valueof(input);
      String word = '';
      integer rem = val / 100;
      integer mod = Math.mod(val,100);
      if (rem > 0 && Deci_val == 0) {
        word = to_19[rem] + ' hundred';
        if (mod > 0) {
          word += ' ';
        }        
      }
      else if (rem > 0 && Deci_val != 0) {
        word = to_19[rem] + ' hundred';
        if (mod > 0) {
          word += ' ';
        }        
      }
     
      if (mod >= 0) {
        word += convert_nn(input - 100 * rem);
      }
      return word;
    }
    public static String english_number(decimal val) {
      if (val < 100) {
        return convert_nn(val);
      }
      if (val < 1000) {
        return convert_nnn(val);
      }
      for (integer v = 0; v < denom.size(); v++) {
        integer didx = v - 1;
        integer dval = (integer)Math.pow(1000, v);
        if (dval > val) {
          integer mod = (integer)Math.pow(1000, didx);
          integer l = (integer) val / mod;
          decimal r = val - (l * mod);
          String ret = convert_nnn(l) + ' ' + denom[didx];
          if (r > 0) {
            ret += ' ' + english_number(r);
          }
          return ret;
        }
      }
      return 'Should never get here, bottomed out in english_number';
    }
}