Upto 20% Scholarship on Live Online Classes

- Technology Blogs -

How to integrate Blockchain with Salesforce?

  • »
  • Blog
  • »
  • Blockchain
  • »
  • How to integrate Blockchain with Salesforce?
integrate Blockchain with Salesforce

The last two years will be associated with prodding on transformative blockchain norms and arrangements, driven partially by the interest in transparency, coordinated effort, and improved productivity in the transportation of technology. Concentrated on development here, Salesforce has joined the blockchain world– to improve the production network involvement for its clients, cloud technology, marketing automation, and to satisfy end purchasers better.

Salesforce has dependably been an organization that is always looking forward to the next big innovation, regardless of whether that was mobile, social, internet of things or artificial intelligence. In a meeting towards the finish of March with Business Insider’s Julie Bort, Salesforce co-founders Marc Benioff and Parker Harris discussed the scope of subjects including how the organization came to take a shot at one of the next hot advancements, a blockchain product.  This blog will shed light on Salesforce and Blockchain integration. The blog covers the following topics- 

Introduction of Blockchain

As per the Wikipedia “A blockchain, originally blockchain is a growing list of records, called blocks, which are linked using cryptography.”

Blockchain was first depicted in 1991 by Stuart Haber and W. Scott Stornetta. In any case, it got into the spotlight after Bitcoin.

Blockchain has nodes, and these nodes are called Blocks. Each square contains the hash, hash of the past square, timestamp, and the information. Treating with blockchain isn’t simple. If a square has been tainted than the chain gets adulterated.
salesforce Curriculum

At the peak level, a blockchain is only a database. Its distinctive qualities are the unchanging nature of its exchanges and decentralized control; decentralized control is its foremost element. With conventional databases, one association controls ace information. Be that as it may, with blockchain, or dispersed record, taking part associations to have equivalent capacity to peruse and compose master data.

Blockchain innovation was promoted in 2009 by the digital money Bitcoin and later in 2014 by the more summed up open-source Ethereum. At that time, the two innovations depended on a vast open unknown system for their security and utilized monetary instruments to support interest. These elements pulled in terrible entertainers who caused some prominent episodes, which added to the negative view of blockchain innovation.

The Concept of Blockchain

A Block is quite like the connected list yet with greater multifaceted nature. The information from the square creates a square’s hash. Be that as it may, it is easy to create the hash from the information. To counteract this, it additionally contains the hash of the past square. Along these lines, if any information is contacted, at that point square get invalid and the chain as well. If somebody needs to hack the blockchain, then the programmer needs to refresh every one of the squares. It isn’t that straightforward and the time has come devouring also. In Bitcoin, each square can be refreshed or made in the hole of 10 minutes. So it can take one individual’s lovely life to change every one of the squares.

Read:   JanBask Training Gives a High Level of Business Analyst Training

Concept of Blockchain

Benefits that you can get from aligning Blockchain with Salesforce 

A). The Increase of CRM Data Security

That is the point at which your organization can get demonstrated information that is ensured by blockchain innovation. It is a huge element while utilizing cloud arrangements.

B). The Ability to Be Closer to Your Customers and Grasp their Demands

Blockchain can give you a top to the bottom outline of the prospects and clients, break down their requests and choose where to convey the business assets. That is the reason for applying the blockchain innovation inside CRM can support consumer loyalty and give you an inventive apparatus for dealing with the business procedure.

C). The Customer Experience Management Improvement

That is how you will guarantee the customer’s information security and deal with the customer’s experience in any case of the business.

Besides, you will be able to:

  • use an obvious and secure customers database to give a powerful client reliability program;
  • manage customer rewards;
  • secure the customers’ wallets to build your organization’s trust;
  • guard the mobile applications from programmer assaults with the assistance of blockchain innovation.

Consequently, the blockchain together with CRM can expand the security, quality, and speed of your client administration higher than ever. Accordingly, it ought to be seen that this blend makes them both a solitary incredible couple.

Basic Integration of Blockchain with Salesforce Apex

We have seen a ton of buzz about blockchain. We have experienced a few of the online journals and fundamental projects in NodeJs. Really, regardless we think about it less. Be that as it may, our enthusiasm for salesforce brings us to compose the Basic blockchain program at the peak. The blockchain is, still Interstellar and Inception for many people.

Read:   Salary Structure of a Salesforce Developer in the USA

Let’s Code:

1). The first step is to create a class called Block. This class will further be utilized to create new blocks in the chain.

A). public Block(integer index, string data, string prevHash)

The constructor of the class will have three parameters.

  • Index: Index of the block.
  • Data: Data for the Block.
  • prevHash: Hash code of the previous block.

B). private long generateTimeStamp()

This method will generate timestamp for the block.

C). private long generateTimeStamp()

This method will generate timestamp for the block.

D).

public string getHash(){

    Blob dataToEncrypt = Blob.valueOf( this.data + this.prevHash + this.index + this.timestamp );

    Blob encrypted = crypto.generateMac('HmacSHA256', dataToEncrypt, Blob.valueOf('key'));

    return EncodingUtil.base64Encode(encrypted);

}

This method creates hash code from data + prevHash + index + timestamp.

I am using the generateMac method from Crypto class.

I am selecting HmacSHA256 in the algorithm.

You can choose any Private key to generate a message authentication code (Mac).

E).

public string getHash(){

Blob dataToEncrypt = Blob.valueOf( this.data + this.prevHash + this.index + this.timestamp );

Blob encrypted = crypto.generateMac('HmacSHA256', dataToEncrypt, Blob.valueOf('key'));

return EncodingUtil.base64Encode(encrypted);

}

This method creates hash code from data + prevHash + index + timestamp.

I am using the generateMac method from Crypto class.

I am selecting HmacSHA256 in the algorithm.

You can choose any Private key to generate a message authentication code (Mac).

2). The next step is to create a Class called Blockchain. This is the class that will be utilized to create the new blocks in the chain and then to Validate that chain.

A).

public void addBlock(string data){

//Defining Index from chain size

integer index = chain.size();


//Checking for previous block's hash, If it is the first block then it set the previous block as '0'

string prevHash = chain.isEmpty()==true ? '0' : chain.get(chain.size()-1).hash;


//Creating a block from index, data and previous block's hash

Block newBlock = new Block(index, data, prevHash);


//Adding the new block in the chain

chain.add(newBlock);

}

This method will add a new block to the chain with the given data.

B). public boolean isChainValid()

This method is checking for the valid chain.

if the chain is not valid then it will return false,

Read:   How to Update, Insert, Export or Delete Data Using Apex Data Loader?

if it is valid then it will return true.

C).

public boolean isBlockValid(integer index){

//Checking block's hash with run time calculated a hash from the block

//If someone has changed the block data then getHash will return a new data

//This will not be same as the block's Hash

if(chain[index].hash != chain[index].getHash() ){

return false;

}



//If the index is greater than zero then it is also checking the block's prevHash from previous block's hash.

//If someone changed the data and but still he needs to change the hash as well

//Hash is generated by the combination of data+index+timestap+prevHash.

//If someone wants to make the hash correct, he has to change the prevHash as well

//Now the block seems good as all the needed values are changed

//But now this line will check prevHash from previous index's block hash.

//It will not be the same. Now it sends the false in return.

if(index > 0 && chain[index].prevHash != chain[index-1].hash ){

return false;

}

return true;

}

This method is checking for the valid block.

if the block is not valid then it will return false,

if it is valid then it will return true.

As you have to see that if someone wants to change a block then the person needs to change the entire chain.

@Lastly, Test the code that you have just run

isTest

public class BlockChainTest{
//Testing Blockchain

@isTest

public static void testBlockChain(){

/**Data Setup**/
//Creating Instance of Blockchain

BlockChain bChain = new BlockChain();
//addBlock method take data as the string
//Changing data to the string with the JSON format
//Adding the first block to the chain

bChain.addBlock( json.serialize( new BCTestDataWrapper('Iron Man', '2334343434') ) );
//Adding the second block to the chain

bChain.addBlock( json.serialize( new BCTestDataWrapper('Thor', '34343434') ) );

/**Positive Testing**/
//isChainValid will return true, as no data has been modified from block

system.assertEquals(true, bChain.isChainValid() );

//Print Blockchain

system.debug('-Blockchain Data Before Modifying--'+Json.serialize( bChain.chain) );

/**Negative Testing**/

//Now updating the 0 index's block

BCTestDataWrapper tData = (BCTestDataWrapper)JSON.deserialize(bChain.chain[0].data, BCTestDataWrapper.class);

tData.name = 'Thanos';

bChain.chain[0].data = json.serialize(tData);

//isChainValid will return false, as the data has been modified from block

system.assertEquals(false, bChain.isChainValid() );

//Print Blockchain

system.debug('-Blockchain Data After Modifying--'+Json.serialize( bChain.chain) );

}

}


Conclusion

Integrating Salesforce with Blockchain is going to give it a huge bump as it is already an ace CRM tool; integration with Salesforce is only going to increase the functionality of Salesforce. Do write back to us in case of any queries.

JanBask Training

JanBask Training

JanBask Training is a leading Global Online Training Provider through Live Sessions. The Live classes provide a blended approach of hands on experience along with theoretical knowledge which is driven by certified professionals.



Write a Comment

avatar
  Subscribe  
Notify of

Trending

Top 30 Core Java Interview Questions and Answers for Fresher, Experienced Developer
What Is Trigger In Salesforce?
Top 30 Manual Testing Interview Questions & Answers for Fresher
Different Types of SQL Server & SQL Database Functions
Top 20 AWS Interview Question and Answers For Fresher, Experienced Developer

Related Posts

How to integrate Blockchain with Salesforce?
Blockchain Learning Certification Path – Future Scope & Career Growth
A Beginner’s Guide to the working of Blockchain Technology
What Is Blockchain? Blockchain Tutorial Guide for Beginners