0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Lightning環境のグローバル検索用URLのハック

Last updated at Posted at 2021-02-01

classic環境では以下のように簡単にURLハックできたみたいです。

https://xxxx--lightning.my.salesforce.com/_ui/search/ui/UnifiedSearchResults?sen=ka&sen=003&str=[call.cli]&initialViewMode=summary&searchAll=true

では、Lightning環境ではどうでしょうか。ちょうど質問がありましたので調べてみると
url strings appearing in classic rather than lightning

そのそもURLが違います(当然かな)、それとBase64エンコードする必要があるみたいです。

回避策を頼りにコンポーネントを作ってみました。
質問者の検索条件と同じようにしてみます。

以下のコンポーネントでLightningのグルーバル検索用URLが生成されました。

コンポーネント

<aura:component implements="force:appHostable" access="global">
        <!-- ここに検索したい単語をセットする -->
	<aura:attribute name="search" type="String" default="call.cli"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <lightning:layout horizontalAlign="spread" multipleRows="true">
        <lightning:layoutItem padding="around-xx-small" flexibility="grow" size="12" mediumDeviceSize="12" largeDeviceSize="12"> 
            <div class="slds-box slds-box_xx-small slds-text-align_left slds-m-around_xx-small slds-theme_default">                            
                <lightning:layout verticalAlign="left" multipleRows="true">
                    
                    
    				Redirecting to search results for {!v.search}
                    
                </lightning:layout>
            </div>
        </lightning:layoutItem>
    </lightning:layout>
    
</aura:component>

コントローラ

({
	doInit : function(component, event, helper) {
        // Grab search query from URL
        var searchQuery = component.get("v.search");
        
        // Convert search query into SF expected format
        // "type":"TOP_RESULTS",,"id":"Product2","entity":"Product2"
        //取引先責任者だけを指定。実際には "name":"Contact"だけでもよさそうな感じ
        var stringToEncode = 
            '{"componentDef":"forceSearch:search","attributes":{"term":"'+ 
            searchQuery + '","scopeMap":{"labelPlural":"Contacts","entity":"Contact","name":"Contact" },"context":{"disableSpellCorrection":false,"SEARCH_ACTIVITY":{"term":"'+
            searchQuery + '"}}}}';
        var encodedString = btoa(stringToEncode);
        
        // Redirect user (this only works from Lightning App, won't work from components)
        window.location = "/one/one.app?source=alohaHeader#" + encodedString;

		
	}
})
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?