ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Creating a custom search Engine in Salesforce

Home / Article & Blogs / Salesforce / Integration / Creating a custom search Engine in Salesforce
By Team ABSYZ inIntegration

Hi All,

We can create a custom search engine in salesforce with the help of google. Let’s go in detail to create a custom search engine in salesforce these are the steps needs to follow.

  1. Need to have a google developer Account
  2. Create a custom search engine in Google
  3. Creating a visual Force Page in Salesforce
  4. Integrating Salesforce with Google to fetch the results.

In this blog, I am creating a custom search engine to return the person details based on the email address. Note: If the email address is linked with linkedIn, Facebook or Google Plus.

To create a google developer account visit this link: https://console.developers.google.com

On creation of account then create a project in google and on the creation of project create credentials and then API key will be created. Copy the API Key.

credential-screen

Create a custom search Engine by visiting this link: https://cse.google.com/

custom-serach-engine-creation-page

The sites needs to be added so the new custom search engine will search only from the respective sites. Sites add screenshot is shown below.

site-add-page

Then create a custom search engine and add the sites to search in your created new custom search engine. On the URL you can see the cx=’017xxxxxx’ so copy the cx parameter.

getting-cs

Then Open your salesforce account create a visual Force Page and Controller with the following code.

The Visual Force Page:

start-scree

By entering an email address in the page and then you can see the either facebook, googleplus or facebook link.

search-screen

Visual Force Page:

[sourcecode language=”java”]

<apex:page controller=”searchcontroller”>
<h> Please Search Here </h>
<apex:form>
<apex:inputText value=”{!inputstring}”/>
<apex:commandButton action=”{!submit}” value=”Search” />
<apex:pageBlock rendered=”{!check}”>
<apex:commandLink value=”{!laststrurl}” action=”{!open}” target=”_blank” />

<apex:image url=”{!img}” />
</apex:pageBlock>
</apex:form>
</apex:page>

[/sourcecode]

Controller:

[sourcecode language=”java”]

public with sharing class searchcontroller {

public String inputstring {
get;
set;
}
public string img {
get;
set;
}
public string laststrurl {
get;
set;
}
public boolean check {
get;
set;
}
//Api key is used as keyVal
public string keyVal = ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’;
//cx is used as searchVal
public string searchVal =’xxxxxxxxxxxxxxxxxxxxxxxx’;

public intelligentcontroller() {
check = false;
}

public PageReference submit() {

String strBody;
Http http = new Http();
HttpRequest req = new HttpRequest();

string endurl = ‘https://www.googleapis.com/customsearch/v1?key=’+keyVal +’&amp;cx=’+searchVal +’&amp;q=’ + inputstring;
req.setEndpoint(endurl);
req.setmethod(‘GET’);
try {
HttpResponse res = http.send(req);
strBody= res.getbody();

} catch (exception e) {
system.debug(e);
}

// Below logic is to parse the output

System.debug(strBody);
str.replace(‘\n’, ”);
system.debug(‘final’ + strBody);

string substr = strBody.substringBetween(‘”items”: [‘, ‘”cse_image”: [‘);
system.debug(‘substringgggg’ + substr);

if (substr != NULL) {
laststrurl = substr.substringBetween(‘”link”:’, ‘,’);
laststrurl = laststrurl.replace(‘ ‘, ”);
string substrlast = strBody.substringBetween(‘”cse_image”: [‘, ‘]’);
img = substr.substringBetween(‘”src”:’, ‘}’);
img = img.replace(‘ ‘, ”);
img = img.replace(‘”‘, ”);
if (laststrurl != NULL || laststrurl != ”) {
check = true;
} else {
check = false;
}
} else {
substr = strBody.substringBetween(‘”items”: [‘, ‘”pagemap”:’);
if (substr != NULL) {
laststrurl = substr.substringBetween(‘”link”:’, ‘,’);
laststrurl = laststrurl.replace(‘ ‘, ”);
string substrlast = str.substringBetween(‘”cse_image”: [‘, ‘]’);
img = ‘test’;
if (laststrurl != NULL || laststrurl != ”) {
check = true;
} else {
check = false;
}
}
}

return null;
}

public PageReference open() {
PageReference pg = new PageReference(laststrurl);
pg.setRedirect(true);
return pg;
}
}

[/sourcecode]

custom search engineGoogleRESTSalesforce
146
Like this post
127 Posts
Team ABSYZ

Search Posts

Archives

Categories

Recent posts

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

What Is Graphic Design? (Executive Summary 2023)

What Is Graphic Design? (Executive Summary 2023)

  • Previous PostCSV parsing to sObjects
  • Next PostSObject Tree Structure

Related Posts

PLATFORM EVENTS IN SALESFORCE
Integration Salesforce

PLATFORM EVENTS IN SALESFORCE

Integrate SharePoint with Salesforce using Microsoft Graph API
Apex Integration Salesforce

Integrate SharePoint with Salesforce using Microsoft Graph API

Create/Update Salesforce Picklist definitions using metadata API
Integration Metadata API Salesforce

Create/Update Salesforce Picklist definitions using metadata API

Increase your Productivity with the Apex Metadata API
Integration Metadata API

Increase your Productivity with the Apex Metadata API

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT