Showing posts with label Apex. Show all posts
Showing posts with label Apex. Show all posts

Friday, August 23, 2019

Creating a Salesforce Scratch Org Using SFDX CLI

sfdc force:org:create -a <yourScartchOrgAliasName> -d 30 -f config/project-scratch-def.json -s

If you want to create a scratch org using the Salesforce CLI please use the below the command.

sfdx force:org:create -a <aliasNameOfYourOrg> -d <duration 1-30> - f <file path> -s (defaults)

sfdc force:org:create -a <aliasNameOfYourOrg> -d 30 -f config/project-scratch-def.json -s

-d   -- Scratch org duration 1 to 30 days
-a   -- Alias name that you give for your scratch org
-s    -- defaults this org for all ongoing commands
-f    -- config file location



You can specify all your scratch org configuration in this config file before you run this command


Hope this helped you..Enjoy..!


Basic Structure Of SFDX CLI Commands

Basically all the CLI commands will be in below format

namespace:topic:[Subtopics]:methodName

namespace             --  force/lightning
topic                       -- apex/org/data
Subtopics               -- apex:class,data:bulk,auth:web
methodname          -- final action

Sample Commands:

force:alias:list
force:alias:set
force:apex:class:create
force:apex:execute
force:apex:log:get
force:apex:log:list
force:apex:log:tail
force:apex:test:report
force:apex:test:run
force:apex:trigger:create
force:auth:jwt:grant
force:auth:list
force:auth:logout
force:auth:sfdxurl:store
force:auth:web:login
force:config:get
force:config:list
force:config:set
force:data:bulk:delete
force:data:bulk:status
force:data:bulk:upsert
force:data:record:create
force:data:record:delete
force:data:record:get
force:data:record:update
force:data:soql:query
force:data:tree:export
force:data:tree:import
force:doc:commands:display
force:doc:commands:list
force:lightning:app:create
force:lightning:component:create
force:lightning:event:create
force:lightning:interface:create
force:lightning:lint
force:lightning:test:create
force:lightning:test:install
force:lightning:test:run
force:limits:api:display
force:mdapi:convert
force:mdapi:deploy
force:mdapi:deploy:cancel
force:mdapi:deploy:report
force:mdapi:describemetadata
force:mdapi:listmetadata
force:mdapi:retrieve
force:mdapi:retrieve:report
force:org:clone
force:org:create
force:org:delete
force:org:display
force:org:list
force:org:open
force:org:shape:create
force:org:shape:delete
force:org:shape:list
force:org:snapshot:create
force:org:snapshot:delete
force:org:snapshot:get
force:org:snapshot:list
force:org:status
force:package1:version:create
force:package1:version:create:get
force:package1:version:display
force:package1:version:list
force:package:create
force:package:hammertest:list
force:package:hammertest:report
force:package:hammertest:run
force:package:install
force:package:install:report
force:package:installed:list
force:package:list
force:package:uninstall
force:package:uninstall:report
force:package:update
force:package:version:create
force:package:version:create:list
force:package:version:create:report
force:package:version:list
force:package:version:promote
force:package:version:report
force:package:version:update
force:project:create
force:project:upgrade
force:schema:sobject:describe
force:schema:sobject:list
force:source:convert
force:source:delete
force:source:deploy
force:source:deploy:cancel
force:source:deploy:report
force:source:open
force:source:pull
force:source:push
force:source:retrieve
force:source:status
force:user:create
force:user:display
force:user:list
force:user:password:generate
force:user:permset:assign
force:visualforce:component:create
force:visualforce:page:create


Hope this helped you..Enjoy..!

Saturday, July 6, 2019

Base Lightning Components in Salesforce LWC

In Lightning web components(lwc) we will Base Lightning Components to display the particular record information/to create a record quickly with provided information with out using any custom apex.

List of the available Base Lightning Components are
  • lightning-record-edit-form
  • lightning-record-form
  • lightning-record-view-form

lightning-record-edit-form:

  • This component wrapper accepts the record id to display one or more fields and labels related to that field corresponding to given record id 
  • This will not require any apex because it uses Lightning Data Services to fetch the data
  • This will not support Standard objects like Task and Events.
  • Use lightning-output-field to display data in read only format
  • Use lightning-input-field to edit these fields in edit on record edit page

lightning-record-form:

  • Use this component to build the forms quickly to create a record,view the record or to update the record. 
  • Building the record creation forms is easier than building the form using lightning-record-edit-form and lightning-record-view-form. 
  • This component accepts 4 properties like object name which is mandatory,record id which is optional in case of create record ,mode to specify view/edit/read only and layout type like Full or compact
  • It will also takes care of FLS and sharing rules
 <lightning-record-form  
   record-id="739hchjsh773"  
   object-api-name="Position__c"  
   layout-type="Full"  
   mode="view">  
 </lightning-record-form>  

lightning-record-view-form:

  • Use this component when you want to dispaly the record on view mode
  • This will not require any apex because it uses Lightning Data Services to fetch the data
  • This will not support Standard objects like Task and Events.
  • It will also takes care of FLS and sharing rules.

For more information refer:

Hope this helps you...Enjoy!

How To Access Salesforce Org Data in Lightning Web Components

In Classic if you want access/create the Salesforce Data we can either use some Standard Controllers or Custom controllers .Similar to Classic in Lighting Web Components also you can use two different ways to access/create the data into Salesforce objects or to show the Salesforce objects data in Lightning Web Components.

  1. Base Lightning Components
  2. Wire Services

Base Lightning Components:


These are the standard salesforce components which will be used to view the record,to edit the record and to view the record in read only mode.

Benefits:
  • Doesn't require apex code
  • Field labels are displayed based on org default
  • It's has built over Lighting UI API and Lightning Data Service API
  • It access models Static and Dynamically
  • Metadata Aware
  • Custom rendering of data
  • Custom layouts and multi column layouts



Wire Service:

Wire service will use Lighting /UI API Module and Lightning Data Service to fetch the data from the Salesforce Servers/Objects and to show it in the components.Basically we have to import the wire adapters into our lighting web components js file in order to build the communication between the components and servers.The results returned from the wire adapter will be stored either in property or function.

  • Lighting /UI API Module : It will contains bunch of wire adapters(small segment of code) and some JS APIs. These wire adapters will be used to fetch the data from the servers and these JS APIs if you want to modify this data or to push the data into servers.

  • Lightning Data Service : It will act an interface between the wire adapters and data base to get the data from the data base into the adapters. Basically adapters will interacts with Lightning Data Services to fetch the data from the data base.









 Hope this helps you...Enjoy!


Wednesday, August 23, 2017

Salesforce Site Template is Not Coming in Force.com Site

If your Site Template is not coming on your there might be the below issues.

1. Site Template page has not been added for Site Template on Site Detail Page



2. If your using any visual force page in your sites and if your not adding Template to visual force page you will not be able show the template.Please add the template to each and every page.


<apex:page standardController="Case" showHeader="false">
    <apex:composition template="{!$Site.Template}">
        <apex:define name="body">
    <head>
              <apex:includeScript value="{!$Resource.dataTableJS}"/>
       <apex:stylesheet value="{!$Resource.dataTableCSS}" />
     </head>
   <apex:form>
      ----
      ----
   </apex:form>
 </apex:define>
   </apex:composition>
</apex:page>

Hope this helps you...Enjoy!

CSS Styles/Scripts Are Not Working in Salesforce Force.com Sites

If your styles/scripts are working perfectly in Sandbox and Production preview but if it's not working on Force.com sites which has hosted publicly on Sales force server below points might be the issue.

Your page is referring to some external CSS/JS files:

<apex:page>
 <head>
 <apex:stylesheet value="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css" />
<apex:includescript value="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" /> 
</head>
<apex:form>
  ----
  ----
</apex:form>
</apex:page>

If your referring any styles/scripts from external sources with out storing them in Static Resource you will end up with problem Please store that files in Statistic resource and then use it then it will work in Force.com sites as well.


<apex:page>
 <head>
  <apex:includeScript value="{!$Resource.dataTableJS}"/>
  <apex:stylesheet value="{!$Resource.dataTableCSS}" />
</head>
<apex:form>
  ----
  ----
</apex:form>
</apex:page>


Your Static Resource is File not accessible publicly



If your using any static resource in your page and if that static resource is not accessible publicly (Cache Control set to Private) then styles will not reflect in Force.com sites.So mark your Static resources cache control as Public



Hope this helps you...Enjoy!


Wednesday, August 9, 2017

System.TypeException: Invalid date/time Exception in Salesforce Apex

  • When your assigning a value DateTime field using the String then we will end up with this error.
  • If your receiving your date value as part of JSON response and then assiging to DateTime value you will also end up with same error.
To avoid this issue we can use the below two procedures

Sample Error Code:


if(mapName.KeySet().contains('creation_Time') && string.isNotBlank(string.valueof(mapName.get('creation_Time'))))
{

 if(string.valueof(mapName.get('creation_Time')).contains('T'))
  {
    ObjectInsatnce.creation_Time__c = datetime.valueof(string.valueof(mapName.get('cancellation_time')).replace('T',' '));
  }
else
{
 ObjectInsatnce.Cancellation_Time__c = datetime.valueof(mapName.get('cancellation_time'));
}
}

Rectified Source Code:


if(mapName.KeySet().contains('creation_Time') && string.isNotBlank(string.valueof(mapName.get('creation_Time'))))
{

if(string.valueof(mapName.get('creation_Time')).contains('T'))
{
 ObjectInsatnce.creation_Time__c = datetime.valueof(string.valueof(mapName.get('cancellation_time')).replace('T',' '));
}
else
{
  ObjectInsatnce.Cancellation_Time__c = datetime.valueof((String)mapName.get('cancellation_time'));
}
}
 

Hope this helps you....Enjoy!