
Salesforce Codes
79 FOLLOWERS
In this website we are going to implement salesforce codes like visualforce pages, lightning components, triggers. It is most useful for the begginers who are interested in learning salesforce and also it will be useful to the people who already known salesforce.
Salesforce Codes
1y ago
Apex Class:
public class CloneOpportunityWithSpecificFieldsCtrl {
@AuraEnabled
public static Map<String, String> cloneToOpportunity(String Id,String oppName){
Map<String, String> response = new Map<String, String>();
List<Opportunity> opp = [select Id,Name,AccountId,StageName,CloseDate
from Opportunity Where Id =:Id];
if(opp.size() > 0){
try{
Opportunity newopp = new Opportunity();
newopp.Name = oppName;
newopp.StageName = 'Prospecting ..read more
Salesforce Codes
1y ago
Apex Trigger:
trigger AutomaticallyAssignAccountToContact on Contact (before insert) {
Map<String, Id> domains = new Map<String, Id>();
for(Contact con: Trigger.new) {
domains.put(con.Email.split('@').get(1), null);
}
for(Account acc: [SELECT Name FROM Account WHERE Name IN :domains.keySet()]) {
domains.put(acc.Name.toLowercase(), acc.Id);
}
for(Contact c: Trigger.new) {
if(domains.get(c.Email.split('@').get(1)) != null) {
c.AccountId = domains.get(c.Email.split('@').get(1 ..read more
Salesforce Codes
1y ago
Follow below steps for this Scenario:
Create Domain__c Text Field on Account and Domain__c Formula Text Field on Contact
Formula :
(MID(Email,FIND('@', Email, 1)+1, (LEN(Email) - FIND('@', Email, 1)+1)))
In this scenario Account Domain__c value like ‘gmail.com’ other examples: yahoo.com,wipro.com,infosys.com
Contact Email like ‘salesforcecodes@gmail.com’ then automatically assign Account to this New Contact
trigger AssignAccountToContactBasedOnEmailDomain on Contact (before insert) {
List<String> contactEmaildomains = new List<String>();
for(Contact con : Trigger.new ..read more
Salesforce Codes
1y ago
Apex Trigger
trigger CountOfContactsRelatedToAccount on Contact (after insert, after delete, after Undelete) {
Set<Id> accId = new Set<Id>();
if(Trigger.isInsert || Trigger.isUndelete){
for(Contact con : Trigger.new){
accId.add(con.AccountId);
}
}
if(Trigger.isDelete){
for(Contact con : Trigger.old){
accId.add(con.AccountId);
}
}
List<Account> accList = [Select Id,Name,Count_of_Contacts__c ,(Select id from contacts) from Account where Id IN : accId];
for(Account acc :accList){
acc.Co ..read more
Salesforce Codes
1y ago
Apex Trigger
trigger UpdateRelatedContactsBasedOnAccount on Account (before update, after update) {
Set<id> accid = new Set<id>();
for(Account a : Trigger.new){
if(a.Rating != null){
accid.add(a.id);
}
if(!accid.isEmpty()){
List<Contact> conList = [select Id, Name, AccountId, Level__c from Contact where AccountId =: accid];
if(!conList.isEmpty()){
for(Contact c : conList){
if(a.Rating == 'Hot'){
c.Level__c='Primary';
}else if(a.Rati ..read more
Salesforce Codes
1y ago
End Point URL: https://api.androidhive.info/contacts/
First add above URL in Remote Site Settings.
Apex Class
public class JsonDataInsert {
public static HttpResponse jsonData() {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://api.androidhive.info/contacts/');
request.setMethod('GET');
HttpResponse response = http.send(request);
if (response.getStatusCode() == 200) {
EmployeeRecordsList employeeRecords = (EmployeeRecordsList) JSON.deserialize(response.getBody(),EmployeeRecordsList.c ..read more
Salesforce Codes
1y ago
Apex Trigger
trigger LeadEmailContactEmailSameUpdateCon on Lead (after insert) {
LeadEmailAndContactEmailSameConvertLead.ConvertleadWithSameEmail(Trigger.New);
Apex Class
public class LeadEmailAndContactEmailSameConvertLead {
public Static void ConvertleadWithSameEmail(List<Lead> lea){
Map<String,lead> mapemailleads = new Map<String,lead>();
for(Lead l:lea) {
if(l.Email != Null){
mapemailleads.put(l.email,l);
}
}
List<Contact> ContactEmail=[select id,LastName,Email,AccountId ..read more
Salesforce Codes
1y ago
Apex Class
public class customLookUpController {
@AuraEnabled
public static List < sObject > fetchLookUpValues(String searchKeyWord, String ObjectName,String accountId) {
String searchKey = searchKeyWord + '%';
String sQuery='';
List < sObject > returnList = new List < sObject > ();
if(ObjectName == 'contact' || ObjectName == 'opportunity'){
sQuery = 'select id, Name from ' +ObjectName + ' where Name LIKE: searchKey and accountId =: accountId order by createdDate ASC limit 5';
} else {
// Create a Dynamic ..read more
Salesforce Codes
1y ago
Lightning Component
<aura:application extends="force:slds">
<aura:attribute name="myText" type="string" />
<aura:attribute name="myNumber" type="string" />
<aura:attribute name="myDate" type="string" />
<aura:attribute name="myNumSpl" type="string" />
<div >
<p >Restrict Numbers, Alphabets and Special Characters</p>
<span onkeypress="{!c.TextCheck}">
<lightning:input label="Account Name"
name="Body"
placeholder="Enter Text ..read more
Salesforce Codes
1y ago
Apex Class
public class ContactsaddToAccountController {
@AuraEnabled
public static List<contact> getContacts() {
List<contact> totalList = new List<contact>();
for(Contact cc : [SELECT Id,Name,Email from contact limit 20]){
totalList.add(cc);
}
return totalList;
}
@AuraEnabled
public static void addParentAccount(String ParentId , List<String> lstOfContactIds){
list<Contact> lstContacts = new list<Contact>();
for(string sContactId : lstOfContactIds){
Con ..read more