Monday, 19 March 2018

Display SVG Icon in Lightning Component ( Lightning Component Helper)

Hi ,

To display icons from in lightning we have to follow the below steps.

1) Creating the Lightning Component with the name "svgIcon"

 Create a new Lightning component from the menu: File > New > Lightning Component

2)Paste the following the code

Click on the COMPONENT tab, then paste:

  <aura:attribute name="svgPath"        default="" type="String" description="the path for the icon in the static resource, this will be use in a SVG use tag" />
  <aura:attribute name="name"           default="" type="String" description="Symbol name of icon" />
  <aura:attribute name="class"          default="" type="String" description="the class of this SVG tag, can be use for CSS purpose" />
  <aura:attribute name="containerClass" default="" type="String" description="Container class name for span container of icon" />
  <aura:attribute name="category"       default="" type="String" description="Category of icon- action, standard, utility etc." />
  <aura:attribute name="size"           default="" type="String" description="Size of icon-- small, medium, large" />
  <aura:attribute name="assistiveText"  default="" type="String" description="Description name of icon" />
  <span aura:id="container" class="{!v.containerClass}">
    <span aura:id="assistiveText" class="slds-assistive-text">{!v.assistiveText}</span>

Click on the HELPER tab, then paste:

  renderIcon: function(component) {
    var prefix = "slds-";
    var svgns = "";
    var xlinkns = "";
    var size = component.get("v.size");
    var name = component.get("");
    var classname = component.get("v.class");
    var containerclass = component.get("v.containerClass");
    var category = component.get("v.category");

    var containerClassName = [
        ].join(' ');
    component.set("v.containerClass", containerClassName);

    var svgroot = document.createElementNS(svgns, "svg");
    var iconClassName = prefix+"icon "+prefix+"icon--" + size+" "+classname;
    svgroot.setAttribute("aria-hidden", "true");
    svgroot.setAttribute("class", iconClassName);
    svgroot.setAttribute("name", name);

    // Add an "href" attribute (using the "xlink" namespace)
    var shape = document.createElementNS(svgns, "use");
    shape.setAttributeNS(xlinkns, "href", component.get("v.svgPath"));

    var container = component.find("container").getElement();
    container.insertBefore(svgroot, container.firstChild);

Click on the RENDERER tab, then paste:

  render: function(component, helper) {
    // By default, after the component finished loading data/handling events,
    // it will call this render function this.superRender() will call the
    // render function in the parent component.
    var ret = this.superRender();

    // Calls the helper function to append the SVG icon
    return ret;

3.Use the New Component

Use your new component whenever you need an Lightning Design System SVG icon. For example, if your Static Resource is named SLDS you might use:

<c:svgIcon svgPath="/resource/SLDS/assets/icons/standard-sprite/svg/symbols.svg#user" category="standard" size="large" name="user" />

Example Component:

<aura:component >
<div class="slds-icon_container"> 
    <c:svgIcon svgPath="/resource/SLDS/assets/icons/standard-sprite/svg/symbols.svg#user" category="standard" size="large" name="user" />
    <div class="slds-icon_container"> 
    <c:svgIcon svgPath="/resource/SLDS/assets/icons/standard-sprite/svg/symbols.svg#account" category="standard" size="large" name="account" class="slds-icon"/>
     <div class="slds-icon_container"> 
    <c:svgIcon svgPath="/resource/SLDS/assets/icons/standard-sprite/svg/symbols.svg#contact" category="standard" size="large" name="contact" />



Tuesday, 27 February 2018

Test Setup Methods


Test setup methods can be time-saving when you need to create reference or prerequisite data for all test methods, or a common set of records that all test methods operate on.

We have to use "@testSetup" annotation to write test setup method.

Small Use Case for you:

Case is updating with an account when case is created with different scenarios.

Then for creating test class for the same requirement i have to create an account in each method for covering different scenarios in the logic.

But with "testsetup" method we can avoid creating the same account in multiple methods instead we can create once in testsetup method then we can utilize the same in all test methods.

@testSetup static void methodName() {


private class CommonTestSetup {

    @testSetup static void setup() {
        // Create common test accounts
        Account accountObj = new Account(Name='ABCD Account');
        insert accountObj;       
    @isTest static void testMethod1() {
       //Create case with a scenario it can take account data from the above test method to update on case based on your original logic to cover your code

    @isTest static void testMethod2() {
        //Create case with a scenario it can take account data from the above test method  to update on case based on your original logic to cover your code


If a test class contains a test setup method, the testing framework executes the test setup method first, before any test method in the class. Records that are created in a test setup method are available to all test methods in the test class and are rolled back at the end of test class execution. If a test method changes those records,such as record field updates or record deletions, those changes are rolled back after
 each test method finishes execution. The next executing test method gets access to the original unmodified state of those records.

Tuesday, 20 February 2018

Named Credentials

Hi ,

A named credential specifies the URL of a callout endpoint and its required authentication parameters in one definition. To simplify the setup of authenticated callouts, specify a named credential as the callout endpoint. If you instead specify a URL as the callout endpoint, you must register that URL in your org’s remote site settings and handle the authentication yourself. For example, for an Apex callout, your code would need to handle authentication, which can be less secure and especially complicated for OAuth implementations.

Salesforce manages all authentication for callouts that specify a named credential as the callout endpoint so that you don’t have to. You can also skip remote site settings, which are otherwise required for callouts to external sites, for the site defined in the named credential.

Named credentials are supported in these types of callout definitions:
§  Apex callouts
§  External data sources of these types:
o   Salesforce Connect: OData 2.0
o   Salesforce Connect: OData 4.0
o   Salesforce Connect: Custom (developed with the Apex Connector Framework)

By separating the endpoint URL and authentication from the callout definition, named credentials make callouts easier to maintain. For example, if an endpoint URL changes, you update only the named credential. All callouts that reference the named credential simply continue to work.
Named credentials support basic password authentication and OAuth 2.0. You can set up each named credential to use an org-wide named principal or to use per-user authentication so that users can manage their own credentials.

To reference a named credential from a callout definition, use the named credential URL. A named credential URL contains the scheme callout:, the name of the named credential, and an optional path. For example: callout:My_Named_Credential/some_path.
You can append a query string to a named credential URL. Use a question mark (?) as the separator between the named credential URL and the query string. For example: callout:My_Named_Credential/some_path?format=json.


In the following Apex code, a named credential and an appended path specify the callout’s endpoint.
HttpRequest req = new HttpRequest();
Http http = new Http();
HTTPResponse res = http.send(req);
The referenced named credential specifies the endpoint URL and the authentication settings.
Path:Setup->Administer->Security Controls-> Named Credentials

Named credential detail page
If you use OAuth instead of password authentication, the Apex code remains the same. The authentication settings differ in the named credential, which references an authentication provider that’s defined in the org.
Named credential authentiation settings with OAuth options
In contrast, let’s see what the Apex code looks like without a named credential. Notice that the code becomes more complex to handle authentication, even if we stick with basic password authentication. Coding OAuth is even more complex and is an ideal use case for named credentials.
HttpRequest req = new HttpRequest();

// Because we didn't set the endpoint as a named credential, 
// our code has to specify:
// - The required username and password to access the endpoint
// - The header and header information
String username = 'myname';
String password = 'mypwd';
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' +
req.setHeader('Authorization', authorizationHeader);
// Create a new http object to send the request object
// A response object is generated as a result of the request  
Http http = new Http();
HTTPResponse res = http.send(req);

Sunday, 7 May 2017

Reading Attachment ID's from CSV,retrieve from and Stores into the local folder using java


Here in the following example

We tried to explain how to read csv file which has attachment id's and then retrieving the related documents to local folder.
Use Case :
Developer gets one csv file with  attachment id's and those needs to be retrieved from and stores into local folder.

Please look into the comments you can uderstand the what is the code for reading id's from CSV file and qurying the same from and stores into local folder.

Import com.sforce.soap.enterprise.Connector;
Import com.sforce.soap.enterprise.EnterpriseConnection;
Import com.sforce.soap.enterprise.QueryResult;
Import com.sforce.soap.enterprise.sobject.Attachment;
Import com.sforce.soap.enterprise.sobject.Opportunity;
Import java.util.ArrayList;
Import java.util.List;
Import *;
Public class Retrieve3 {
Public static void main (String [] args) throws NumberFormatException, IOException, URISyntaxException {
/ * Reading CSV File which has attachement record Id's * /
List <String> documentIdSet = new ArrayList <String> ();
                        String csvFile = "D: /DemoFOlder/AttachmentIdSheet.csv";
String line = "";
                        String cvsSplitBy = ",";
                        Try (BufferedReader br = new BufferedReader (new FileReader (csvFile))) {
                            While ((line = br.readLine ())! = Null) {
                                // use comma as separator
                                String [] attachmentId = line.split (cvsSplitBy);

                                System.out.println ("attachmentId =" + attachmentId [0]);                            
documentIdSet.add (attachmentID [0]);
                            documentIdSet.remove (0);                        
                        } Catch (IOException e) {
                            e.printStackTrace ();
/ * End of Reading CSV File which has attachement record Id's * /
/ * Start of Retrieving the Documents from Salesforce and put them into LocalFolder * /
                    // Create a new connectionconfig to your Salesforce Org
                     ConnectorConfig sfconfig = new ConnectorConfig ();
                     // Use your salesforce username
                     sfconfig.setUsername ( "");                  
                     // Use your salesforce password with your security token look like:
                     sfconfig.setPassword ( "testXXXXXXX");                  
                     EnterpriseConnection partnercon = null;  
// create a salesforce connection object with the credentials supplied in your connectionconfig
Partnercon = Connector.newConnection (sfconfig);  
String strIds = "";
For (String ids: documentIdSet) {
((StrIds.equals "")) {if
StrIds = "'" + ids + "'";
else {
StrIds + = ", '" + ids + "'";
For (String ids: documentIdSet) {
QueryResult describeGlobalResult = partnercon.query ("select Id, Name, Body from Attachment where Id =" "+ ids +" '");
System.out.println (describeGlobalResult.getRecords () length.);              
Boolean done = false;
while (! done)
 For (int k = 0; k <describeGlobalResult.getRecords (). Length; k ++)

 Attachment a = Attachment describeGlobalResult.getRecords () [k];                    
 String fpath123 = "D: // DemoFOlder // Attachments";

 File path = new File (fpath123);
 String mySubFolder = a.getId ();          
 File newDir = new File (path + File.separator);        
 Boolean success = newDir.mkdirs ();          
 FileOutputStream fos = new FileOutputStream (newDir + File.separator + a.getId () + "-" + a.getName ());
 Fos.write (a.getBody ());
 Fos.close ();
 If (describeGlobalResult.isDone ()) {
Done = true;
 } Else {
  DescribeGlobalResult = partnercon.queryMore (describeGlobalResult.getQueryLocator ());
                     } Catch (ConnectionException e) {    
                        E.printStackTrace ();
/ * Endo of Retrieving the Documents from Salesforce and put them into LocalFolder * /

Wednesday, 2 November 2016

Getting Custom Field Id without hardcoding through Tooling API (Without Http Callout also)


We can get custom field ids for URL hacking to auto populate through Tooling API as shown below.

Apex Code:

List<FieldDefinition> fieldList =  [SELECT DurableId,QualifiedApiName FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName ='Account'and QualifiedApiName='NoofEmployees__c'];
String NoofEmployeesId = fieldList[0].DurableId.split('\\.')[1];

Visualforce Page (Java Script):

<script type="text/javascript">
            var __sfdcSessionId = '{!GETSESSIONID()}';
<script src="../../soap/ajax/38.0/connection.js" type="text/javascript"></script>
var qr = sforce.connection.query("SELECT DurableId,QualifiedApiName FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName ='Account'and QualifiedApiName='NoofEmployees__c'" );
              var NoofEmployeesId = qr.getArray("records")[0].DurableId.split('.')[1];

Thursday, 15 September 2016

Exposing an Apex Class as REST Web Service

Hi ,

We are going to learn how to write a REST webservice in

We can expose our Apex classes and methods so that external applications can access our code

and our application through the REST architecture.

 @RestResource annotation is used to expose a class as REST resource .

 Similarly we have to add annotations to methods to expose them throug REST like @HttpPost,@HttpGet etc.,

 If we add "@HttpGet" annotation for a method to expose it as a Rest resource then that can be called by Http GET request
 from external applications.

Sample Post Service:
global without sharing class StudentCreationcls {
    global static String createStudentRecord(DoctorServiceParser doctObj){
        Doctor__c doctorObj = new Doctor__c();
        doctorObj.Name =doctObj.Name;
        doctorObj.Salary__c = doctObj.Salary;
        doctorObj.Gender__c = doctObj.Gender;            
        Database.saveResult saveResult = database.insert(doctorObj,false);
            System.debug('Record Id:'+saveResult.getId());
        JSONGenerator gen=JSON.createGenerator(true);    
        gen.writeStringField('message','Doctor record is created Successfully');
        String responseString= gen.getAsString();
        return responseString;

Parser Class:
This class will be used for parsing the details in the request
global class DoctorServiceParser {

    global String Name{get;set;}
    global String FirstName{get;set;}
    global decimal consultationFee{get;set;}
    global String LastName{get;set;}
    global decimal Salary{get;set;}
    global String Gender{get;set;}

Our service endpoint will be :https://hostnamesalesforce/services/apexrest/DoctorService

Request Format for this:

We can execute this in rest Explorer of workbench for validating before we are going to give for exteranl applications.


Saturday, 3 September 2016

Excellent C ,C++ ,Java ,Photo Shop Tutorias

Hi Guys,

Please find the below url for excellent tutorials of C,C++,Java ,Photo Shop Tutorials.

Contact Details :

Sri Sai Computer Education

Phone:+91 9885094573,7386972889 ,

Andhra Pradesh (state),
India(country) -- 516001.