• Adam Drissel 1
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies
Please help quickly!

I have looked everywhere and I cannot find a way to add a link on our Agent Console to allow our customer support agents to click and get directly to the Lightning App.  Currently this is what they see:

User-added image

When they click on that link it opens up a VF page, which then opens up a Flow:

User-added image

I tried creating a simple VF page that performs a jQuery redirect to the Lightning App url:
 
<apex:page showHeader="false" sidebar="false">
  <apex:includeLightning />
  <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"/>
  <script type="text/javascript">
      $(document).ready(function(){
          window.location.href="https://lmi--drissel.lightning.force.com/c/Case_QuickCreateApp.app";
      });
  </script>
  <body onload="load();"></body>
</apex:page>

But when that button is clicked in the Console it brings up this:

User-added image

A blank page.

Please help!  I really need my agents to be able to click through to the app right from the Console.
I am trying to make a call to the REST Api from my Lightning Component.  There is a section in the Lightning Components Developer Guide specifically addressing this:

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_api_calls_platform.htm?search_text=api%20call

The relevant portion states: "Sometimes, you have to make API calls from server-side controllers rather than client-side code. In particular, you can’t make calls to Salesforce APIs from client-side Lightning component code. For information about making API calls from server-side controllers, see Making API Calls from Apex."

When you click on that link it takes you to the following portion of the Lightning Components Developer Guide (please note that ALL of this is thus far in the Lightning developer guide):

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/apex_api_calls.htm#apex_api_calls

The relevant portion there is "To call Salesforce APIs, make the API calls from your component’s Apex controller. Use a named credential to authenticate to Salesforce." 

In the middle section on that page it states: "By security policy, sessions created by Lightning components aren’t enabled for API access. This prevents even your Apex code from making API calls to Salesforce. Using a named credential for specific API calls allows you to carefully and selectively bypass this security restriction."

This seems to read very simple.  If you want to make an API call from your Lightning component, you need to do so from the Lightning Apex Controller, and make sure you use a Named Credential to authenticate.  Here is my named credential data (details on setup found here: https://developer.salesforce.com/docs/atlas.en-us.208.0.apexcode.meta/apexcode/apex_callouts_named_credentials.htm)

User-added image
My setup is identical to the one in the Apex Developer Guide (linked above).  Here are the relevant portions of my Lightning code:

Component
<aura:component implements="force:appHostable" controller="Case_QuickCreateController">    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>

Lightning Controller
({    
    doInit : function(component, event, helper){
        helper.callApi(component);
	}
})

Lightning Helper
({
    callApi: function(component) {
        var action = component.get("c.callRestApi");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS" && response.getReturnValue() != '') {
                // "populate data here"
            }
            else if(state === "ERROR"){
                console.log('A problem occurred: ' + JSON.stringify(response.error));
            }
        });
        
        $A.enqueueAction(action);
    }
})

Apex Controller
public with sharing class Case_QuickCreateController {
	@AuraEnabled
    public static String getSFDCInstance(){
        return System.URL.getSalesforceBaseURL().toExternalForm();
    }

	@AuraEnabled
    public static void callRestApi(){
        String instance = getSFDCInstance();
        String url = 'callout:LightningAPICallout/services/data/v40.0/sobjects/Case/describe?format=json';
        
        Http h = new Http();
        
        HttpRequest req = new HttpRequest();       
        req.setEndpoint(url);
        req.setMethod('GET');
        
        HttpResponse res = h.send(req);
        String body = res.getBody();
        
        system.debug(body);
    }
}

The resulting HttpResponse and message in the Debug Log are:
System.HttpResponse[Status=Unauthorized,StatusCode=401]

{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}

I am following all of the documentation to a "T".  Why am I still not getting a valid session Id and subsequently being authorized?

Please help ASAP!
 
When I make a call to the API (code below) I get the following error message returned:
System.HttpResponse[Status=Unknown Version, StatusCode=400]

Here is the code I am using:
public static void callRestApi(){
        String instance = getSFDCInstance();
        String sessionId = getSessionId();
        String url = instance+'/services/data/v37.0/sobjects/Case/describe/ -H \"Authorization: Bearer'+sessionId+'\"';
        
        system.debug(url);
        
        Http h = new Http();
        
        HttpRequest req = new HttpRequest();        
        req.setEndpoint(url);
        req.setMethod('POST');
		req.setHeader('Charset', 'UTF-8');
        req.setHeader('Content-Type', 'text/plain');
        
        system.debug(req);
        
        HttpResponse res = h.send(req);
        String body = res.getBody();
        
        system.debug(body);
    }

​I've tried a "GET" call as well and get the same exact response.  What "version" is unknown?  My URL is formatted exactly as the Salesforce REST API documentation has it.

Please help ASAP.
When I make a call to the API (code below) I get the following error message returned:
System.HttpResponse[Status=Unknown Version, StatusCode=400]

Here is the code I am using:
public static void callRestApi(){
        String instance = getSFDCInstance();
        String sessionId = getSessionId();
        String url = instance+'/services/data/v37.0/sobjects/Case/describe/ -H \"Authorization: Bearer'+sessionId+'\"';
        
        system.debug(url);
        
        Http h = new Http();
        
        HttpRequest req = new HttpRequest();        
        req.setEndpoint(url);
        req.setMethod('POST');
		req.setHeader('Charset', 'UTF-8');
        req.setHeader('Content-Type', 'text/plain');
        
        system.debug(req);
        
        HttpResponse res = h.send(req);
        String body = res.getBody();
        
        system.debug(body);
    }

​I've tried a "GET" call as well and get the same exact response.  What "version" is unknown?  My URL is formatted exactly as the Salesforce REST API documentation has it.

Please help ASAP.
Hello Experts,

I want someone to put some light to teh new feature introduced by salesforce Named credential

My scenario is somethign like this:
1.I have a rest based webservice in target org which i am invoking through source org
2.I have created named credential in source org as shown below
User-added image
3. Further in my code that invokes the webservice i have written the below satatements:
HttpRequest req= new HttpRequest();

String reqBody='{"vEmail":"'+email+'",'+'"vSubject":"'+subject+'",'+'"vDate":"'+dt+'"}';
		req.setEndpoint('callout:ExternalPortalCreds');
		req.setMethod('POST');
		req.setBody(reqBody);
		Http http=new Http();
		HttpResponse res= http.send(req);

However this gives error as Session expired or invalid session id. How do i get the session id if i want to use named credential in my code?
Any help would be appreciated

Regards
Neha