• Venkat Dodla
  • NEWBIE
  • 5 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
I have a question on how to convert an Article URL mentioned below to that of the Article Title as an hyperlink. 
Article URL: https://Domain/lightning/r/Knowledge__kav/kA0SKWN0005WoRKAU/view (https://urldefense.proofpoint.com/v2/url?u=https-3A__BaseURL_lightning_r_Knowledge-5F-5Fkav_kA0SKWN0005WoRKAU_view&d=DwQFaQ&c=WlnXFIBCT3pmNh_w8hYeLw&r=j5d5-cF1KHg1HqDDS_kuy_27r5YVKNvDb545SWhOoJw&m=ssyyfr7pp8xSSZoYxuFGeXE0g40TQU6-th9aw-YHHS0&s=mRxSl0Iecr5_QkxM-Cf1XAdlzVxBKDnOF61-7NX-66s&e=" style="color:blue; text-decoration:underline)
I have a lightning button (code shared below) when clicked will copy the above URL so that the user can share the URL with their co-workers. I had completed achieving until here.
What I am looking currently is, to find out a way to copy the Article Title as a hyperlink that way user can share the Article title in an email which is readable. Once user click on the Title hyperlink, it will route the user to the online published version of the Article as mentioned above. 

I have went through below links in-order to find way and placed my findings at end of each link:
1) https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_str_link (https://urldefense.proofpoint.com/v2/url?u=https-3A__www.w3schools.com_jsref_tryit.asp-3Ffilename-3Dtryjsref-5Fstr-5Flink&d=DwQFaQ&c=WlnXFIBCT3pmNh_w8hYeLw&r=j5d5-cF1KHg1HqDDS_kuy_27r5YVKNvDb545SWhOoJw&m=ssyyfr7pp8xSSZoYxuFGeXE0g40TQU6-th9aw-YHHS0&s=wzJR3EH4F2S3PvVgNTl78hWV_iB9d7fSGYI2FWuNnEw&e=" style="color:blue; text-decoration:underline)  (This is exactly what I looking for but the str.link function is not working in Controller JS and this is how it is performing: <a href="https://BaseURL/lightning/r/Knowledge__kav/kA0SKWN0005WoRKAU/view">Test (https://urldefense.proofpoint.com/v2/url?u=https-3A__BaseURL_lightning_r_Knowledge-5F-5Fkav_kA0SKWN0005WoRKAU_view-2522-253ETest&d=DwQFaQ&c=WlnXFIBCT3pmNh_w8hYeLw&r=j5d5-cF1KHg1HqDDS_kuy_27r5YVKNvDb545SWhOoJw&m=ssyyfr7pp8xSSZoYxuFGeXE0g40TQU6-th9aw-YHHS0&s=nrVk3r4xYrLZh4b3OiH9CrCp0aNNZoAUuUzva0W6vpo&e=" style="color:blue; text-decoration:underline) Copy URL</a>)
2) https://developer.salesforce.com/docs/component-library/bundle/lightning:formattedUrl/documentation (https://urldefense.proofpoint.com/v2/url?u=https-3A__developer.salesforce.com_docs_component-2Dlibrary_bundle_lightning-3AformattedUrl_documentation&d=DwQFaQ&c=WlnXFIBCT3pmNh_w8hYeLw&r=j5d5-cF1KHg1HqDDS_kuy_27r5YVKNvDb545SWhOoJw&m=ssyyfr7pp8xSSZoYxuFGeXE0g40TQU6-th9aw-YHHS0&s=fO9NR3Alr9xfI9WwJ3x1UEr0RNjmpk9t6BL7umkyXXQ&e=" style="color:blue; text-decoration:underline) (I am able to convert the Article title as hyperlink  like <lightning:formattedUrl value="https://salesforce.com" (https://urldefense.proofpoint.com/v2/url?u=https-3A__salesforce.com-2522&d=DwQFaQ&c=WlnXFIBCT3pmNh_w8hYeLw&r=j5d5-cF1KHg1HqDDS_kuy_27r5YVKNvDb545SWhOoJw&m=ssyyfr7pp8xSSZoYxuFGeXE0g40TQU6-th9aw-YHHS0&s=78FXqRq7qB4a7YtbHCCG8z549HFUyp1z5pAB5DH0Q8c&e=" style="color:blue; text-decoration:underline) label="{!articleTitle}"/> but this is showing as title on Article page. I do not want to display it rather want to read the hyperlink value and pass it over to Controller JS that way I can pass it over the Helper.JS)
3) Also tried using record.linkName = '/'+record.Id; from the following link but no luck : https://www.infallibletechie.com/2018/07/how-to-hyperlink-record-in.html (https://urldefense.proofpoint.com/v2/url?u=https-3A__www.infallibletechie.com_2018_07_how-2Dto-2Dhyperlink-2Drecord-2Din.html&d=DwQFaQ&c=WlnXFIBCT3pmNh_w8hYeLw&r=j5d5-cF1KHg1HqDDS_kuy_27r5YVKNvDb545SWhOoJw&m=ssyyfr7pp8xSSZoYxuFGeXE0g40TQU6-th9aw-YHHS0&s=Cr8BdtbFwdsMPW6hyIWjR0Y1IoFPxJxpdAvK84BHQx0&e=" style="color:blue; text-decoration:underline)
Here is the code that I have so far:
Component.cmp:
            <div>
                <!-- Create Copy URL button-->
                <lightning:button onclick="{!c.copyArticleURL}" label="Copy Shortcut">
                </lightning:button>
            </div>
Controller.js:
    copyArticleURL: function(cmp, event, helper){
        var url = location.href;  // entire url including querystring
        var baseURL = url.substring(0, url.indexOf('/', 14));

        var action = cmp.get("c.getVersionID_CopyURL");
            action.setParams({"articleId":cmp.get("v.recordId"),});
            action.setCallback(this,function(response){
            var state = response.getState();
            var cntlrResponse=response.getReturnValue();
            var ArtOnlineVersionID = cntlrResponse.KnowledgeArticleId;
            var copyURL = baseURL + "/lightning/r/Knowledge__kav/"+ArtOnlineVersionID+"/view";
             helper.copyTextHelper(cmp,event,copyURL);
        });
          $A.enqueueAction(action); 
    },
Helper.JS:
    copyTextHelper : function(component,event,text) {
        // Create an hidden input
        var hiddenInput = document.createElement("input");
        // passed text into the input
        hiddenInput.setAttribute("value", text);
        // Append the hiddenInput input to the body
        document.body.appendChild(hiddenInput);
        // select the content
        hiddenInput.select();
        // Execute the copy command
        document.execCommand("copy");
        // Remove the input from the body after copy text
        document.body.removeChild(hiddenInput); 
},
APEX Class:
Public static Knowledge__kav getVersionID_CopyURL(String articleId)
    {
        Knowledge__kav KA = new Knowledge__kav();
        if(articleId!=null)
        {
            for(Knowledge__kav kv1:[select Id,Title,KnowledgeArticleID from Knowledge__kav where Id =:articleId limit 1])
                KA = Kv1;
        }
        return KA;  
    }
Kindly share your thoughts if you have it. Appreciate your help and support.
Hi Friends,

I have below code that statically passes value from VF Page to controller when a button is clicked. I am looking code to provide 2 input fields like name and phone no. and have user type the value into these field and when user clicks on submit button, the values should be sent to controller.
Thanks for your time and help.

APEX Controller:
Global class RemoteActionCall_Controller {
  //Variable under test
    public static String valuefromJS {get; set;}
    
    @RemoteAction
    global static void someMethod(String parameter){
       
        valuefromJS = parameter;
        System.debug(valuefromJS);
        
     //   return null;
    }
}
VF Page for performing RemoteAction:
<apex:page id="myPage" controller="RemoteActionCall_Controller">
    <!-- Include JQuery in the page -->
    <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
    <style type="text/css">
        .pointer
        {
        cursor:pointer;
        border:1px solid #ccc;
        padding:5px;
        }
    </style>
    
    <script type="text/javascript">
        function sendVariable(parameter){        
        
        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.RemoteActionCall_Controller.someMethod}',
            parameter, 
            function(result, event){
                if (event.status) {
                    //do something here
                    console.log('Oh Ya');
                }
            },
            {escape: true}
        );
    }
    </script>
    
    <apex:form >                
        <!-- Command button to set the value -->
        <apex:commandButton value="Set Value" onclick="sendVariable('New Value'); return false;" />
    </apex:form>
</apex:page>
Hi Friends,

I have below code that statically passes value from VF Page to controller when a button is clicked. I am looking code to provide 2 input fields like name and phone no. and have user type the value into these field and when user clicks on submit button, the values should be sent to controller.
Thanks for your time and help.

APEX Controller:
Global class RemoteActionCall_Controller {
  //Variable under test
    public static String valuefromJS {get; set;}
    
    @RemoteAction
    global static void someMethod(String parameter){
       
        valuefromJS = parameter;
        System.debug(valuefromJS);
        
     //   return null;
    }
}
VF Page for performing RemoteAction:
<apex:page id="myPage" controller="RemoteActionCall_Controller">
    <!-- Include JQuery in the page -->
    <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
    <style type="text/css">
        .pointer
        {
        cursor:pointer;
        border:1px solid #ccc;
        padding:5px;
        }
    </style>
    
    <script type="text/javascript">
        function sendVariable(parameter){        
        
        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.RemoteActionCall_Controller.someMethod}',
            parameter, 
            function(result, event){
                if (event.status) {
                    //do something here
                    console.log('Oh Ya');
                }
            },
            {escape: true}
        );
    }
    </script>
    
    <apex:form >                
        <!-- Command button to set the value -->
        <apex:commandButton value="Set Value" onclick="sendVariable('New Value'); return false;" />
    </apex:form>
</apex:page>
Hi,
I am not able to understand the below question correctly Please help me out. - 
Create a class that has a method accepting two strings. The method searches for contacts that have a last name matching the first string and a mailing postal code (API name: MailingPostalCode) matching the second. It gets the ID and Name of those contacts and returns them.The Apex class must be called 'ContactSearch' and be in the public scope.
The Apex class must have a public static method called 'searchForContacts'.
The 'searchForContacts' method must accept two incoming strings as parameters, find any contact that has a last name matching the first, and mailing postal code matching the second string. The method should return a list of Contact records with at least the ID and Name fields.
The return type for 'searchForContacts' must be 'List<Contact>'.