Canvas allows developers to connect existing legacy system or any web-based application with Salesforce
using javascript and REST API.Canvas applications can be displayed in chatter,Salesforce Mobile Cards or Visualforce Page.
ex :
<apex:page controller="JSONGeneratorSample">
<apex:canvasApp developerName="mycanvas" parameters="{!generateJSON}" />
</apex:page>
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global" >
<div class="canvas-container">
<force:canvasApp developerName="mycanvas" height="1200px"/>
</div>
</aura:component>
Canvas App in Salesforce :
Canvas enables you to easily integrate a third-party application in Salesforce.
Canvas is a set of tools and javascript APIs that you can use to expose an application as a canvas app.
This means you can take your new or existing applications and make them available to your users as part of their Salesforce experience.
Canvas App Previewer :
Canvas App Previewer is a development tool that lets you see what your canvas apps will look like before you publish them.
Note :
The third-party app that you want to expose as a canvas app can be written in any language.
The only requirement is that the app has a secure URL (HTTPS).
Important Entity :
1.Authentication
2.Context
3.Cross-domain XHR
4.Events
5.Canvas Apps in Visualforce
canvas app is also a kind of connected app.you can consider canvas app as connected app
with some enhanced features to make it work seamlessly with external apps within Salesforce UI.
Some of these additional features are :
1.canvas app settings has 'Access Method' option which simplifies the way your connected app is
getting authenticated and authorized. This is important when you want to have your canvas app do
aurhentication and authorization behind the scene without having user know about it.
2.Canvas app frameowork provides LightWeight and easy-to-use javascript libraries.
3.Canvas app frameowork natively provides 'Context Services' which tells more about the logged-in user,
what org are they in,how much area does the canvas provide to display etc.
4.It natively allows cross-domain API calls.
5.It is based on lightweight JSON eventing frameowork which allows your app to publish and
subscribe to events.(the events are sent through Canvas API).
Important Parameters :
Authentication - signed request or OAuth 2.0.
Context
Cross-domain cross-domain XML HTTP requests
Resizing -M
Events - Events prvide a javascript-based way to send and receive events between canvas apps.
Canvas Apps in Aura
Canvas Apps in Visualforce
Canvas Apps in the publisher
Canvas Apps in the Chatter Feed
Canvas in the Salesforce Mobile App
Canvas can be placed in Salesforce :
1.Chatter feed
2.Chatter tab
3.Console
4.Visualforce Page
5.Layouts and Mobile Cards
6.Mobile Nav
7.Open CTI
8.Publisher
Authentication and Permission :
1.Permission
"Customize Application"
"Modify All Data"
2.Authentication
1.Signed request
2.Oauth2.0
How does canvas work ?
1.User clicks on the application from a chatter tab or Visualforce Page.
2.A signed Post request is sent to the external application.
3.External application decodes signed request,obtaining canvasRequest object.
4.External application returns HTML that is loaded into the Salesforce UI.
5.User interacts with external application page within Salesforce.
6.External application page calls out to containing frame's javascript SDK.containing page calls Salesforce.
7.External application interacts through standard APIs.
Note :
1.Canvas apps are loaded into salesforce through an iframe.
2.with canvas you can use a secure communication protocol via javascript to communicate with salesforce.
Access method :
The Force.com Canvas Framework provides authentication into salesforce.
1.Signed Request(POST)
2.OAuth Webflow (GET)
CanvasLifecycleHandler:
Note :
Apex LifeCycle Handler : Controlling your Force.com Canvas context.
Customizing the Canvas Signed Request :
Signed Request : Delivering Context to your App.
The signed request is the default (and recommended) access method.
when you click the Canvas app, we Post a signed equest to your endpoint.
Context contains data like :
1.Client information
OAuth Token,Refresh Token,Oauth login URLs
2.User Information
Name,Username,ID,Email etc
3.Organization Information
Name,ID,MNamespace etc.
4.Environment Information
Dsiplay Location,Dimensions,Parameters,Record info etc.
5.Version Information
6.Useful Links
Controlling Signed Request using CanvasLifecycleHandler :
1. Using Apex to control your signed request.
2.Apex class is associated with the Canvas App.
3.You can control
-> Remove certain Signed Elements.
-> Customizing Parameters/Customize Record Fields.
-> Customizing the Canvas URL
-> Custom Error Handling
ex
public class MyCanvasListener implements Canvas.CanvasLifecycleHandler{
public Set<Canvas.ContextTypeEnum> excludeContextTypes(){
Set<Canvas.ContextTypeEnum> excluded = new Set<Canvas.ContextTypeEnum>();
excluded.add(Canvas.ContextTypeEnum.ORGANIZATION);
excluded.add(Canvas.ContextTypeEnum.USER);
excluded.add(Canvas.ContextTypeEnum.RECORD_DETAIL);
return excluded;
}
public void onRender(Canvas.RenderContext renderContext){
Canvas.ApplicationContext app = renderContext.getApplicationContext();
Canvas.EnvironmentContext env = renderContext.getEnvironmentContext();
Double currentVersion = Double.valueOf(app.getVersion());
if (currentVersion <= 5){
throw new Canvas.CanvasRenderException('Error: Versions earlier than 5 are no longer supported.');
}
app.setCanvasUrlPath('/alternatePath');
env.addEntityFields(new Set<String>{'Name','BillingAddress','YearStarted'});
Map<String, Object> previousParams =(Map<String, Object>) JSON.deserializeUntyped(env.getParametersAsJSON());
previousParams.put('newCustomParam','newValue');
env.setParametersAsJSON(JSON.serialize(previousParams));
}
}
Custom Error Handling :
with the apex lifecycle handler, you can inject your own error handling.
-> Error handling logic exists inside of the apex class.
-> Error is displayed in the Canvas error handling framework.
No comments:
Post a Comment