Showing posts with label Salesforce. Show all posts
Showing posts with label Salesforce. Show all posts

Thursday, December 12, 2019

Unable To Fetch The affinityToken From SessionId API In Live Agent REST API


  • According to the salesforce documentation to get the affinityToken first in headers you  have to set the X-LIVEAGENT-AFFINITY as null.
  • If your not setting or if your not passing this header without null value in your request will not receive any affinityToken.


Sample request without X-LIVEAGENT-AFFINITY header:








Sample request with X-LIVEAGENT-AFFINITY header:








Hope this helps you..Enjoy..!

Wednesday, December 11, 2019

How To Open a New Tab in Classic Console Using LWC Lightning Out

You have visual force and inside this your loading the LWC component using Lightning Out in Salesforce Classic Console.

Now,if you want to open a new sub tab (record detail page or visual force page) inside the console on click of a link (inside your LWC .html file) please use the below code.

test.html

<template>
     <lightning-card title="Additional Details" icon-name="custom:custom18">
       <template if:true={showform}>               
          <a href="javascript:srcUp('/apex/PageName?id=3773737');" target="_blank">Test</a>         
       </template>
    </lightning-card>
</template>

If it's not working or getting any issue please include the below 2 lines script files in your visual force page.

<apex:includeScript value="/soap/ajax/45.0/connection.js" />
<apex:includeScript value="/support/console/45.0/integration.js" />


Hope this helps you..Enjoy..!

Monday, December 9, 2019

How To Store The Pre Chat Details in Live Agent Transcript Object Using REST API

In my previous post we have learn how to pass the pre-chat details in REST API and how it shown to agent etc .Now,if you want to store this information in ChatTranscript (Object Name -LiveChatTranscript ) for future reference we can do it easily just by setting few things the same request body by making some changes at "transcriptFields":[] property in the request.

This information will get stored only after agent has ended the chat conversation with customer and if has chosen a option to store the transcript.

First,please goto the ChatTranscript object and create a custom fields to store the required data.

In my scenario I want to store the product category and price .So,I have created 3 new fields as Category__c,Product_Category__c,Price_Range__c. Product which comes from the chat request I want to store it 2 custom fields called Category__c,Product_Category__c and Price range in Price_Range__c.


API Details:


Headers:
X-LIVEAGENT-API-VERSION:34
X-LIVEAGENT-AFFINITYaffinityToken from SessionId API
X-LIVEAGENT-SESSION-KEYkey from from SessionId API
X-LIVEAGENT-SEQUENCE:1
Content-Type:application/json



Sample Request:

{
  "organizationId": "000008afQ",
  "deploymentId": "57228",
  "buttonId": "57328",
  "sessionId": "id-from-response",
  "userAgent": "Lynx/2.8.8",
  "language": "en-US",
  "screenResolution": "1900x1080",
  "visitorName": "Frank Underwood",
  "prechatEntities": [
    
  ],
  "receiveQueueUpdates": true,
  "isPost": true,
  "prechatDetails": [
   {
      "label": "Price Range",
      "value": "20,000-30,000",
      "displayToAgent": true,
      "transcriptFields": [ "Price_Range__c"],
      "entityFieldMaps": [
        
      ]
    },
{ "label": "Product Category", "value": "Smart Phone", "displayToAgent": true, "transcriptFields": ["Category__c","Product_Category__c"], "entityFieldMaps": [ ] }, { "label": "Description", "value": "I'm looking for a mobile with 8GB RAM and 256 GB ROM ", "displayToAgent": true, "transcriptFields": [ ], "entityFieldMaps": [ ] } ] }

Sample Response:

["Ok","200"]

                                             Hope this helps you..Enjoy..!

Friday, December 6, 2019

Live Agent REST API To Send The Pre Chat Details

Let's take a use case ,where you have bot or some custom FAQs to handle the basic customer queries and but sometimes it's required to connect the customer with one of your executives using salesforce live agent chat.

Whenever your connecting the customer with agent,it's required to pass the pre-chat conversation details to agents so that it will help him/her to greet the customer with issue details and also helps to resolve the customer queries quickly.

Luckily Salesforce supports all these features in their REST API.Please take a look at the api details below.

API Details:


Headers:
X-LIVEAGENT-API-VERSION:34
X-LIVEAGENT-AFFINITYaffinityToken from SessionId API
X-LIVEAGENT-SESSION-KEY: key from from SessionId API
X-LIVEAGENT-SEQUENCE:1
Content-Type:application/json


Sample Request:

{
  "organizationId": "000008afQ",
  "deploymentId": "57228",
  "buttonId": "57328",
  "sessionId": "id-from-response",
  "userAgent": "Lynx/2.8.8",
  "language": "en-US",
  "screenResolution": "1900x1080",
  "visitorName": "Frank Underwood",
  "prechatEntities": [
    
  ],
  "receiveQueueUpdates": true,
  "isPost": true,
  "prechatDetails": [
    {
      "label": "Product Category",
      "value": "Smart Phone",
      "displayToAgent": true,
      "transcriptFields": [  ],
      "entityFieldMaps": [
        
      ]
    },
    {
      "label": "Price Range",
      "value": "20,000-30,000",
      "displayToAgent": true,
      "transcriptFields": [  ],
      "entityFieldMaps": [
        
      ]
    },
    {
      "label": "Description",
      "value": "I'm looking for a mobile with 8GB RAM and 256 GB ROM ",
      "displayToAgent": true,
      "transcriptFields": [   ],
      "entityFieldMaps": [
        
      ]
    }
  ]
}

Sample Response:

["Ok","200"]

How Agent Looks in Salesforce This Data:
After mouse over on Accept


In chat Transcript



Hope this helps you..Enjoy..!




Live Agent REST API To Check Whether Agents Are Available(in Online or Not)

If you want to check whether any agent is available or not to take the new chat,then first we need to check whether a particular button is available to take the request or not.

Because agents are tagged under a particular button,if button status is online it means agents are under the same button is available to take the request.

Please look at the API details below


This api basically takes the list of button ids to which you want to verify ,if specified button id is online it will returns the flag called isAvailable or else isAvailable will not be present in the response.


EndPoint : 


https://HostName/chat/rest/Visitor/Availability?Availability.prefix=Visitor&Availability.ids=[List of Button Ids]&deployment_id=DeploymentId&org_id=OrganizationId

Headers:
X-LIVEAGENT-API-VERSION:34

Content-Type:application/json


Query parameters:

  • org_id - The ID of the Salesforce organization that’s associated with the Live Agent deployment.
  • deployment_id - The 15-digit ID of the Live Agent deployment that the chat request was initiated from.
  • Availability.ids - A comma separated button object IDs for which to verify availability.


{
"messages": [
{
"type": "Availability",
"message": {
"results": [
{
"id": "573280000l",
"isAvailable": true // Agents are available to accept new chat request 
},
{
"id": "573000004" // No agents are available to accept new chat request 
},
{
"id": "5730I00000",
"isAvailable": true //Agents are available to accept new chat request
}
]
}
}
]
}


Hope this helps you..Enjoy..!


Friday, August 23, 2019

Creating a Salesforce Scratch Org Using SFDX CLI

sfdc force:org:create -a <yourScartchOrgAliasName> -d 30 -f config/project-scratch-def.json -s

If you want to create a scratch org using the Salesforce CLI please use the below the command.

sfdx force:org:create -a <aliasNameOfYourOrg> -d <duration 1-30> - f <file path> -s (defaults)

sfdc force:org:create -a <aliasNameOfYourOrg> -d 30 -f config/project-scratch-def.json -s

-d   -- Scratch org duration 1 to 30 days
-a   -- Alias name that you give for your scratch org
-s    -- defaults this org for all ongoing commands
-f    -- config file location



You can specify all your scratch org configuration in this config file before you run this command


Hope this helped you..Enjoy..!


Basic Structure Of SFDX CLI Commands

Basically all the CLI commands will be in below format

namespace:topic:[Subtopics]:methodName

namespace             --  force/lightning
topic                       -- apex/org/data
Subtopics               -- apex:class,data:bulk,auth:web
methodname          -- final action

Sample Commands:

force:alias:list
force:alias:set
force:apex:class:create
force:apex:execute
force:apex:log:get
force:apex:log:list
force:apex:log:tail
force:apex:test:report
force:apex:test:run
force:apex:trigger:create
force:auth:jwt:grant
force:auth:list
force:auth:logout
force:auth:sfdxurl:store
force:auth:web:login
force:config:get
force:config:list
force:config:set
force:data:bulk:delete
force:data:bulk:status
force:data:bulk:upsert
force:data:record:create
force:data:record:delete
force:data:record:get
force:data:record:update
force:data:soql:query
force:data:tree:export
force:data:tree:import
force:doc:commands:display
force:doc:commands:list
force:lightning:app:create
force:lightning:component:create
force:lightning:event:create
force:lightning:interface:create
force:lightning:lint
force:lightning:test:create
force:lightning:test:install
force:lightning:test:run
force:limits:api:display
force:mdapi:convert
force:mdapi:deploy
force:mdapi:deploy:cancel
force:mdapi:deploy:report
force:mdapi:describemetadata
force:mdapi:listmetadata
force:mdapi:retrieve
force:mdapi:retrieve:report
force:org:clone
force:org:create
force:org:delete
force:org:display
force:org:list
force:org:open
force:org:shape:create
force:org:shape:delete
force:org:shape:list
force:org:snapshot:create
force:org:snapshot:delete
force:org:snapshot:get
force:org:snapshot:list
force:org:status
force:package1:version:create
force:package1:version:create:get
force:package1:version:display
force:package1:version:list
force:package:create
force:package:hammertest:list
force:package:hammertest:report
force:package:hammertest:run
force:package:install
force:package:install:report
force:package:installed:list
force:package:list
force:package:uninstall
force:package:uninstall:report
force:package:update
force:package:version:create
force:package:version:create:list
force:package:version:create:report
force:package:version:list
force:package:version:promote
force:package:version:report
force:package:version:update
force:project:create
force:project:upgrade
force:schema:sobject:describe
force:schema:sobject:list
force:source:convert
force:source:delete
force:source:deploy
force:source:deploy:cancel
force:source:deploy:report
force:source:open
force:source:pull
force:source:push
force:source:retrieve
force:source:status
force:user:create
force:user:display
force:user:list
force:user:password:generate
force:user:permset:assign
force:visualforce:component:create
force:visualforce:page:create


Hope this helped you..Enjoy..!

How To Open Command Palette In Visual Studio Code

Basically we will use command palette as an alternative option whatever we will be doing with commands can be done with this without writing any commands.

Based on your operating system you can use the below listed short cuts.

  • Windows Os - Ctrl+Shift  P
  • Mac Os - Command+Shift P



Hope this helped you..Enjoy..!

How To List All Commands In SFDX CLI

If you don't remember all the commands and if you want to know the list of the commands then please use the below command in your terminal window.It will list outs all the available commands.



sfdx commands

force:apex:class:create
force:apex:execute
force:org:open
.
.
.
force:auth:list





Hope this helped you..Enjoy..!

SFDX CLI Command To LogIn to An Org

If you want to login to your developer org/sandbox using the Salesforce CLI please use the below the command.

sfdx force:auth:web:login -a <aliasNameOfYourOrg> -d

sfdx force:auth:web:login -a mergedDev -d

-d   -- Makes this org as default for subsequent commands
-a   -- Alias name that you give for an org to identify prod/sandbox or which sandbox

Once you execute this command you can see this alias name under sfdx-config.json file.Based on the org you (dev or devhub) used it will stores the alias name under the this.


{
    "defaultusername": "mergedDev"}
-------------In case of devhub login------------
{
    "defaultdevhugusername": "mergedDev"}



Hope this helped you..Enjoy!..

Thursday, August 8, 2019

How to Use Rendered Attribute With Html Tags

Scenario:

Basically if you want to conditionally show/hide in any visual force element we will use the "rendered=true/false".Let assume if your using any html tags like <div> <span> in your visual force page and you want to hide/show conditionally we can not use the "rendered=true/false" property with these html tags.

Solution:

In these type of situations you can use some standard css styles to show or hide html content on conditionally.


<div style="{!IF(AND(condition1,condition2),'display:block','display:none')}">

//display:block - Shows the content,it's similar to rendered="true"

//dispaly:none - Hides the content,it's similar to rendered="false"

Sample Code:

<div class="slds-truncate sldswordWrap" style="{!IF(AND(condition1,condition2),'display:block','display:none')}">
      <span class="slds-icon_container slds-icon-standard-call">
        <svg class="slds-icon" aria-hidden="true">
           <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/standard-sprite/svg/symbols.svg#call" />
        </svg>
        <span class="slds-assistive-text">Description of icon when needed</span>
      </span>
</div>

Hope this helped you..Enjoy!..

Wednesday, August 23, 2017

Salesforce Site Template is Not Coming in Force.com Site

If your Site Template is not coming on your there might be the below issues.

1. Site Template page has not been added for Site Template on Site Detail Page



2. If your using any visual force page in your sites and if your not adding Template to visual force page you will not be able show the template.Please add the template to each and every page.


<apex:page standardController="Case" showHeader="false">
    <apex:composition template="{!$Site.Template}">
        <apex:define name="body">
    <head>
              <apex:includeScript value="{!$Resource.dataTableJS}"/>
       <apex:stylesheet value="{!$Resource.dataTableCSS}" />
     </head>
   <apex:form>
      ----
      ----
   </apex:form>
 </apex:define>
   </apex:composition>
</apex:page>

Hope this helps you...Enjoy!

CSS Styles/Scripts Are Not Working in Salesforce Force.com Sites

If your styles/scripts are working perfectly in Sandbox and Production preview but if it's not working on Force.com sites which has hosted publicly on Sales force server below points might be the issue.

Your page is referring to some external CSS/JS files:

<apex:page>
 <head>
 <apex:stylesheet value="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css" />
<apex:includescript value="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" /> 
</head>
<apex:form>
  ----
  ----
</apex:form>
</apex:page>

If your referring any styles/scripts from external sources with out storing them in Static Resource you will end up with problem Please store that files in Statistic resource and then use it then it will work in Force.com sites as well.


<apex:page>
 <head>
  <apex:includeScript value="{!$Resource.dataTableJS}"/>
  <apex:stylesheet value="{!$Resource.dataTableCSS}" />
</head>
<apex:form>
  ----
  ----
</apex:form>
</apex:page>


Your Static Resource is File not accessible publicly



If your using any static resource in your page and if that static resource is not accessible publicly (Cache Control set to Private) then styles will not reflect in Force.com sites.So mark your Static resources cache control as Public



Hope this helps you...Enjoy!