2017年12月22日金曜日

[Visualforce] DateTime項目をDate形式で表示する/Show DateTime field as Date format

<問題・Problem>

DateTime項目をDateのみ表示したい。
例)2017/12/25 9:30 → 2017/12/25

Display only Date of DateTime field.
Ex)2017/12/25 9:30 → 2017/12/25

<解決策・Solution>

<apex:outputText><apex:param>を使います。
Use <apex:outputText> and <apex:param>.



<サンプル・Sample>

 <apex:outputtext value="{0, date, yyyy/MM/dd}">  
      <apex:param value="{!DateField__c}"></apex:param>  
 </apex:outputtext>  

2017年12月19日火曜日

[Apex/Visualforce] エラー/Error Unexpected Token : 'FROM'

<問題・Problem>

エラー:Unexpected Token : 'FROM'
Error : Unexpected Token : 'FROM'

<解決策・Solution>

SOQLに問題あり。おそらくカンマがFROMの前に余計に付いています。
There is a problem in SOQL. Maybe there is extra comma "," just before "FROM".

2017年12月6日水曜日

[jQuery] 要素の直下にコンテンツを追加したい/Insert content to the beginning of each element

<問題・Problem>

コンテンツをappendで追加しようとすると、要素の一番最後に追加されるが、一番最初に追加したい。
You want to add contents at the beginning of the selected element. But when you use "append", contents will be insert at the end of the selected element.


<解決策・Solutions>

appendではなくprependを使う。
Use "prepend" instead of "append".


<サンプル・Sample>

 HTML :   
 <ul>  
   <li>pen</li>  
   <li>pineapple</li>  
   <li>apple</li>  
 </ul>  
   
 jQuery :  
 $('li').prepend('<li>PPAP!</li>');  
   
 Result :   
 <ul>  
   <li>PPAP</li>  
   <li>pen</li>  
   <li>pineapple</li>  
   <li>apple</li>  
 </ul>  
   

2017年12月4日月曜日

[Salesforce] 管理パッケージ化の注意点/Notes of Managed Package

App Exchangeにアプリケーションを登録する場合、「管理パッケージ」を作成する必要があります。一度管理パッケージ化してしまうと、今まで経験したことのない問題にたくさんぶち当たるので、それらの問題点を随時まとめていこうと思います。
To register your application to App Exchange, you need to create a "Managed Package". But once you create a Managed Package, many problems you've never experienced occurs. I will collect these problems and update it in this page.

<Apex Class>
1.
globalで書いたメソッドは、削除や引数の変更など行うことができなくなる。
global method can't be deleted or modified its arguments.



[Apex/JSON] JSON型文字列を配列にする/Change JSON Type to Array

<問題・Problem>

JSON型の文字列をApex ClassでList型やMap型に変換したい!
JSON type String needs to be changed to List type or Map type in Apex Class!

<解決策・Solution>

JSON.deserializeとキャストを使用します。
Use JSON.deserialize and Cast.

Listの場合/List case:
List<String> リスト名/List Name = (List<String>)JSON.deserialize(JSON文字列/JSON String , List<String>.class);

<サンプル・Sample>

JSON:
 [  
   {"name":"pen","num":"10"},  
   {"name":"pineapple","num":"20"},  
   {"name":"apple","num":"30"}  
 ]  

Apex Class:
 String jsonString = '[{"name":"pen","num":"10"},{"name":"pineapple","num":"20"},{"name":"apple","num":"30"}]';  
   
 List<map<String,String>> sampleList = (List<Map<String,String>>)JSON.deserialize(jsonString,List<Map<String,String>>.class);  
 
 for(Integer i = 0;i<sampleList.size();i++){  
   for(String s : sampleList[i].keySet()){  
     system.debug(s + ' : ' + sampleList[i].get(s));  
   }  
 }  

Debug Result:
 pen : 10  
 pineapple : 20  
 apple : 30  

2017年12月1日金曜日

[Visualforce SLDS] slds-tableのヘッダーを固定する/Fix header of slds-table

<問題・Problem>

SLDSのTableComponentページhttps://www.lightningdesignsystem.com/components/data-tables/にはヘッダーを固定する方法が書いてありません。
There is no description about fixed header in SLDS TableComponent pagehttps://www.lightningdesignsystem.com/components/data-tables/.

<解決策・Solution>

実は、ヘッダーを固定するクラスがSLDSに用意されているのです!ヘッダー固定はとっても簡単に実装できます!
Actually, there are some classes which can fix table header! It's very easy to implement the feature!

Class:
  • slds-table–header-fixed_container
  • slds-table--header-fixed
  • slds-cell-fixed

<サンプル・Sample>


 <div class="slds-table--header-fixed_container" style="height:300px;">  
   <div class="slds-scrollable_y" style="height:100%;">  
     <table class="slds-table slds-table_bordered slds-table--header-fixed">  
       <thead>  
         <tr class="slds-text-title_caps">  
           <th scope="col">  
             <div class="slds-truncate slds-cell-fixed" style="padding: 8px;" title="Name">  
               Name   
             </div>  
           </th>  
           <th scope="col">  
             <div class="slds-truncate slds-cell-fixed" style="padding: 8px;" title="Amount">  
               Amount  
             </div>  
           </th>  
         </tr>  
       </thead>  
       <tbody >  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Pen"><a href="javascript:void(0);">pen</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">10</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Pineapple"><a href="javascript:void(0);">Pineapple</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">20</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Apple"><a href="javascript:void(0);">Apple</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">30</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Pen"><a href="javascript:void(0);">pen</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">10</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Pineapple"><a href="javascript:void(0);">Pineapple</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">20</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Apple"><a href="javascript:void(0);">Apple</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">30</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Pen"><a href="javascript:void(0);">pen</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">10</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Pineapple"><a href="javascript:void(0);">Pineapple</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">20</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Apple"><a href="javascript:void(0);">Apple</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">30</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Pen"><a href="javascript:void(0);">pen</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">10</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Pineapple"><a href="javascript:void(0);">Pineapple</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">20</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Apple"><a href="javascript:void(0);">Apple</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">30</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Pen"><a href="javascript:void(0);">pen</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">10</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Pineapple"><a href="javascript:void(0);">Pineapple</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">20</div>  
           </td>  
         </tr>  
         <tr>  
           <th scope="row" data-label="Name">  
             <div class="slds-truncate" title="Apple"><a href="javascript:void(0);">Apple</a></div>  
           </th>  
           <td data-label="Amount">  
             <div class="slds-truncate" title="10">30</div>  
           </td>  
         </tr>  
       </tbody>  
     </table>  
   </div>  
 </div>  

[jQuery] 追加した要素にイベントを設定/Setup Event to added element

<問題・Problem>

append()などを使用し、要素を追加すると、以下のように書いたイベントが動かきません。
When adding elements by using like "append()", the following code doesn't work.

  • $('.sample').change(function(){...
  • $('.sample').onclick(function(){...

<解決策・Solution>

以下のようにコードを書き換えます。
Replace the code with the following.
  • $('.sample').on('change',function(){...
  • $('.sample').on('click',function(){...

<注意・Note>

これでも動かない場合、以下のように$(function(){で囲み忘れている可能性があります。
If your code still doesn't work, be sure to use " $(function(){ " outside the code.

$(function(){
    $('.sample').on('click',function(){...
    });
});