Lightning: A Simple Multi Select Component

 

 

As we all know Lightning is on boom now. With every release we get new feature and functionality on Lightning. Many of us are just realized how much it is important to learn lightning so now I will share some small code sample related to Lightning in upcoming using them you can get a quick start your Lightning study. i also recommend you to check my previous post to get the basic Idea.

Today I will share a simple multi select component where we will pass data between two components.

MSPL.gif

Lightning Component

Controller JS


As from code you can easily get the idea that I have used component.get and have passed the attribute value to get the selected value and add/ remove the value from list. You can find the complete code here. Play with it and let me know if you face any issue.

 

Happy programming 🙂

Advertisements

Connect Salesforce with Authorize.Net

Connect Salesforce with Authorize.Net

Hi All, We all know about authorize.net. Its the most common payment gateway used to make payment transaction from Website. We can also use it with Salesforce to setup payment gateway where our users can make a purchase and do payments as well.

Its very easy to connect Salesforce with Authorize.net. In this post we will use Sandbox account to make transaction but you can follow same steps for live transactions.

  • First Sign up for a Sandbox account here. Screenshot_2.pngNow you will get Login Id and Transaction Key. Store them in some place so that we can use them later.

Screenshot_1

  •  Now there are various method from which we can make a payment, Authorize a payment, Charge a card later and void the transaction. In case of Production URl we need to change the base URl.
  • Also make sure you add the base URL in remote site setting.

Screenshot_3.png


public with sharing class AuthorizePayment {

private string APIkey = '********';
private string transKey = '************';
private string Amt = '5';
private string cardNum = '5424000000000015';
private string expdate = '1220';
private string cvvCode = '999';

//Method to make payment and charge the card
public void makePayment(){
//Getting access token from Paypal
HttpRequest req1 = new HttpRequest();
req1.setMethod('POST');
req1.setEndpoint('https://apitest.authorize.net/xml/v1/request.api');
req1.setHeader('content-type', 'application/json');
/*
Production URL: https://api.authorize.net/xml/v1/request.api

XSD URL: https://api.authorize.net/xml/v1/schema/AnetApiSchema.xsd
*/

string messageBody1 ='{"createTransactionRequest":{"merchantAuthentication":{"name":"'+APIkey+'","transactionKey":"'+transKey+'"},'
+'"refId":"123456","transactionRequest":{"transactionType":"authCaptureTransaction","amount":"'+Amt+'","payment":{"creditCard":'
+'{"cardNumber":"'+cardNum+'","expirationDate":"'+expdate+'","cardCode":"'+cvvCode+'"}},"lineItems":{"lineItem":{"itemId":"1","name":"vase",'
+'"description":"Cannes logo","quantity":"18","unitPrice":"45.00"}},"tax":{"amount":"4.26","name":"level2 tax name","description":"level2 tax"},'
+'"duty":{"amount":"8.55","name":"duty name","description":"duty description"},"shipping":{"amount":"4.26","name":"level2 tax name",'+
'"description":"level2 tax"},"poNumber":"456654","customer":{"id":"99999456654"},"billTo":{"firstName":"Ellen","lastName":"Johnson",'+
'"company":"Souveniropolis","address":"14 Main Street","city":"Pecan Springs","state":"TX","zip":"44628","country":"USA"},"shipTo":'+
'{"firstName":"China","lastName":"Bayles","company":"Thyme for Tea","address":"12 Main Street","city":"Pecan Springs","state":"TX","zip":"44628",'+
'"country":"USA"},"customerIP":"192.168.1.1","transactionSettings":{"setting":{"settingName":"testRequest","settingValue":"false"}},'+
'"userFields":{"userField":[{"name":"MerchantDefinedFieldName1","value":"MerchantDefinedFieldValue1"},{"name":"favorite_color","value":"blue"}]}}}}';

req1.setHeader('Content-length', String.valueOf(messageBody1.length()));
req1.setBody(messageBody1);

req1.setTimeout(60*1000);
Http h1 = new Http();
String resp1;
HttpResponse res1 = h1.send(req1);
resp1 = res1.getBody();
Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res1.getBody().substring(1,res1.getBody().length())) ;
for(string keyStr : responseMap.keyset())
system.debug(keyStr+'-----------Response------------------>>>>'+responseMap.get(keyStr));
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Confirm, resp1));

}

//Method to authorize the card to make the payment later
public void authorizecard(){
HttpRequest req1 = new HttpRequest();
req1.setMethod('POST');
req1.setEndpoint('https://apitest.authorize.net/xml/v1/request.api');
req1.setHeader('content-type', 'application/json');
/*
Production URL: https://api.authorize.net/xml/v1/request.api

XSD URL: https://api.authorize.net/xml/v1/schema/AnetApiSchema.xsd
*/

string messageBody1 ='{ "createTransactionRequest": { "merchantAuthentication": { "name":"'+APIkey+'","transactionKey":"'+transKey+'" }, '+
'"refId": "123456", "transactionRequest": { "transactionType": "authOnlyTransaction", "amount": "'+Amt+'", "payment": { "creditCard": '+
'{ "cardNumber":"'+cardNum+'","expirationDate":"'+expdate+'","cardCode":"'+cvvCode+'" } }, "lineItems": { "lineItem": { "itemId": "1", '+
'"name": "vase", "description": "Cannes logo", "quantity": "18", "unitPrice": "45.00" } }, "tax": { "amount": "4.26", "name": "level2 tax name",'+
'"description": "level2 tax" }, "duty": { "amount": "8.55", "name": "duty name", "description": "duty description" }, "shipping": '+
'{ "amount": "4.26", "name": "level2 tax name", "description": "level2 tax" }, "poNumber": "456654", "customer": { "id": "99999456654" },'+
' "billTo": { "firstName": "Ellen", "lastName": "Johnson", "company": "Souveniropolis", "address": "14 Main Street", "city": "Pecan Springs",'+
' "state": "TX", "zip": "44628", "country": "USA" }, "shipTo": { "firstName": "China", "lastName": "Bayles", "company": "Thyme for Tea", '+
'"address": "12 Main Street", "city": "Pecan Springs", "state": "TX", "zip": "44628", "country": "USA" }, "customerIP": "192.168.1.1", '+
'"transactionSettings": { "setting": { "settingName": "testRequest", "settingValue": "false" } }, "userFields": { "userField": [ '+
'{ "name": "MerchantDefinedFieldName1", "value": "MerchantDefinedFieldValue1" }, { "name": "favorite_color", "value": "blue" } ] } } } }';

req1.setHeader('Content-length', String.valueOf(messageBody1.length()));
req1.setBody(messageBody1);

req1.setTimeout(60*1000);
Http h1 = new Http();
String resp1;
HttpResponse res1 = h1.send(req1);
resp1 = res1.getBody();
Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res1.getBody().substring(1,res1.getBody().length())) ;
for(string keyStr : responseMap.keyset())
system.debug(keyStr+'-----------Response------------------>>>>'+responseMap.get(keyStr));
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Confirm, resp1));

}

//Method for refund the settled payment
public void refundPay(){
HttpRequest req1 = new HttpRequest();
req1.setMethod('POST');
req1.setEndpoint('https://apitest.authorize.net/xml/v1/request.api');
req1.setHeader('content-type', 'application/json');
/*
Production URL: https://api.authorize.net/xml/v1/request.api

XSD URL: https://api.authorize.net/xml/v1/schema/AnetApiSchema.xsd
*/

string messageBody1 ='{ "createTransactionRequest": { "merchantAuthentication": { "name":"'+APIkey+'","transactionKey":"'+transKey+'" },'+
' "refId": "123456", "transactionRequest": { "transactionType": "refundTransaction", "amount": "5.00", "payment": { "creditCard": '+
'{ "cardNumber":"'+cardNum+'","expirationDate":"'+expdate+'" } }, "refTransId": "60024747323" } } }';

req1.setHeader('Content-length', String.valueOf(messageBody1.length()));
req1.setBody(messageBody1);

req1.setTimeout(60*1000);
Http h1 = new Http();
String resp1;
HttpResponse res1 = h1.send(req1);
resp1 = res1.getBody();
Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res1.getBody().substring(1,res1.getBody().length())) ;
for(string keyStr : responseMap.keyset())
system.debug(keyStr+'-----------Response------------------>>>>'+responseMap.get(keyStr));
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Confirm, resp1));

}

//method for cancel the unseattled payment
public void voidPay(){
HttpRequest req1 = new HttpRequest();
req1.setMethod('POST');
req1.setEndpoint('https://apitest.authorize.net/xml/v1/request.api');
req1.setHeader('content-type', 'application/json');
/*
Production URL: https://api.authorize.net/xml/v1/request.api

XSD URL: https://api.authorize.net/xml/v1/schema/AnetApiSchema.xsd
*/

string messageBody1 ='{ "createTransactionRequest": { "merchantAuthentication": { "name":"'+APIkey+'","transactionKey":"'+transKey+'" },'+
'"refId": "123456", "transactionRequest": { "transactionType": "voidTransaction", "refTransId": "60024747323" } } }';

req1.setHeader('Content-length', String.valueOf(messageBody1.length()));
req1.setBody(messageBody1);

req1.setTimeout(60*1000);
Http h1 = new Http();
String resp1;
HttpResponse res1 = h1.send(req1);
resp1 = res1.getBody();Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res1.getBody().substring(1,res1.getBody().length())) ;
for(string keyStr : responseMap.keyset())
system.debug(keyStr+'-----------Response------------------>>>>'+responseMap.get(keyStr));
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Confirm, resp1));
}

}

  • From the transaction response you will get the transId which you can n cancellation and other processes. You can read more about them in detail from here.

So now you can setup a payment gateway in your force.com site or for internal user. If you like this post or want to add something let me know in comments section.

Happy Programming 🙂

Salesforce Summer 17: Cool Seagulls in Summer

Hi everyone, we all know Salesforce release 3 updates for its system in a year.  Now Salesforce recently launched Summer 17. Summer is hot and in Rajasthan it’s very hot.  So here are few hot and exciting updates for everyone.

Summer_17_Release_Logo

  1. Use Advanced PDF to Render Visualforce Pages as PDF Files (Pilot)

Advanced PDF renders Visualforce pages as PDF files with broader support for modern HTML standards, such as CSS3, JavaScript, and HTML5. This change applies to both Lightning Experience and Salesforce Classic.

To use Advanced PDF, set renderAs=”advanced_pdf” in the tag of a Visualforce page with API version 40.0 or later. This process is similar to the existing process for rendering a Visualforce page as a standard PDF file.

PDF pages rendered with Advanced PDF are subject to the same limitations as legacy PDF pages, including the maximum page size and limited number of fetched resources. Advanced PDF pages also time out after rendering for 2 minutes, which includes asynchronous processing time.

  1. Roll Back Changes in Your Org When Remote JavaScript Methods Throw Exceptions

When a JavaScript method in an Apex class calling a remote action throws an exception, the action isn’t completed. Previously, when a method threw an exception, the action was completed.

For example, when you created an Apex class that used a remote action to add an account to your org and that method threw an exception, the account was added. Now, the account isn’t added. With this enhancement, JavaScript remoting methods that throw exceptions no longer cause changes in your org. This change applies to both Lightning Experience and Salesforce Classic.

  1. Cache Operations Supported in Visualforce Controllers

Cache operations made using the put and remove methods in the Cache Namespace are now supported in constructors and getter methods of Visualforce controllers.

  1. New Option for Parallel Testing on the isTest() Annotation

Use the @isTest(isParallel=true) annotation to indicate test classes that can be run in parallel and aren’t restricted by the default limits on the number of concurrent tests. This makes the execution of test classes more efficient, because more tests can be run in parallel.

  1. Deploy Changes Now Trigger Recompile of All Apex Code

All of an org’s Apex code is now automatically recompiled before completing a metadata deploy, a package install, or a package upgrade.

Previously, a deploy, install, or upgrade left the org with invalidated code, which sometimes caused recompilation errors when many Apex transactions occurred. This change in behavior improves performance following metadata deploys and package updates.

  1. Disable Access to Non-global Apex Controller Methods in Managed Packages (Critical Update)

This critical update corrects access controls on Apex controller methods in managed packages. When this update is enabled, only methods marked with the global access modifier are accessible by Lightning components from outside the package namespace. These access controls prevent you from using unsupported API methods that the package author didn’t intend for global access.

Prior to this update, non-global methods (that is, Apex controller methods that weren’t marked with the global access modifier) could be accessed by Lightning components outside of the package namespace.

  1. Metadata Access in Apex

If you’re an ISV creating apps that use custom metadata components, you can now access     metadata using Apex. This change applies to both Lightning Experience and Salesforce Classic.

During or after an install (or upgrade), your app can create or update metadata to let users configure your app. Use the new Metadata namespace for accessing metadata in Apex code. The Metadata namespace contains classes that represent metadata types and components as well as classes that let you retrieve or deploy metadata components in the subscriber org.

  1.   Salesforce Integrations: Taking Salesforce to the Next Level

Now you can connect Salesforce with Skype for Business , Gmail, Google Calendar and Microsoft Office 365. They are generally available in both Lightning and Salesforce classic. Nut some of them are only available in Lightning.

  1. Einstein Vision Is Now Generally Available

Sign up for Einstein Vision to receive 1,000 free predictions per calendar month. If you need more predictions, you can purchase them.

Getting an Einstein Platform account is the first step to accessing the API. Use the sign-up page to get an account. You can get an account in two ways.

  • Heroku—When you provision the Einstein Vision add-on, an Einstein Platform account is created for you.
  • Salesforce—Log in with your Salesforce credentials and create an account.

After you create an account, you download your private key file. Use this file to create an access token.

You can also try your hand on a Trailhead project to understand it better.

  1. Removed LockerService Restriction on instanceof in JavaScript

    Previously, Salesforce advised against using theinstanceof operator in JavaScript code when LockerService is activated. This restriction has been removed, except when checking arrays.

There are many more other update related to Lightning and Einstein. As I am also reading them in more details so I might make another post for them in depth. This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release.

Sign up now for a pre release org.

You can read release notes here. Let me know if I missed something here or if you want to add something then let me know in comments section.

IOT And AI: The future is here

Salesforce with 3 release in a year also introduce many more products from time to time to use the latest technology  to keep it system updated and fast. While the current major thing is Lightning, Salesforce recently introduce two more products and actively working on them. They are Internet of Thing and Artificial Intelligence.

As everyone is aware these two things are major part of IT industry and in upcoming year so salesforce Introduce them for its CRM.  So I everyone should start learning these technology because they are the future and as a Developer we need to keep ourself updated.

IOT: Salesforce IoT Cloud is powered by Thunder, a scalable event processing engine, designed to ingest and analyze billions of events. Events are the data that comes from the networked devices and objects we talked about above. On top of that, Thunder lets you take personalized actions based on these events, which help your company create more enriching and focused customer experiences.

salesforce-iot

IoT Cloud’s way of taking in data and triggering actions to create experiences lets your company focus on creating engaging, individualized experiences for all your customers. These might be customized alerts, emails, or messages. Or the actions might be something else within Salesforce, like creating a service ticket, or customizing the information they access through an app.

Imagine a world where you can react to real-time information, quickly creating these interactions with all your customers, so that the experiences feel personal, specific, and at the right time. Well, imagine no more. Buckle up for a quick flight to the land of IoT.

Artificial Intelligence:  AI is the concept of having “machines think like humans.” You’re starting to see examples of AI in your everyday life because we’re at an evolutionary tipping point. AI isn’t a new concept—we’ve had the theoretical models for a long time—but it’s finally possible thanks to the access and increase in large amounts of data combined with the low cost of high-power computing.

en-usc0d1ba1f59e62557189904ee48b34c4e

AI has benefits for all parts of the business. Sales reps no longer have to enter sales data manually. Marketers no longer have to use manual A/B testing to select the best social media images for their next campaign. And customer service managers no longer have to sift through long lists of incoming service calls to prioritize their time.

AI will impact each and every part of CRM and with Einstein  it will make many thing smooth as well because in the bunch of leads it will show most important Leads on top, Notify you to follow from customer and send them reminder email and many other things as well. AI will act like personal Assistance available at anytime anywhere in your fingertip. AI with CRM make Salesforce CRM a smart CRM.

So this is a brief idea of what IOT and AI is but in near future they play an important part and this will make them a must learn thing. So include them in your learning or TO DO list and let me know in comments what things you like most about these and what improvement you want to see in them.

Winter 17 is Here! A Quick Preview

Winter 17 is Here! A Quick Preview

Salesforce community is very busy these days. Dreamforce is near and everybody is preparing themselves for this mega event. As winter is here. So today I come up with 10 important feature of Winter 17

  1. Horizontal Navigation Comes to Lightning — One of the main initial features of Lightning, the collapsible side panel navigation, will be a thing of the past when Winter 17 goes live. This will be a big gain in efficiency and will ease the transition from Classic as it is similar to the Classic tabbed header. An awesome feature of the top navigation is when you hover over the tab name, you get a list of recent object records.
  2. Lightning Experience enhancements — Create Custom Apps in Lightning Experience and Navigate More Efficiently, Get Field-Level Help in Lightning Experience, Get Field-Level Help in Lightning Experience using save & New button
  3. Napili Is Now Called Customer Service (Napili) and it now supports more objects.
  4. Now you can use global search instead of Quick Find to find specific setup records, such as the Lead Source picklist or the Sales Rep profile. This feature is available in Lightning Experience only.
  5. Now you can create and manage your global picklist value sets from either user interface. No more switching back and forth to manage all of your picklists in Setup. Also Standard, multi-select picklists can be as detailed as you need them to be with a new limit of 255 characters per entry.
  6. The time window to quick-deploy your validations has expanded from 4 days to 10 days. This larger time window provides you more flexibility for scheduling your quick deployment and helps minimize the impact on your org.
  7. Build Reusable, Invocable Processes — This new feature will allow admins to create one Process and reuse it by invoking it from another Process. It’ll be available in Classic and Lightning editions.
  8. Inline Editing in List View Comes to Lightning —Lightning users will be able to hover over fields in a Listview and click to edit. This feature is in Beta and some restrictions will apply.
  1. Add the force:lightningQuickAction or force:lightningQuickActionWithoutHeader interface to a Lightning component to enable it to be used as a custom action in Lightning Experience or Salesforce1. You can use components that implement one of these interfaces as object-specific actions in both Lightning Experience and Salesforce1. You can use them as global actions only in Salesforce1.
  2. The Lightning Design System is now automatically added to your Lightning Out and Lightning Components for Visualforce apps. The Lightning Design System provides a look and feel that’s consistent with Lightning Experience.

 

Here are the 10 features which I found useful. I will keep updating this list whenever I found any useful feature in Winter 17 release notes. In the meantime you should give a read to Winter 17 notes and if found anything useful share them in comments. Cheers 🙂