1分でわかるreturn false; preventDefault(); stopPropagation() の違い

クリックイベントのサンプル

.innerを子、.outerを親にしてそれぞれにクリックイベントのサンプルを作成した。リンクをクリックするとalertの”.inner”, “.outer”が表示されてからiwb.jpに遷移する。

1
2
3
4
5
6
7
$(“.inner”).click(function(){
alert(“.inner”);
});

$(“.outer”).click(function(){
alert(“.outer”);
});
alertの”.inner”, “.outer”が表示されてからiwb.jpに遷移するサンプル

preventDefault()

preventDefault()を使用するとリンクの遷移などのイベントを無効にできる。

1
2
3
4
5
6
7
8
$(“.inner”).click(function(e){
e.preventDefault();
alert(“.inner”);
});

$(“.outer”).click(function(){
alert(“.outer”);
});
preventDefault()のサンプル

stopPropagation()

stopPropagation()を使用するとイベント伝播をキャンセルできる。alertの”.inner”は表示されるが”.outer”は表示されない。リンク遷移は有効。

1
2
3
4
5
6
7
8
$(“.inner”).click(function(e){
e.stopPropagation();
alert(“.inner”);
});

$(“.outer”).click(function(){
alert(“.outer”);
});
stopPropagation()のサンプル

preventDefault()+stopPropagation()

preventDefault()とstopPropagation()は併用可能。この場合alertで”.inner”は表示されるが”.outer”は表示されずリンクの遷移も発生しない。

1
2
3
4
5
6
7
8
9
$(“.inner”).click(function(e){
e.preventDefault();
e.stopPropagation();
alert(“.inner”);
});

$(“.outer”).click(function(){
alert(“.outer”);
});
preventDefault()+stopPropagation()のサンプル

return false

return falseはそれが記述された箇所を読み込んだ時点で以降の処理がすべてなくなる。イベント伝播(バブリング)も発生しない。よって.innerをクリックした場合は”.inner”と”.outer”の両方が表示されずリンクの遷移も発生しない。

1
2
3
4
5
6
7
8
$(“.inner”).click(function(){
return false;
alert(“.inner”);
});

$(“.outer”).click(function(){
alert(“.outer”);
});
return falseのサンプル

Salesforce Sites Profile ゲストプロファイル

Salesforce Sites Profile ゲストプロファイル

Force.com Sitesを外部から閲覧するユーザにはSites用のゲストプロファイルが適用されて、その権限が細かく設定できるとのこと。[設定]→[開発]→[サイト]→サイト選択→[公開アクセス設定]の中で、今回設定したいのは、標準オブジェクト権限とカスタムオブジェクト権限の部分です。

Mavensmate-Oauth2-Url

Mavensmate-Oauth2-Url

oauth2 url is like below

https://login.salesforce.com//services/oauth2/authorize?client_id=3MVG9uudbyLbNPZP7kLgoRiWVRqiN8gFcKwdAlztVnjgbj9shSk1vMXJNmV7W0ciFbeYiaP9D4tLfBBD06l_7&redirect_uri=https%3A%2F%2Flocalhost%3A56248%2Fsfdc%2Fauth%2Fcallback&response_type=token&display=popup&prompt=login&state=%7B%22callback%22%3A%22%2Fapp%2Fproject%2Fauth%2Ffinish%22%7D
`</pre>

## oauth2 url is like below

<pre>`https://login.salesforce.com//services/oauth2/authorize?
client_id=3MVG9uudbyLbNPZP7kLgoRiWVRqiN8gFcKwdAlztVnjgbj9shSk1vMXJNmV7W0ciFbeYiaP9D4tLfBBD06l_7&amp;
redirect_uri=https://localhost:56248/sfdc/auth/callback&amp;
response_type=token&amp;
display=popup&amp;
prompt=login&amp;
state={"callback":"/app/project/auth/finish"}

python-and-the-force-com-rest-api-simple-simple-salesforce-example
salesforce quickstart_oauth

Create test class using SalesforceXyTools

SalesforceXyTools

Auto Create VF-Controller-DTO-DAO-Code

Hello,I am Exia.huang. Today I will show you how to create testclass quickly by using SalesforceXyTools. And how to create to create test data quickly.

##

  1. Open the apex code, and find the menu below. [SFDC-XY]->[SFDC Code Creator]->[Create Test Code] SOSSOS

    • The class code which I have selected is like below.

      /
      @author huangxy
      /
      public with sharing class BlogController extends SfdcXyController {

    // DTO Bean
    public BlogDto blogDto {get;set;}

    public BlogController() {

    search();
    

    }

    private void search(){

    <span class="pl-smi">String</span> id <span class="pl-k">=</span> <span class="pl-smi">ApexPages</span><span class="pl-k">.</span>currentPage()<span class="pl-k">.</span>getParameters()<span class="pl-k">.</span>get(<span class="pl-s"><span class="pl-pds">'</span>id<span class="pl-pds">'</span></span>);
    <span class="pl-k">if</span>(<span class="pl-smi">String</span><span class="pl-k">.</span>isBlank(id)){
        <span class="pl-c1">this</span><span class="pl-k">.</span>blogDto <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-smi">BlogDto</span>();
    }<span class="pl-k">else</span>{
        <span class="pl-c1">this</span><span class="pl-k">.</span>blogDto <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-smi">BlogDto</span>(<span class="pl-smi">BlogDao</span><span class="pl-k">.</span>getBlogById(id));
    }
    

    }

    /
    upsert Dto
    /
    public PageReference doSave() {

    <span class="pl-smi">Boolean</span> result;
    
    <span class="pl-smi">Savepoint</span> sp <span class="pl-k">=</span> <span class="pl-smi">Database</span><span class="pl-k">.</span>setSavepoint();
    <span class="pl-k">try</span> {
        upsert blogDto<span class="pl-k">.</span>getSobject();
        result <span class="pl-k">=</span> <span class="pl-c1">true</span>;
    } <span class="pl-k">catch</span>(<span class="pl-smi">DMLException</span> e) {
        <span class="pl-smi">Database</span><span class="pl-k">.</span>rollback(sp);
        <span class="pl-smi">System</span><span class="pl-k">.</span>debug(<span class="pl-s"><span class="pl-pds">'</span>saveDto DMLException:<span class="pl-pds">'</span></span> <span class="pl-k">+</span> e<span class="pl-k">.</span>getMessage());
        result <span class="pl-k">=</span> <span class="pl-c1">false</span>;
    } <span class="pl-k">catch</span>(<span class="pl-smi">Exception</span> e) {
        <span class="pl-smi">Database</span><span class="pl-k">.</span>rollback(sp);
        <span class="pl-smi">System</span><span class="pl-k">.</span>debug(<span class="pl-s"><span class="pl-pds">'</span>saveDto Exception:<span class="pl-pds">'</span></span> <span class="pl-k">+</span> e<span class="pl-k">.</span>getMessage());
        result <span class="pl-k">=</span> <span class="pl-c1">false</span>;
    }
    <span class="pl-k">return</span> <span class="pl-c1">null</span>;
    

    }

    /
    Go Next
    /
    public override PageReference doNext() {

    <span class="pl-smi">Boolean</span> result <span class="pl-k">=</span> doCheck();
    setNextMode(result);
    <span class="pl-k">return</span> <span class="pl-c1">null</span>;
    

    }

    /
    Go Back
    /
    public override PageReference doBack() {

    <span class="pl-smi">Boolean</span> result <span class="pl-k">=</span> <span class="pl-c1">true</span>; 
    setBackMode(result);
    <span class="pl-k">return</span> <span class="pl-c1">null</span>;
    

    }

    /
    do Check
    /
    public override Boolean doCheck() {

    <span class="pl-smi">Boolean</span> result <span class="pl-k">=</span> <span class="pl-c1">true</span>;
    
    <span class="pl-k">return</span> result;
    

    }
    }

    • Select [Create Test Code], the test code will be created automatically like below.

      /
      @author huangxy
      /
      @isTest
      private class BlogControllerTest {

/
This is a test method for BlogController
/
static testMethod void test_BlogController() {

<span class="pl-c"><span class="pl-c">//</span> PageReference pageRef = Page.Blog;</span>
<span class="pl-c"><span class="pl-c">//</span> Test.setCurrentPage(pageRef);</span>
<span class="pl-c"><span class="pl-c">//</span> pageRef.getParameters().put('param1', 'param1');</span>

<span class="pl-smi">Test</span><span class="pl-k">.</span>startTest();

BlogController blogController = new BlogController();

<span class="pl-smi">Test</span><span class="pl-k">.</span>stopTest();

<span class="pl-c"><span class="pl-c">//</span> Check</span>
<span class="pl-c"><span class="pl-c">//</span> System.assert(ApexPages.hasMessages());</span>
<span class="pl-c"><span class="pl-c">//</span> for(ApexPages.Message msg : ApexPages.getMessages()) {</span>
<span class="pl-c"><span class="pl-c">//</span>     System.assertEquals('Upload file is NULL', msg.getSummary());</span>
<span class="pl-c"><span class="pl-c">//</span>     System.assertEquals(ApexPages.Severity.ERROR, msg.getSeverity());</span>
<span class="pl-c"><span class="pl-c">//</span> }</span>

}

/
This is a test method for doSave
/
static testMethod void test_doSave() {

<span class="pl-c"><span class="pl-c">//</span> PageReference pageRef = Page.Blog;</span>
<span class="pl-c"><span class="pl-c">//</span> Test.setCurrentPage(pageRef);</span>
<span class="pl-c"><span class="pl-c">//</span> pageRef.getParameters().put('param1', 'param1');</span>

<span class="pl-smi">Test</span><span class="pl-k">.</span>startTest();

BlogController blogController = new BlogController();
PageReference resultDoSave = blogController.doSave();

<span class="pl-smi">Test</span><span class="pl-k">.</span>stopTest();

<span class="pl-c"><span class="pl-c">//</span> Check</span>
<span class="pl-c"><span class="pl-c">//</span> System.assert(ApexPages.hasMessages());</span>
<span class="pl-c"><span class="pl-c">//</span> for(ApexPages.Message msg : ApexPages.getMessages()) {</span>
<span class="pl-c"><span class="pl-c">//</span>     System.assertEquals('Upload file is NULL', msg.getSummary());</span>
<span class="pl-c"><span class="pl-c">//</span>     System.assertEquals(ApexPages.Severity.ERROR, msg.getSeverity());</span>
<span class="pl-c"><span class="pl-c">//</span> }</span>

}

/
This is a test method for doNext
/
static testMethod void test_doNext() {

<span class="pl-c"><span class="pl-c">//</span> PageReference pageRef = Page.Blog;</span>
<span class="pl-c"><span class="pl-c">//</span> Test.setCurrentPage(pageRef);</span>
<span class="pl-c"><span class="pl-c">//</span> pageRef.getParameters().put('param1', 'param1');</span>

<span class="pl-smi">Test</span><span class="pl-k">.</span>startTest();

BlogController blogController = new BlogController();
PageReference resultDoNext = blogController.doNext();

<span class="pl-smi">Test</span><span class="pl-k">.</span>stopTest();

<span class="pl-c"><span class="pl-c">//</span> Check</span>
<span class="pl-c"><span class="pl-c">//</span> System.assert(ApexPages.hasMessages());</span>
<span class="pl-c"><span class="pl-c">//</span> for(ApexPages.Message msg : ApexPages.getMessages()) {</span>
<span class="pl-c"><span class="pl-c">//</span>     System.assertEquals('Upload file is NULL', msg.getSummary());</span>
<span class="pl-c"><span class="pl-c">//</span>     System.assertEquals(ApexPages.Severity.ERROR, msg.getSeverity());</span>
<span class="pl-c"><span class="pl-c">//</span> }</span>

}

/
This is a test method for doBack
/
static testMethod void test_doBack() {

<span class="pl-c"><span class="pl-c">//</span> PageReference pageRef = Page.Blog;</span>
<span class="pl-c"><span class="pl-c">//</span> Test.setCurrentPage(pageRef);</span>
<span class="pl-c"><span class="pl-c">//</span> pageRef.getParameters().put('param1', 'param1');</span>

<span class="pl-smi">Test</span><span class="pl-k">.</span>startTest();

BlogController blogController = new BlogController();
PageReference resultDoBack = blogController.doBack();

<span class="pl-smi">Test</span><span class="pl-k">.</span>stopTest();

<span class="pl-c"><span class="pl-c">//</span> Check</span>
<span class="pl-c"><span class="pl-c">//</span> System.assert(ApexPages.hasMessages());</span>
<span class="pl-c"><span class="pl-c">//</span> for(ApexPages.Message msg : ApexPages.getMessages()) {</span>
<span class="pl-c"><span class="pl-c">//</span>     System.assertEquals('Upload file is NULL', msg.getSummary());</span>
<span class="pl-c"><span class="pl-c">//</span>     System.assertEquals(ApexPages.Severity.ERROR, msg.getSeverity());</span>
<span class="pl-c"><span class="pl-c">//</span> }</span>

}

/
This is a test method for doCheck
/
static testMethod void test_doCheck() {

<span class="pl-c"><span class="pl-c">//</span> PageReference pageRef = Page.Blog;</span>
<span class="pl-c"><span class="pl-c">//</span> Test.setCurrentPage(pageRef);</span>
<span class="pl-c"><span class="pl-c">//</span> pageRef.getParameters().put('param1', 'param1');</span>

<span class="pl-smi">Test</span><span class="pl-k">.</span>startTest();

BlogController blogController = new BlogController();
Boolean resultDoCheck = blogController.doCheck();

<span class="pl-smi">Test</span><span class="pl-k">.</span>stopTest();

<span class="pl-c"><span class="pl-c">//</span> Check</span>
<span class="pl-c"><span class="pl-c">//</span> System.assert(ApexPages.hasMessages());</span>
<span class="pl-c"><span class="pl-c">//</span> for(ApexPages.Message msg : ApexPages.getMessages()) {</span>
<span class="pl-c"><span class="pl-c">//</span>     System.assertEquals('Upload file is NULL', msg.getSummary());</span>
<span class="pl-c"><span class="pl-c">//</span>     System.assertEquals(ApexPages.Severity.ERROR, msg.getSeverity());</span>
<span class="pl-c"><span class="pl-c">//</span> }</span>

}

/
This is a test method for all
/
static testMethod void test_all() {

<span class="pl-c"><span class="pl-c">//</span> PageReference pageRef = Page.Blog;</span>
<span class="pl-c"><span class="pl-c">//</span> Test.setCurrentPage(pageRef);</span>
<span class="pl-c"><span class="pl-c">//</span> pageRef.getParameters().put('param1', 'param1');</span>

<span class="pl-smi">Test</span><span class="pl-k">.</span>startTest();

// test BlogController
BlogController blogController = new BlogController();

// test doSave
PageReference resultDoSave = blogController.doSave();

// test doNext
PageReference resultDoNext = blogController.doNext();

// test doBack
PageReference resultDoBack = blogController.doBack();

// test doCheck
Boolean resultDoCheck = blogController.doCheck();

<span class="pl-smi">Test</span><span class="pl-k">.</span>stopTest();

<span class="pl-c"><span class="pl-c">//</span> Check</span>
<span class="pl-c"><span class="pl-c">//</span> System.assert(ApexPages.hasMessages());</span>
<span class="pl-c"><span class="pl-c">//</span> for(ApexPages.Message msg : ApexPages.getMessages()) {</span>
<span class="pl-c"><span class="pl-c">//</span>     System.assertEquals('Upload file is NULL', msg.getSummary());</span>
<span class="pl-c"><span class="pl-c">//</span>     System.assertEquals(ApexPages.Severity.ERROR, msg.getSeverity());</span>
<span class="pl-c"><span class="pl-c">//</span> }</span>

}

}

  1. Insert Test Data(All Field) I will select Blog__c. SOSSOSSOS

    List<Blogc> blogList = new List<Blogc>();
    for(Integer i=0; i<5; i++){
    Blogc blog = new Blogc();
    blog.commentc = CoaM5Vy + string.valueof(i) ; //評価
    blog.comment_status
    c = spam; //評価ステータス
    blog.contentc = biKtXlF + string.valueof(i) ; //内容
    blog.excerpt
    c = QVbhcE8 + string.valueof(i) ; //概要
    blog.statusc = Draft; //ステータス
    blog.title
    c = 52lF1IP + string.valueof(i) ; //タイトル
    blogList.add(blog);
    }
    insert blogList;

  2. Insert Test Data(From SOQL)SOSSOSSOS


    select id,name,commentc,contentc from Blog__c limit 2

    • Select [Insert Test Data(From SOQL) ] Menu, the sql will be change to apex code like below.

        List<Blogc> blogList = new List<Blogc>();
      Blogc blog0 = new Blogc();
      // blog0.id = ‘a096F00001yVNHWQA4’; // カスタムオブジェクト ID
      blog0.name = ID-0004; // ブログNo
      blog0.commentc = 評価; // 評価
      blog0.content
      c = 評価; // 内容
      blogList.add(blog0);

    Blogc blog1 = new Blogc();
    // blog1.id = ‘a096F00001yVNHRQA4’; // カスタムオブジェクト ID
    blog1.name = ID-0003; // ブログNo
    blog1.commentc = 評価1e; // 評価
    blog1.content
    c = 内容; // 内容
    blogList.add(blog1);

    upsert blogList;

Export Sobject To Excel By Using SalesforceXyTools

SalesforceXyTools

SalesforceXyTools Export Soject To Excel

Hello,I am Exia.huang. Today I will show you how to export soject to excel.

There are 3 steps.

  1. Find the menu below. [SFDC-XY]->[SFDC Object]->[Save SFDC Object List AS Excel] SOS
  2. Input your save path and xlsx file name. SOS

SOS

  1. Open the excel file, and enjoy yourself. SOSSOS SOS

SalesforceXyTools-install

SalesforceXyTools

SalesforceXyTools Install Help

Prerequisites

Plugin Installation(Use Package Control to Install)

  1. Open Sublime Text 3
  2. Run Package Control: Install Package command

  3. Search for SalesforceXyTools SOS

  4. Hit Enter, That is all. SOS