function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michael MMichael M 

Get user's current URL with Flow or apex

Hello, is it possible to use a lightning flow to get the user's current url (equivalent of javascript's window.location.href), using  a lightnign flow? If not, is it possible with apex (not visualforce)?
Best Answer chosen by Michael M
AbhishekAbhishek (Salesforce Developers) 
https://webkul.com/blog/how-to-get-current-page-url-from-apex-code/

Your code is answered above.


Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.

All Answers

AbhishekAbhishek (Salesforce Developers) 
https://webkul.com/blog/how-to-get-current-page-url-from-apex-code/

Your code is answered above.


Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.
This was selected as the best answer
Michael MMichael M
Great- thank you!  Now I am trying to use that in a middle of an einsteni bot dialogue. It doesn't seem to be working-- any idea why? here is my code, which I am invoking from my einstein bot dialogue:

public with sharing class BotUrlClass {
public class TranscriptInput {
    @InvocableVariable(required=true)
    public ID routableID;
  }
  
  public class VisitorUrlOutput {
    @InvocableVariable(required=true)
    public String urlOfMostRecentPage;
      
  }
 
  @InvocableMethod(label='Get User URL')
  public static List<VisitorUrlOutput> getUrlName(List<TranscriptInput> transcripts) {
 
    List<VisitorUrlOutput> urls = new List<VisitorUrlOutput>();
  
    for (TranscriptInput transcript : transcripts) {
    
      // Query for the transcript record based on the ID
      LiveChatTranscript transcriptRecord = [SELECT Name, URL__c
                                             FROM LiveChatTranscript 
                                             WHERE Id = :transcript.routableID 
                                             LIMIT 1];
        
        string headerdata2= ApexPages.currentPage().getHeaders().get('Host');
        string urlvalue2=Apexpages.currentPage().getUrl();
        string url2='https://' + headerdata2+ urlvalue2;  
        
      
      // Store the url in an output variable
      VisitorUrlOutput urlData = new VisitorUrlOutput();
      urlData.urlOfMostRecentPage = url2;
      
      // Add the url to the list of outputs
      urls.add(urlData);
    }
    
    return urls;
  }
}
AbhishekAbhishek (Salesforce Developers) 
Micheal I have to check.

Please create a new question me or my team will look into and answer your query.
Michael MMichael M
ok- thank you
Nithin SinkaranNithin Sinkaran
Hi Abhishek  
How does this integrate with Screen Flow? I am unable to get value forApexpages.currentPage() which always gives null and throws attempts to dereference a null object.