SHARE - Salesforce My Notes
SHARE - Salesforce My Notes
studentList=[
{id:123, name:"shubham", Age:15},
<template iterator:stu={studentList}> {id:124, name:"abhay", Age:16},
ITERATOR LOOP <div key={stu.value.id}> {id:125, name:"Adesh", Age:18},
<h3>{stu.value.name}</h3> <h4>{stu.value.Age}</h4> {id:126, name:"vaibhav", Age:25}
</div>
</template> ]
currentTarget event.currentarget.value (to get from where the event is fired if both event has same event Handler)
The CustomEvent() constructor has one required parameter, which is a string indicating the event type.
eventTarget.disptachEvent();
event.preventDefault();
const selectEvent = new CustomEvent('selection', {
CHILD TO PARENT
detail: event.target.name
});
showNotifyParentHandler(event) {
event.preventDefault();
const selectEvent = new CustomEvent('show', {
CHILD TO PARENT
bubbles: true
WITH BUBBLING
});
this.dispatchEvent(selectEvent);
}
The preventDefault() method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur.
@wire(getListui, {
uiListsApi
objectApiName:ACCOUNT,
listviewApiName:AllAccounts
}) wiredListView
const fields={};
fields[NAME_FIELD.fieldApiName]=this.accName;
fields[ANNUAL_REVENUE.fieldApiName]=this.accRev;
console.log(fields);
Create Record
let recordInput={apiName:ACCOUNT_OBJECT.objectApiName, fields}
createRecord(recordInput).then(result=>{
this.accName=''
console.log('Account created ID', JSON.stringify(result.id))
}).catch(error=>{
console.error(error)
})
TOPIC Code
this.dispatchEvent(new ShowToastEvent({
TOAST EVENT title 'Contact',
message 'Updated Successfully',
variant 'success'
}));
REFRESH APEX
refreshApex(this.wiredData);
this[NavigationMixin.Navigate]({
type 'standard__navItemPage',
attributes {
apiName "The unique name of the CustomTab."
}
});
this[NavigationMixin.Navigate]({
type 'standard__component',
attributes {
componentName "c__component name"
}
});
NAVIGATION this[NavigationMixin.Navigate]({
type 'standard__objectPage',
attributes {
actionName "home, list, or new",
objectApiName "The API name of the standard or custom object. "
}
});
this[NavigationMixin.Navigate]({
type 'standard__recordPage',
attributes {
actionName "clone, edit, or view",
recordId "recordId",
objectApiName "The API name of the record’s object. Optional for lookups."
}
});
handleNameChange(event) {
this.name = event.target.value;
} <template>
<lightning-input label="Name" value={name} onchange={handleNameChange}></lightning-input>
LWC VALIDATION validateName() { <lightning-button label="Validate" onclick={validateName}></lightning-button>
const namePattern = /^[A-Za-z ]+$/; // Allow only letters and spaces <div iftrue={nameError} class="error">{nameError}</div>
if (!namePattern.test(this.name)) { </template>
this.nameError = 'Name can only contain letters and spaces.';
} else {
this.nameError = '';
// Name is valid, you can perform further actions here
}
}
}
<template>
<lightning-input
label="Name"
type="text"
name="name"
value={name}
LWC VALIDATION required
pattern="[A-Za-z ]+"
message-when-pattern-mismatch="Name can only contain letters and spaces."
oninput={handleNameChange}>
</lightning-input>
</template>
TOPIC CODE
Method in list
add(element);
add(index, listElement);
addall(fromlist);
LIST addall(from set);
equals(listsecond);
contains(listelements);
clone();
clear();
get(index);
indexof();
isEmpty();
remove();
sort();
size();
set(index,listelement);
Declaration-
Methods In set
add(setelements);
addall(list);
SET addall(set);
clear();
clone();
equals();
contains(single element);
containsall(compair with list);
size();
isempty();
remove(single set elment);
removeall();
Methods-
put(key,value);
MAP
putall(secondmap);
remove(key);
value();
size();
clear();
equals(second map);
clone();
get(key);
containskey(key);
isempty()
keyset()
// Custom Metadata
List<Account_Metadata__mdt> cn= Account_Metadata__mdt.getAll().values();
CUSTOM System.debug(cn[0].masterlabel);
METADTA Map<String, Account_Metadata__mdt> mcs = Account_Metadata__mdt.getAll();
system.debug('keys are'+mcs.keyset());
system.debug('values are' +mcs.values());
public class Metadata {
Boolean triggerActive=mdt.get('Contact_Switch').Active__c;
System.debug(mdt.get('Contact_Switch'));
TriggerSwtich__mdt mc = TriggerSwtich__mdt.getInstance('Account_Switch');
System.debug('mc is '+mc);
}
}
for(String kmcs.keySet()){
PRINT MAP System.debug('keys are '+ k +' and values are '+ mcs.get(k));
}
Lead[] l1= [Select Name, leadSource from Lead ORDER BY Name ASC];
system.debug(l1);
mail.setReplyTo('[email protected]');
mail.setSenderDisplayName('Salesforce Support');
mail.setSubject('New Case Created' );
mail.setPlainTextBody('Your Case has been created.');
SCHEMA
Map<string, Schema.SObjectField> flMap= r.fields.getMap();
Set<string> keys= flMap.keyset();
system.debug('flmap '+flMap);
Schema.DescribeSobjectResult r= Account.sobjectType.getDescribe();
ISCREATBLE
system.debug('r is creatable '+r.isCreateable());
In an after insert trigger and the records are read-only in that context as they have been written, but not committed, to the database.
FINAL EXCEPTION This kind of error occurs if you try to update lists/record which are/is read-only in the trigger execution. For example, trigger.new and trigger.old are both read-only lists and cannot be applied with a DML operation.
A field value of the object can be changed using trigger.new but only in case of before triggers. But in case of after triggers changing the values of the records in trigger.new context will throw an exception as "Record is read-only"
Integration
Headers
Authorization header Authorization header is used to send the client’s credentials to the server when the client is attempting to access a protected resource.
The User-Agent header identifies the web browser or client application that is making the request, which enables the server to tailor its response
to the client. For instance, if the User-Agent header indicates that the request is coming from the Chrome browser, the server may include CSS
User-Agent prefixes for CSS properties that are compatible with Chrome.
The Content-Type header identifies the media type of the content in the request body. For instance, Content-Type: application/json indicates that
Content-Type the request body contains JSON data. This information helps the server successfully interpret and process the payload.
Authentication
POSTMAN
@RestResource(urlMapping='/ContactAPI/*')
YOUR OWN APEX REST API /services/apexrest/ContactAPI
OAUTH BASIC RESOURCE OWNER(USERNAME & PASSWORD)
Body of POST
username
append (passwordSecuiryToke) or Relax Ip from Connected pp Edit
password Policy
grant_type password
client_id
client_secret
Body of GET
header of the request, input the access token and token type. Key- Authorization | Value Bearer + access-token FOR JSON FOR XML
Content- Type application/json application/xml; charset= UTF-8
Accept application/json application/xml
Resource Owner: The user who owns the data and can grant access to it. For example, you are the resource
owner if you allow an app to access your Google Drive files.
Client: The third-party application (like a mobile app or website) that requests access to the resource owner's
data.
Resource Server: The server that hosts the resource owner's data (e.g., Google's servers for Google Drive).
Authorization Server: The server that issues access tokens after authenticating the resource owner and
authorizing the client (e.g., Google’s OAuth server).
Tokens:
Access Token: A credential the client uses to access the resource owner's data. This token is typically short-lived.
Refresh Token: A long-lived token that allows the client to obtain a new access token when the current one expires. This avoids needing to ask the user to log in again.
OAuth 2.0
2 step Process-
1- Hit URL in browser of Resource Owner ( Resource - QuickBooks & owner- I if I have access to Quickbooks A/
C), then it return Authorization code which is valid for 60 MIn
2- send Auth Code to get Access Tokeen
QUICKBOOK
Client Id ABbEN9XosnekoudOUUneDTZQLp6DJG2WzctEZR0rvHxKv6ORiP
Client Secret I4Z8ELclxMUtx47iByzNTXG99vb8cWxZbkGDmjvc
https//appcenter.intuit.com/connect/oauth2?
client_id=ABbEN9XosnekoudOUUneDTZQLp6DJG2WzctEZR0rvHxKv6OR
iP
&response_type=code&scope=com.intuit.quickbooks.accounting
&redirect_uri=https//www.salesforce.com
URL to get Auth Code &state=security_token
POST https//oauth.platform.intuit.com/oauth2/v1/tokens/bearer
HTTP/1.1
Accept application/json
Authorization Basic
UTM0dVBvRDIwanp2OUdxNXE1dmlMemppcTlwM1d2
NzRUdDNReGkwZVNTTDhFRWwxb0g6VEh0WEJlR3dheEtZSlVNaFhzeGx
ma1l
XaFg3ZlFlRzFtN2szTFRwbw==
Content-Type application/x-www-form-urlencoded
Host oauth.platform.intuit.com
Body grant_type=authorization_code&
code=L3114709614564VSU8JSEiPkXx1xhV8D9mv4xbv6sZJycibMUI&
Exchange the authorization code for access tokens redirect_uri=https//www.mydemoapp.com/oauth-redirect
GOOGLE API
631950255594-mncomd3ev7ka1q5oa9fkd9bdgitem5ur.apps.googleuse
ClientId (SF Calender)
rcontent.com
Client Secret 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
https//accounts.google.com/o/oauth2/v2/auth?
scope=https//www.googleapis.com/auth/calendar https//
www.googleapis.com/auth/calendar.events &
access_type=offline&
include_granted_scopes=true&
URL for Auth2.0 step 1 (GET THE AUTH CODE) response_type=code&
state=state_parameter_passthrough_value&
redirect_uri=https//www.salesforce.com&
client_id=http//
631950255594-mncomd3ev7ka1q5oa9fkd9bdgitem5ur.apps.googleuse
rcontent.com
POST /token HTTP/1.1
Host oauth2.googleapis.com
Content-Type application/x-www-form-urlencoded
Resources-
Apex Rest
https//developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_intro.htm
https//developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_code_sample_basic.htm
https//trailhead.salesforce.com/en/content/learn/v/modules/apex_integration_services/
apex_integration_rest_callouts
Apex SOAP
https//developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_web_services.htm
https//trailhead.salesforce.com/en/content/learn/v/modules/apex_integration_services/
apex_integration_soap_callouts
Basic Authentication
https//en.wikipedia.org/wiki/Basic_access_authentication
Connected Application
https//developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/
intro_oauth_and_connected_apps.htm
JWT Authentication
https//blog.logrocket.com/jwt-authentication-best-practices/
https//jwt.io/
LinkedInd API
https//docs.microsoft.com/en-us/linkedin/
https//docs.microsoft.com/en-us/linkedin/shared/authentication/authentication
QuickBooks API
https//developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/account
Authentication - https//developer.intuit.com/app/developer/qbo/docs/develop/
authentication-and-authorization
Google API
Authentication - https//developers.google.com/identity/protocols/oauth2/web-server
Salesforce API -
Authentication - https//help.salesforce.com/articleView?id=remoteaccess_oauth_web_server_flow.htm&type=5
Freshdesk API
https//developers.freshdesk.com/api/
https//help.salesforce.com/articleView?id=named_credentials_about.htm&type=5
https//help.salesforce.com/articleView?id=sso_provider_sfdc.htm&type=5
https//help.salesforce.com/articleView?id=sso_authentication_providers.htm&type=5
https//help.salesforce.com/articleView?id=sso_provider_plugin_custom.htm&type=5
Einstein API
Sign Up - https//api.einstein.ai/signup
Authentication - https//metamind.readme.io/docs/generate-an-oauth-token-using-your-key
Exaples - https//developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/quickreference.htm
Streaming API
https//developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/intro_stream.htm
https//trailhead.salesforce.com/en/content/learn/v/modules/api_basics/api_basics_streaming
Platform Event
https//developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/
platform_events_intro.htm
https//trailhead.salesforce.com/en/content/learn/v/projects/workshop-platform-events/platform-event-define
https//trailhead.salesforce.com/content/learn/modules/platform_events_basics
https//developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/
cdc_intro.htm
https//trailhead.salesforce.com/en/content/learn/v/modules/change-data-capture/
understand-change-data-capture
JSForce -
https//jsforce.github.io/document/
http//jsforce.github.io/jsforce/doc/
Outbound Message
https//developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_om_outboundmessaging.htm
https//help.salesforce.com/articleView?id=workflow_managing_outbound_messages.htm&type=5
https//developer.salesforce.com/docs/atlas.en-us.api.meta/api/
sforce_api_om_outboundmessaging_setting_up.htm
Metadata API
GitHub - https//github.com/financialforcedev/apex-mdapi
Introduction - https//developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_intro.htm
https//developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/file_based.htm
https//trailhead.salesforce.com/content/learn/modules/apex_metadata_api
Unit Test
https//developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_unit_tests.htm
https//trailhead.salesforce.com/en/content/learn/v/modules/apex_testing/apex_testing_intro
https//developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing.htm
https//help.salesforce.com/articleView?id=code_run_tests.htm&type=5
https//developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/
apex_classes_restful_http_testing_httpcalloutmock.htm
https//developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts.htm
https//developer.salesforce.com/blogs/developer-relations/2013/03/
testing-apex-callouts-using-httpcalloutmock.html
Heroku
https//trailhead.salesforce.com/content/learn/modules/salesforce_heroku_integration
https//www.heroku.com/salesforce
External Object
https//help.salesforce.com/articleView?id=external_object_define.htm&type=5
Project
https//pipedrive.readme.io/docs/core-api-concepts-authentication
https//developers.pipedrive.com/docs/api/v1/#/
GIT
GIT BASICS
version git --version
git help --all press q to exit view and shift + G END
config git config --global user.name "w3schools-test"
Use global to set the username and e-mail for every repository on your computer.
config git config --global user.email "[email protected]"
If you want to set the username/e mail for just the current repo you can remove global
initialize Git git init git dont track Empty Folder
Create new Repo in GitHub
mkdir make new directory
cd current dir
cd.. out of current dir
U untracked
M Modified
A Index Added (After Stating Done)
Adds content from all *.txt files under Documentation directory and its subdirectories:
Stage (Add Files to staging Ares) File ready to be committed git add . ----git add Documentation/\*.txt
unstage I still need to do some changes git rm --cached ...
Commit (only staged changes will be committed in Local Repo) finalizing the changes
Push push to git (local to remote) git push --set-upstream origin master
Local Repo VS code
git push --set-upstream origin master
Git Hub git remote add origin https//github.com/w3schools-test/hello-world.git
git remote add origin https//github.com/shubhaktripathi/oct23.git
FETCH So, on your local Git, fetch updates to see what has changed on GitHub git fetch origin
git diff origin/master git log origin/master
Difference bw Origin and Local
git merge origin/master
Merge
f you just want to update your local repository, without going through all those steps
fetch then Merge?
pull is a combination of fetch and merge. It is used to pull all changes from a remote
PULL(FETCH + MERGE) git pull origin repository into the branch you are working on.
clone from GitHub Repo Git Clone url
pull from github clone
push to scratch org push source to default scratch org
Pull Source from Scratch Org (If any metadata is created in scratch org)
PUSH
GIT CONTRIBUTE
A fork is a copy of a repository. This is useful when you want to contribute to someone fork is not a command in Git, but something offered in GitHub and other repository
Git GitHub Fork else's project or start your own project based on theirs. hosts. Let's start by logging in to GitHub,
we have our own fork, but only on GitHub. We also want a clone on our local Git to keep
working on it.
A clone is a full copy of a repository, including all logging and versions of files.
git clone https//github.com/w3schools-test/w3schools-test.github.io.git Move back to the original repository, and click the green "Code" button to get the URL to
Clone clone
According to Git naming conventions, it is recommended to name your own repository origin,
and the one you forked for upstream
Now we have 2 remotes
origin - our own fork, where we have read and write access
upstream - the original, where we have read-only access
GIT ADVANCE
Examples
log files
temporary files
When sharing your code with others, there are hidden files
often files or parts of your project, you do not personal files
want to share. etc.
touch .gitignore
Create .gitignore
in this file Ignore any files with the .log extension # ignore ALL .log files
*.log
GIT REBASE
You can view all of your settings and where they are
coming from using git config --list --show-origin
Open git config in VS code git config --global core.editor "code --wait"
Open git config in VS code git config --global -e
Global User Name git config --global user.name "John Doe"
Global User Email git config --global user.email [email protected]
git config --global core.autocrlf input
To set main as the default branch name to(master) $ git config --global init.defaultBranch main
check your configuration settings git config --list
$ git help <verb>
$ git <verb> --help
Getting Help $ man git-<verb>
cd C/Users/user/my_project
Initializing a Repository in an Existing Directory git init
git clone
Cloning an Existing Repository git clone https//github.com/libgit2/libgit2
git status
On branch master
Your branch is up-to-date with 'origin/master'.
Checking the Status of Your Files nothing to commit, working tree clean
echo 'My Project' > README
git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files
(use "git add <file>..." to include in what will be committed)
README
simple README file ( Echo command write content in
file) nothing added to commit but untracked files present (use "git add" to track)
Echo (modifying same file) echo helloAll >> README
Tracking New Files( Add - to add files to staging Area) git add README
add all files git add .
git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed
(use "git reset HEAD <file>..." to unstage)
Test.startTest() Async? With Test.startTest asynchronous operation executes in series and result also obtained in test class.
Total number of records processed as a result of DML statements, Approval.process, or 10,000 10,000
Mannual Sharing for Queue
Both can be used, but having can be used for aggregate only and for aggregation. SELECT LeadSource, COUNT(Name)
FROM Lead
GROUP BY LeadSource
wHERE VS Having HAVING COUNT(Name) > 1
Service Cloud-
1. Literals Characters that match themselves. For example, the regex `a` matches the character "a" in a string.
3. Character Classes - `[abc]` Matches any one of the characters "a," "b," or "c."
- `[^abc]` Matches any character except "a," "b," or "c."
- `[a-z]` Matches any lowercase letter.
- `[A-Z]` Matches any uppercase letter.
- `[0-9]` Matches any digit.
- `[A-Za-z0-9]` Matches any alphanumeric character.
5. Escape Sequences To match metacharacters as literals, you can escape them with a backslash `\`. For example, `\.`, `\*`, `\\`.
7. Grouping - `()` Groups characters or patterns together, allowing you to apply quantifiers or other operations to a group.
10. Escaping Special Characters To match characters that are regex metacharacters as literals (e.g., `[`, `]`, `(`, `)`, `?`), you need to escape them with a backslash `\`.
Matching a Pattern String text = 'The quick brown fox jumps over the lazy dog.';
String pattern = 'fox';
Boolean isMatch = Pattern.compile(pattern).matcher(text).find();
System.debug('Is there a match? ' + isMatch); // Output Is there a match? true
Extracting Email Addresses from Text String text = 'Contact us at [email protected] or [email protected] for assistance.';
String pattern = '\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}\\b';
Matcher matcher = Pattern.compile(pattern).matcher(text);
while (matcher.find()) {
System.debug('Found email ' + matcher.group());
}
// Output Found email [email protected]
// Found email [email protected]