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';
    }
}

2015年11月12日 星期四

Salesforce VF 轉出Excel 時,避免欄位值因儲存格格式被修改


轉出Excel時,欄位值常因儲存格格式而被修改
此時可於前後加上&nbsp;便可避免此情形

Try to insert html blanks to the start and end of the string:
<apex:column headerValue="Account Number">                   
    <apex:outputText value="&nbsp;{!mt.Account_Number__c}&nbsp;" escape="false"/>
</apex:column>

 參考網址: Visualforce to Excel: Prevent long number from being displayed in Scientific Notation

2015年11月11日 星期三

取得網頁上表格Table內容[JQuery]

使用JQuery取得網頁內Table的資料

function RunJob(){
    var TableData = getTableData($('#GridName'));
}
             
function getTableData(table) {
    var data = [];
    table.find('tr').each(function (rowIndex, r) {
        var cols = [];
        $(this).find('th,td').each(function (colIndex, c) {
            cols.push(c.textContent);
        });
        data.push(cols);
    });
    return data;
}


參考網頁

2015年11月9日 星期一

取得SObject所有欄位,用以組建SOQL字串

組建SOQL時常需要自行輸入欄位名稱,欄位一多就會耗費許多時間,
以下function可一次取出所有欄位組成SOQL字串
傳入SOject Name可取得所有欄位名稱 (以逗點隔開)


 public getQuote(){
        string SOQL = 'select ' + GetAllField('Quote') + ' from Quote ';
        list<Quote> QuoteList = Database.query(SOQL);
 }

public string GetAllField(string sfo){
        map<string, schema.sobjecttype> allSObjects = schema.getglobaldescribe();
        schema.sobjecttype q = allsobjects.get(sfo);
        schema.describesobjectresult d = q.getdescribe();
        map<string, schema.sobjectfield> m = d.fields.getmap();
        set<string> s = m.keyset();
        string query = '';
        for(string f : s){
            query = query+f+', ';
        }
        query = query.substring(0,query.length()-2);
        return query;     
    }

於Amazon安裝Magento說明

Amazon安裝Magento說明

1          申請&安裝設定Amazon
Amazon基本安裝&SSH連線設定請參照以下網頁:
PS.申請Instance時請申請Amazon Linux,此版本會預先裝好基本套件

2          設定Server環境 & 安裝套件
照以下步驟可完成LAMP環境安裝
http://docs.aws.amazon.com/zh_cn/AWSEC2/latest/UserGuide/install-LAMP.html
PS.
安裝後需自行安裝PHP56相關套件不然會出現錯誤
2.1         phpmyadmin安裝需要用到此套件php56-mbstring
yum install php56-mbstring
2.2         Magento安裝需要用到套件php56-mcrypt, php56-gd
sudo yum install php56-mcrypt
sudo yum install php56-gd

3          安裝phpmyadmin來管理MySQL
請依照以下網頁步驟安裝即可
http://40era.com/1523/
PS.
最新版本請至以下網頁複製連結下載
https://www.phpmyadmin.net/

4          安裝FTP Server , 請參照以下網頁處理
http://stackoverflow.com/questions/7052875/setting-up-ftp-on-amazon-cloud-server

5          安裝Magento
5.1         開啟phpmyadmin,新增空白DB (在此為magento)
5.2         準備magento安裝
5.2.2   解壓(會產生一個magento資料夾)
tar -zxvf magento-1.9.1.0.tar.gz
5.3         安裝sample資料
5.3.1   下載頁面,因安裝為1.9版故請下載1.9版適用Sample Data
http://devdocs.magento.com/guides/m1x/ce18-ee113/ht_magento-ce-sample.data.html
5.4         開始安裝magento,安裝說明請參照以下網頁
http://devdocs.magento.com/guides/m1x/install/installing_install.html#install-magento
PS.
安裝完網頁出現404無法瀏覽,請依照以下網頁處理
http://www.learnmagento.org/magento-tips-tricks/404-error-after-sample-data-installation-in-localhost/
PS.
安裝前須先修改所有資料夾權限為rwx
sudo find magento -exec chmod a+rwx {} ";"

2015年11月8日 星期日

Salesforce VF PDF Configuration

建立PDF相關設定

*Repeat Header
*Repeat Footer
*Page Counter
*WaterMark
*Repeat Grid Header & Footer
*Force to Break Page
*To avoid the 2nd page shift up

<apex:page showHeader="false" sidebar="false"  renderAs="PDF" standardStylesheets="false" applyBodyTag="false"
    standardController="Quote" extensions="ext_CustomQuotationPDF">
    <head>
<style type="text/css"  media="print">      
           @page {                                                     
               @top-center {                   
                   content: element(header);    
               }
           @bottom-left {
                   content: element(footer);
               }

               size: 210mm 297mm;
               margin: 15mm;
               margin-right:0mm;
             
               margin-top: 4.215cm;
               margin-bottom: 2.80cm;
               margin-left: 1.27cm;
               margin-right:1cm;
                     
           }                              

           div.header {                
                       padding: 10px;              
                       position: running(header);
                              
                       height: 50px;
                       margin-bottom: 5px;
                               
           }        
           div.footer {                
               display: block;             
               padding: 5px;               
               position: running(footer);  
               
               clear: both;
               margin-top: 15px;
                       
           }              
         
           .pagenumber:before {                
               content: counter(page);             
           }                       
           .pagecount:before {             
               content: counter(pages);            
           }                
         
           .labelcls
           {
               margin-left:400px; font-size:25px; font-weight:bold;
         
           }
         
           table {-fs-table-paginate: paginate;}
         
</style>
    </head>
    <body>
<div class="header" width="100%">
                       Header Contents
        </div> 
   
    <div class="footer" style="font-size:16px;">
         Footer Contents      
         <center>
             Page <span class="pagenumber"/> of <span class="pagecount"/>
         </center>
    </div>


    <img src="{!URLFOR($Resource.WaterMark)}" width="100%" height="100%" 
     style="position: fixed;background-repeat:repeat;left: 0cm; top:0cm; z-index:-1"/>

    <apex:variable var="PageNum" value="{!1}"/>
    <apex:outputPanel layout="block" style="height:30px;" rendered="{!PageNum > 1}"/>
    <table>
        <thead>
        <tr>
          <th>ITEM</th>
          <th>DESCRIPTION</th>
          <th>QTY</th>
          <th>STANDARD UNIT PRICE</th>
          <th>EXTENDED PRICE</th>
        </tr>
      </thead>
<tfoot>
          <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
          </tr>
</tfoot>
<tbody>
<apex:repeat value="{!CustQuoteItem}" var="line">
   <tr>
   <th></th>
   <th></th>
   <th></th>
   <th></th>
   <th></th>
   </tr>
       <apex:variable var="PageNum" value="{!PageNum+1}"/>
</apex:repeat>
</tbody>
</table>

<div style="page-break-before: always">&nbsp;</div>


2015年11月5日 星期四

使用IDE工具複製Object - How to Clone an Object In Salesforce

Salesforce使用IDE工具複製Object

How to Clone an Object In Salesforce





Visualforce PDF 支援之字形 - Fonts Available When Using Visualforce PDF Rendering

Visualforce PDF 支援之字形


Fonts Available When Using Visualforce PDF Rendering



Visualforce PDF rendering supports a limited set of fonts. To ensure that PDF output renders as you expect, use the supported font names.
For each typeface, the first font-family name listed is recommended.
Typefacefont-family Values
Arial Unicode MS
  • Arial Unicode MS
Helvetica
  • sans-serif
  • SansSerif
  • Dialog
Times
  • serif
  • Times
Courier
  • monospace
  • Courier
  • Monospaced
  • DialogInput