Saturday, September 14, 2019

A  question why lightning web component when developer already invested efforts in learning lightning component (aura component)?

lwc is based on standard web component that uses native browser technology or standard web technology modern Javascript ,html and CSS.
The benefit is to make things open to other platform  and  salesforce approach is also contributing towards develop open web standards.

earlier we were having lightning component based on aura component programing modal which  support ES5 and few feature of ES6(unable to find document what exact feature but it look like just promise from ES6)
where as lwc is using ES6+ advance javascript or modern Java script which make more sense to go for technology upgrade adoption.

Co- existance of aura and lightning
Many of us having question if lwc and LC(aura component) can co exist? Answer is yes but with a understanding of  Facet and slot

also as per understanding lightning aura can contain lwc but vice versa doesn't hold true https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.migrate_decide

now let's have look at composition structure ":"and "-"

lets talk about base component in side aura component

g:reco
rdform>
now lets have a look at lwc base component

namespace:component lightning:Card (lightning base component)
namespace-component lightning-card (lwc)

also lightning aura can contain lwc but vice versa doesn't hold true
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.migrate_decide

to be continued .......

Wednesday, April 25, 2018

Creating Multiple Record in single rest request -Composite API

Hi

we have seen how can we create a record using  single rest request using OOB rest feature as below
/services/data/v40.0/sbjects/account

Method - POST
Body  - JSON
{
  "Name" :"testaccount"
}

Response will return with Id-
{
"Id":"001xxxxxxxxxxx"
}


Now if there is a need to insert data in tree structure in single request then which OOB Rest API need to follow, For this purpose we have Composite Tree API
Account -->contact (need to inset account and Contact in single oob rest req)
Here you go for tree API -
Url- /services/data/v41.0/composite/tree/account(Considering account to be parent node)
Method -Post
Body-
{
"records" :[{
    "attributes" : {"type" : "Account", "referenceId" : "ref1"},
    "name" : "ACC1",
    "phone" : "1234567890",
    "website" : "www.testtst.com",
    "industry" : "Banking",
    "Contacts" : {
      "records" : [
        {
         "attributes" : {"type" : "Contact", "referenceId" : "ref2"},
         "lastname" : "TestFname",
         "Title" : "TestLName",
         "email" : "sample@test.com"
         },
         {
         "attributes" : {"type" : "Contact", "referenceId" : "ref3"},
         "lastname" : "TestDLname",
         "title" : "Dev",
         "email" : "sample@testdev.com",
         "Camping_Item__r" :
             {
                "records" : [{
                "attributes" : {"type" : "Camping_Item__c", "referenceId" : "refCamping"},
                "name" : "mohicamplist"
                }]
             }
         }]
      }
    }]
}

Now the above example shows how can we create a tree structure(account-->contact-->campinglist) in single rest call  which will take automatic references from parent to child record.


Now what if we need to create record in tree structure with population of references from parent to child dynamically- Then Composite request is solution .

-In this approach a series of rest request executes in a single call

Url-
/services/data/v41.0/composite/

{
"compositeRequest" : [
  {
  "method" : "POST",
  "url" : "/services/data/v38.0/sobjects/Account",
  "referenceId" : "refAccount",
  "body" : { "Name" : "mohit composit1 Acc" }
  },
  {
  "method" : "POST",
  "url" : "/services/data/v38.0/sobjects/Contact",
  "referenceId" : "refContact",
  "body" : {
    "LastName" : "Sample composit Contact1",
    "AccountId" : "@{refAccount.id}"
    }
  },
  {
  "method" : "POST",
      "url" : "/services/data/v38.0/sobjects/Camping_Item__c",
       "referenceId" : "campingitem",
        "body" : {
        "name" : "ampingFnl",
        "Account__c" : "@{refAccount.id}",
         "Contact__c" : "@{refContact.id}",
         }
  } ]
}








Wednesday, August 26, 2015

Apex Class Version Control Eclipse Salesforce

As per business , Now Source code management has become viable for successful implementation where team is collaborating .In a Cloud collaboration environment ,where team is putting efforts to minimize daily basis overhead regarding code and its version who did what and when.

so here are how we can maintain source code version  in cloud.

Initial Set Up:

 Source Code repository
         Create SVN repository for source code : (visit:   https://www.assembla.com/subversion/)

  Configuring SVN In Eclipse: 
      Here are some steps through which you can easily setup  SVN tool in Eclipse:
  
  1.  Go to Eclipse
  2. Eclipse--> Help Tab
  3. Click on Eclipse MarketPlace
  4. Search for "Subclipse"  (its a plugin to maintain version)
        Popup window will open--->Click on Install
      5.Click on finish
      6.Warning Message will Appear---> Click on Ok ,after reading message.Eclipse will restart.







        7. Now on Eclipse : Click on "Open Perspective" icon as shown below,PopUp window will open 
          showing "SVN Repository Exploring",Right Click  on "SVN Repository Exploring"--->Click on new-->
         Popup window will open  to add "SVN Repository" -->add Repository URL as specified in Image
          -->On Click on finish button--> Now you are up with SVN :)
         


              





         






 8. Now open existing force.com project

    Right Click on Project -->Go to Team-->share-->select SVN --Click on Commit

,add your comment and done.

9. Setup your Team, and their credential in  www.assembla.com.
10. Now you are up for check-in check-out/lock /unlock in eclipse for apex classes
/triggers.
    












     
   1c7e927dc4de2fc54f11a482950666a1c9a23f41124bfad450

Monday, June 8, 2015

Resolving Selective/Non-Selective Issue with Query Plan


OverView :
Query Plan tool is analytical tool which  helps in increasing query performance in the system.As a developer i ran into issue where i have faced "Selective /Non-Selective Exception"."Selective /Non-Selective Exception" which states how much data we are going to hit and  result(#No of records going to reterive).Salesforce Architecture is something which enforce optimum use of resources does'nt matter whether character in class/custom field or rollup field limitation.

Enable : Query Plan
              Open Developer Console --->Help--->Preferences--->Enable query Plan

@Bottom of developer console --> Option for query Plan.

Understanding Query Plan :
Cardinality
The estimated number of records that the leading operation type would return. For example, the number of records returned by an index.
Fields
 The indexed field(s) used by the query. 
 If query has Index field : 
    Fields : Indexed Field else null
LeadingOperationType
The primary operation type that Salesforce will use to optimize the query.
  • Index - The query will use an index on the query object.
  • Other - The query will use optimizations internal to Salesforce.
  • Sharing - The query will use an index based on the sharing rules associated with the user who is executing the query. If there are sharing rules that limit which records that user can access, Salesforce can use those rules to optimize the query.
  • TableScan - The query will scan all records for the query object.
Notes
An array of one or more feedback notes. Each note contains:
  • description - A detailed description of an aspect of the optimization. This could include information on optimizations that could not be used, with details on why the optimization was not used.
  • fields - An array of one or more fields used for the optimization.
  • tableEnumOrId - The table name for the fields used for the optimization.
This response field is available in API version 33.0 and later.
RelativeCost : It is cost (Selectivity Threshold) of query as compared to or relative to force.com native query Optimizer
   If Cost  Value  >1 mean that the query won’t be selective.(Red Signal): May Hit exception 
  It must be <1 and preffered value is : 0.0n....(0.024 etc) n (Green Signal ) No Exception
SobjectCardinality:
The approximate record count for the query object.


Note: Using Index field in query may not always resolve "Selectivity /Non-Selectivity Issue".In some cases have to use 2nd index field check the cost .

Key Point :

Try And Clause with Custom Index avoid ORING In Query
Avoid !=(-ve Operator)

In Case :If You are using multiple OR Clause  in Query:Try to make  OR Condition  selective individually.
Ex:

OR (A) OR (B) OR (C)
A: Selective with use of index or by other mean
B: Selective with use of index or by other mean
C: Selective with use of index or by other mean



Note : Technical Resource

https://developer.salesforce.com/page/Developing_Selective_Force.com_Queries_through_the_Query_Resource_Feedback_Parameter_Pilot

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_query_explain.htm











Wednesday, May 20, 2015

Sneak into Writing Test Classes

On a sunny day , working from my apartment Balcony :
working on test classes project i have to struggle for code coverage,Though it is said to be simple task but some times found people juggling with obtaining coverage .i would like to introduce some challenges that every developer faces:

a) if a object have many lookup and some complex trigger/classes structure may hit too many soql
b)After trying so many combination of conditional block  can lead  no +ve in code coverage.
c)May hit developer time span to write test class leading migration activity delay
d)In efficient code coverage without writing unit  test for  +ve and -ve scenario.
e) Improper Exceptions Handling


Here are ways to handle:

a/b) If object may have multiple lookups and complex structure with triggers/classe :
-do not provide all lookup at a time since lookup population may be distributed as business

for example : If custom object "aa__c" have lookup let suppose account/contact/case/....it is possible aa__c record may have account/contact for some business and for other business account with other lookup.

So Break single method in multiple as in 1 : populate two lookup or as per your convience in 2: other two....this should be staritgey .

Cover method code in start test/stop test

b) if calling Class method from trigger: in a complex situation while writing test if method not calling -->call that method within testclass while passing argument.

trigger
{
class_abc.pqr(trigger.new);
}

public class class_abc
{
pqr(list<sobject> lst)
}

@test
{
method1()
{
insert record;
list.add(record); // add to list
classinstance.pqr(list);
}
}

c/d)Include if /else condition : set up data for + and - coverage
e)There may be scenarion you are getting last line exception when executing unit test  and after juggling many hours not fixing it up and got no solution in that case use try-catch block.
f) You can call trigger-class methods in test class by passing parameters/argument if any.all method in class will be cover.

Thanks





Monday, April 20, 2015

Issue with RestUrl Salesforce

Point Regarding Rest Api Salesforce :


When sending rest request to the resturl , Make sure added the name space in Url.
if Name space not provided will throw the error :
[
    {
        "errorCode": "NOT_FOUND",
        "message": "Could not find a match for URL /Account/0019000001InXHd"
    }
]

So the request Url should be like :when Class is exposed as restresource:
     https://Instance.salesforce.com/services/apexrest/icoder/Account/AccountId
     https://Instance.salesforce.com/services/apexrest/namespace/Account/AccountId

Saturday, April 18, 2015

Email-to-Case Salesforce Engine

Email-to-Case functionality works like  success factor for company where customer can connect efficiently with quick interaction via email.
Customer can create ticket/cases while sending email to company support process  mail , ticket/inquiries can direct be placed to customer account in CRM.

It is process by which customer query can be resolved via interaction through email.

Process Flow Email-to Case SFDC:

  • When Customer send any  product malfunction/outage/breakdown  inquiries through email , Salesforce automatically logged a case and link the Account(Customer) and Contact(found by Email) to Case.
Feature can be setup:

Customize->Case->Email-to-case

  • Enable Email to Case
  • Enable Notify Case Owner on new Email

When sending Email from Case : Thread Id in subject & In Body

Thread Id : An id which is used for communication to & from for case to identify case related email thread.
if Customer reply to the mail having thread id in subject and in body, Email will automatically be linked to the Case.
All the email activities gone through this email(having ThreadID) communication will be recorded on case.

In Section Routing Address : 
Provide  support@company domain  in email,click on save--> an email notification will be received on "support@company domain"-->verify link-->
there will be email service address.

Set Email FWD setting on "support@company domain" -->Enter Email Service address (Recieived in  Section Routing Address).

Here its all done.

So when a customer send email @support it will forward email to Salesforce Email Service Address and Salesforce Engine eventually create a Case.