completed assignment
This commit is contained in:
3
force-app/main/default/classes/Assigmnt2.cls
Normal file
3
force-app/main/default/classes/Assigmnt2.cls
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
public class Assigmnt2 {
|
||||||
|
|
||||||
|
}
|
||||||
5
force-app/main/default/classes/Assigmnt2.cls-meta.xml
Normal file
5
force-app/main/default/classes/Assigmnt2.cls-meta.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexClass>
|
||||||
166
force-app/main/default/classes/assigment.cls
Normal file
166
force-app/main/default/classes/assigment.cls
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
public class assigment {
|
||||||
|
public static void getLeadQuality(Decimal annualRevenue)
|
||||||
|
{
|
||||||
|
if (annualRevenue > 2000000)
|
||||||
|
{
|
||||||
|
system.debug('High Quality');
|
||||||
|
} else if (annualRevenue >= 500000)
|
||||||
|
{
|
||||||
|
system.debug('Medium Quality');
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
system.debug('Low Quality');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void getSuggestedMovie(String key)
|
||||||
|
{
|
||||||
|
Map<String, List<String>> movieMap = new Map<String, List<String>>
|
||||||
|
{
|
||||||
|
'Action' => new List<String>{'Mad Max', 'Gladiator', 'Die Hard'},
|
||||||
|
'Comedy' => new List<String>{'Superbad', 'Step Brothers', 'The Hangover'},
|
||||||
|
'Drama' => new List<String>{'The Shawshank Redemption', 'Forrest Gump', 'Fight Club'},
|
||||||
|
'Horror' => new List<String>{'The Conjuring', 'Get Out', 'It'},
|
||||||
|
'Sci-Fi' => new List<String>{'Inception', 'Interstellar', 'The Matrix'}
|
||||||
|
};
|
||||||
|
if (!movieMap.containsKey(key))
|
||||||
|
{
|
||||||
|
system.debug('No movies available for this genre');
|
||||||
|
}
|
||||||
|
system.debug(movieMap.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void calculateParkingFee(Integer hoursParked)
|
||||||
|
{
|
||||||
|
Decimal totalFee = 0;
|
||||||
|
for (Integer hour = 1; hour <= hoursParked; hour++) {
|
||||||
|
if (hour == 1)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (hour <= 4)
|
||||||
|
{
|
||||||
|
totalFee += 5;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
totalFee += 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
system.debug(totalFee);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Decimal calculateTotalBill(Map<String, Integer> order)
|
||||||
|
{
|
||||||
|
Map<String, Decimal> menu = new Map<String, Decimal>
|
||||||
|
{
|
||||||
|
'Pizza' => 10.00,
|
||||||
|
'Burger' => 5.00,
|
||||||
|
'Pasta' => 8.00,
|
||||||
|
'Salad' => 6.00,
|
||||||
|
'Soda' => 2.00
|
||||||
|
};
|
||||||
|
|
||||||
|
Decimal totalBill = 0;
|
||||||
|
|
||||||
|
for (String item : order.keySet())
|
||||||
|
{
|
||||||
|
if (menu.containsKey(item))
|
||||||
|
{
|
||||||
|
totalBill += menu.get(item) * order.get(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalBill;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Decimal calculateBonuses(Map<String, Decimal> employees)
|
||||||
|
{
|
||||||
|
Decimal bonusAmount;
|
||||||
|
Map<String, Decimal> bonusMap = new Map<String, Decimal>();
|
||||||
|
|
||||||
|
for (String emp : employees.keyset())
|
||||||
|
{
|
||||||
|
Decimal SalesAmount = employees.get(emp);
|
||||||
|
Decimal bonusPercentage;
|
||||||
|
if (SalesAmount > 100000)
|
||||||
|
{
|
||||||
|
bonusPercentage = 0.20;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
bonusPercentage = 0.10;
|
||||||
|
}
|
||||||
|
bonusAmount = SalesAmount* bonusPercentage;
|
||||||
|
bonusMap.put(emp, bonusAmount);
|
||||||
|
}
|
||||||
|
system.debug(bonusMap);
|
||||||
|
return bonusAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// LIST TO STORE PATIENTS WITH EMERGENCY LEVEL
|
||||||
|
/*List<String> patientList = new List<String>();
|
||||||
|
patientList.add('Ram-Normal');
|
||||||
|
patientList.add('Gopal-Critical');
|
||||||
|
patientList.add('Roshan-Severe');
|
||||||
|
patientList.add('Sham-Normal');
|
||||||
|
System.debug('Patients before sort: ' + patientList);
|
||||||
|
|
||||||
|
// LIST TO STORE EMERGENCY LEVELS
|
||||||
|
List<String> emergencyLevelList = new List<String>{
|
||||||
|
'Critical', 'Severe', 'Normal'
|
||||||
|
};
|
||||||
|
|
||||||
|
// LIST TO STORE SORTED PATIENTS WITH EMERGENCY LEVEL
|
||||||
|
List<String> sortedPatientList = new List<String>();
|
||||||
|
|
||||||
|
// ITERATE OVER EMERGENCY LEVELS
|
||||||
|
for(String emergencyLevel : emergencyLevelList) {
|
||||||
|
// ITERATE OVER PATIENTS
|
||||||
|
for(String patientData : patientList) {
|
||||||
|
// CHECK FOR SORTED EMERGENCY LEVELS
|
||||||
|
if(patientData.contains(emergencyLevel)) {
|
||||||
|
// STORE PATIENT NAME
|
||||||
|
sortedPatientList.add(patientData.split('-')[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.debug('Patients after sort: ' + sortedPatientList);*/
|
||||||
|
|
||||||
|
|
||||||
|
public static void PatientSorter(){
|
||||||
|
map<String, String> sortPatientsByPriority = new map<String, String>();
|
||||||
|
|
||||||
|
map<String, String> Patients = new map<String, String>();
|
||||||
|
Patients.put('Ram', ' Normal');
|
||||||
|
Patients.put('Gopal','Critical');
|
||||||
|
Patients.put('Roshan','Severe');
|
||||||
|
Patients.put('Sham','Normal');
|
||||||
|
system.debug('Patient before sort patient:' +Patients);
|
||||||
|
|
||||||
|
map<integer, String> emergencyLevel = new map<integer, String>();
|
||||||
|
emergencyLevel.put(1,'Severe');
|
||||||
|
emergencyLevel.put(2,'Critical');
|
||||||
|
emergencyLevel.put(3,'Normal');
|
||||||
|
|
||||||
|
for(String emergency:emergencyLevel.values()){
|
||||||
|
for(String patient:Patients.keyset()){
|
||||||
|
if(Patients.get(patient)==emergency)
|
||||||
|
|
||||||
|
{
|
||||||
|
sortPatientsByPriority.put(patient, emergency);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}system.debug(sortPatientsByPriority);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
5
force-app/main/default/classes/assigment.cls-meta.xml
Normal file
5
force-app/main/default/classes/assigment.cls-meta.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexClass>
|
||||||
93
force-app/main/default/classes/training.cls
Normal file
93
force-app/main/default/classes/training.cls
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
public class training {
|
||||||
|
public static void abc(){
|
||||||
|
list<string> cities= new list<string>();
|
||||||
|
cities.add('Delhi');
|
||||||
|
cities.add(0,'Mumbai');
|
||||||
|
cities.add('Kolkata');
|
||||||
|
System.debug('cities'+ cities);
|
||||||
|
list<string> fruits= new list<string>();
|
||||||
|
fruits.add('Apple');
|
||||||
|
fruits.add('Pears');
|
||||||
|
fruits.add('Orange');
|
||||||
|
fruits.addAll(cities);
|
||||||
|
System.debug(fruits);
|
||||||
|
//fruits.clear();
|
||||||
|
System.debug(fruits);
|
||||||
|
system.debug(cities.contains('Kolkata'));
|
||||||
|
system.debug(fruits.remove(2));
|
||||||
|
system.debug(cities.size());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void operators(){
|
||||||
|
integer a= 55, b= 39, c;
|
||||||
|
c= a+b;
|
||||||
|
system.debug(c);
|
||||||
|
Decimal h= 7.8,j=6, i;
|
||||||
|
i= h*j;
|
||||||
|
system.debug(i);
|
||||||
|
Decimal o= 1.9,u= 4.4, r;
|
||||||
|
r= o-u;
|
||||||
|
System.debug(r);
|
||||||
|
Decimal s= 9.0,t=3,n;
|
||||||
|
n= s/t;
|
||||||
|
System.debug(n);
|
||||||
|
integer w= 78,q= 7, d;
|
||||||
|
d= w/q;
|
||||||
|
System.debug(d);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public static void method3(){
|
||||||
|
set <integer> num= new set<integer>();
|
||||||
|
num.add(10);
|
||||||
|
num.add(15);
|
||||||
|
num.add(20);
|
||||||
|
num.add(25);
|
||||||
|
num.add(26);
|
||||||
|
system.debug(num);
|
||||||
|
system.debug(num.contains(20));
|
||||||
|
set<string> cities= new set<string>();
|
||||||
|
cities.add('Delhi');
|
||||||
|
cities.add('Mumbai');
|
||||||
|
cities.add('Kolkata');
|
||||||
|
cities.add('Bhubaneswar');
|
||||||
|
system.debug(cities);
|
||||||
|
list<string> cities1= new list<string>();
|
||||||
|
cities1.add('Guwahati');
|
||||||
|
cities1.add('Hyderabad');
|
||||||
|
system.debug(cities1);
|
||||||
|
cities.addAll(cities1);
|
||||||
|
system.debug(cities);
|
||||||
|
//cities.clear();
|
||||||
|
set <string> cities2= cities.clone();
|
||||||
|
system.debug(cities2);
|
||||||
|
system.debug(cities.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void method4(){
|
||||||
|
map <integer,string> flowers= new map<integer,string>();
|
||||||
|
flowers.put(1,'Lotus');
|
||||||
|
flowers.put(2,'Lily');
|
||||||
|
flowers.put(3,'Hibiscus');
|
||||||
|
flowers.put(4,'Rose');
|
||||||
|
flowers.put(5,'Jasmine');
|
||||||
|
system.debug(flowers);
|
||||||
|
//flowers.clear();
|
||||||
|
system.debug(flowers);
|
||||||
|
system.debug(flowers.containskey(9));
|
||||||
|
map <integer,string> colors= new map<integer,string>();
|
||||||
|
colors.put(6,'Blue');
|
||||||
|
colors.put(7,'Red');
|
||||||
|
colors.put(8,'Yellow');
|
||||||
|
colors.put(9,'White');
|
||||||
|
flowers.putall(colors);
|
||||||
|
system.debug(flowers);
|
||||||
|
map <integer,string> flowers2= new map<integer,string>();
|
||||||
|
colors.remove(7);
|
||||||
|
system.debug(colors);
|
||||||
|
system.debug(colors.size());
|
||||||
|
system.debug(flowers.size());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
5
force-app/main/default/classes/training.cls-meta.xml
Normal file
5
force-app/main/default/classes/training.cls-meta.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>62.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexClass>
|
||||||
10
force-app/main/default/triggers/Assign1.trigger
Normal file
10
force-app/main/default/triggers/Assign1.trigger
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
trigger Assign1 on Account (before insert, before update)
|
||||||
|
{
|
||||||
|
for (Account acc: trigger.new)
|
||||||
|
{
|
||||||
|
if(acc.Name.contains('Tech'))
|
||||||
|
{
|
||||||
|
acc.Industry = 'Technology';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
force-app/main/default/triggers/Assign1.trigger-meta.xml
Normal file
5
force-app/main/default/triggers/Assign1.trigger-meta.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
13
force-app/main/default/triggers/AssignAccountOwner.trigger
Normal file
13
force-app/main/default/triggers/AssignAccountOwner.trigger
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
trigger AssignAccountOwner on Account (before insert)
|
||||||
|
{
|
||||||
|
Map<String, Id> industryUserMap = new Map<String, Id>{
|
||||||
|
'Technology' => 'UI1',
|
||||||
|
'Healthcare' => 'UI2'
|
||||||
|
};
|
||||||
|
for (Account acc : Trigger.new)
|
||||||
|
{
|
||||||
|
if (industryUserMap.containsKey(acc.Industry)) {
|
||||||
|
acc.OwnerId = industryUserMap.get(acc.Industry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
trigger CategorizedOpprtunity on Opportunity (before insert, before update) {
|
||||||
|
for (Opportunity opp : Trigger.New)
|
||||||
|
{
|
||||||
|
if (opp.Amount != null)
|
||||||
|
{
|
||||||
|
if (opp.Amount < 10000)
|
||||||
|
{
|
||||||
|
opp.Category__c = 'Small';
|
||||||
|
}
|
||||||
|
else if (opp.Amount >= 10000 && opp.Amount < 50000)
|
||||||
|
{
|
||||||
|
opp.Category__c = 'Medium';
|
||||||
|
} else if (opp.Amount >= 50000) {
|
||||||
|
opp.Category__c = 'Large';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
3
force-app/main/default/triggers/CreateCaseEmail.trigger
Normal file
3
force-app/main/default/triggers/CreateCaseEmail.trigger
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
trigger CreateCaseEmail on EmailMessage (before insert) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
31
force-app/main/default/triggers/DiscountOpportunity.trigger
Normal file
31
force-app/main/default/triggers/DiscountOpportunity.trigger
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
trigger DiscountOpportunity on Opportunity (before insert,before update) {
|
||||||
|
Map<Decimal, Decimal> discountTiers = new Map<Decimal, Decimal>
|
||||||
|
{
|
||||||
|
100000 => 0.10,
|
||||||
|
50000 => 0.05
|
||||||
|
};
|
||||||
|
|
||||||
|
Decimal maxDiscount = 20000;
|
||||||
|
|
||||||
|
for (Opportunity opportunity : Trigger.New)
|
||||||
|
{
|
||||||
|
Decimal discountAmount = 0;
|
||||||
|
|
||||||
|
for (Decimal tierAmount : discountTiers.keySet())
|
||||||
|
{
|
||||||
|
if (opportunity.Amount >= tierAmount)
|
||||||
|
{
|
||||||
|
discountAmount = opportunity.Amount * discountTiers.get(tierAmount);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (discountAmount > maxDiscount) {
|
||||||
|
opportunity.Discount_Amount__c.addError('Maximum discount exceeded!');
|
||||||
|
} else {
|
||||||
|
|
||||||
|
opportunity.Discount_Amount__c = discountAmount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
25
force-app/main/default/triggers/DuplicateContact.trigger
Normal file
25
force-app/main/default/triggers/DuplicateContact.trigger
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
trigger DuplicateContact on Contact (before insert) {
|
||||||
|
Set<String> emailAddresses = new Set<String>();
|
||||||
|
|
||||||
|
for (Contact contact : Trigger.New) {
|
||||||
|
if (emailAddresses.contains(contact.Email)) {
|
||||||
|
contact.Email.addError('Email already exists!');
|
||||||
|
} else {
|
||||||
|
emailAddresses.add(contact.Email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Contact> existingContacts = [
|
||||||
|
SELECT Id, Email
|
||||||
|
FROM Contact
|
||||||
|
WHERE Email IN :emailAddresses
|
||||||
|
];
|
||||||
|
|
||||||
|
for (Contact contact : Trigger.New) {
|
||||||
|
for (Contact existingContact : existingContacts) {
|
||||||
|
if (contact.Email == existingContact.Email && contact.Id != existingContact.Id) {
|
||||||
|
contact.Email.addError('Email already exists!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
trigger GenerateInvoiceNumber on Invoice (before insert) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
10
force-app/main/default/triggers/PreventHighValue.trigger
Normal file
10
force-app/main/default/triggers/PreventHighValue.trigger
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
trigger PreventHighValue on Opportunity (before insert)
|
||||||
|
{
|
||||||
|
for (Opportunity opp : Trigger.Old)
|
||||||
|
{
|
||||||
|
if (opp.Amount != null && opp.Amount > 100000)
|
||||||
|
{
|
||||||
|
Trigger.OldMap.get(opp.Id).addError('Cannot delete high-value opportunities!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
3
force-app/main/default/triggers/TotalRevenue.trigger
Normal file
3
force-app/main/default/triggers/TotalRevenue.trigger
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
trigger TotalRevenue on Account (before insert) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
3
force-app/main/default/triggers/UpdateAccount.trigger
Normal file
3
force-app/main/default/triggers/UpdateAccount.trigger
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
trigger UpdateAccount on Opportunity (before insert) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
25
force-app/main/default/triggers/UpdateCase.trigger
Normal file
25
force-app/main/default/triggers/UpdateCase.trigger
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
trigger UpdateCase on CaseComment (before insert) {
|
||||||
|
Map<String, String> keywordToStatus = new Map<String, String> {
|
||||||
|
'resolved' => 'Closed',
|
||||||
|
'fixed' => 'Closed',
|
||||||
|
'completed' => 'Closed',
|
||||||
|
'reopen' => 'Reopened',
|
||||||
|
'reopened' => 'Reopened'
|
||||||
|
};
|
||||||
|
|
||||||
|
for (CaseComment comment : Trigger.New) {
|
||||||
|
Case theCase = [
|
||||||
|
SELECT Id, Status
|
||||||
|
FROM Case
|
||||||
|
WHERE Id = :comment.ParentId
|
||||||
|
];
|
||||||
|
|
||||||
|
for (String keyword : keywordToStatus.keySet()) {
|
||||||
|
if (comment.CommentBody.toLowerCase().contains(keyword.toLowerCase())) {
|
||||||
|
theCase.Status = keywordToStatus.get(keyword);
|
||||||
|
update theCase;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
14
force-app/main/default/triggers/ValidNumber.trigger
Normal file
14
force-app/main/default/triggers/ValidNumber.trigger
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
trigger ValidNumber on Contact (before insert)
|
||||||
|
{
|
||||||
|
String phonePattern = '(123) 456-7890';
|
||||||
|
|
||||||
|
for (Contact contact : Trigger.New)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!Pattern.matches(phonePattern, contact.Phone))
|
||||||
|
{
|
||||||
|
|
||||||
|
contact.Phone.addError('Invalid phone format!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
31
force-app/main/default/triggers/ValidateAccount.trigger
Normal file
31
force-app/main/default/triggers/ValidateAccount.trigger
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
trigger ValidateAccount on Account (before insert) {
|
||||||
|
Set<String> accountNames = new Set<String>();
|
||||||
|
|
||||||
|
for (Account account : Trigger.New)
|
||||||
|
{
|
||||||
|
if (accountNames.contains(account.Name))
|
||||||
|
{
|
||||||
|
account.Name.addError('Account name already exists!');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
accountNames.add(account.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Account> existingAccounts = [
|
||||||
|
SELECT Id, Name
|
||||||
|
FROM Account
|
||||||
|
WHERE Name IN :accountNames
|
||||||
|
];
|
||||||
|
|
||||||
|
for (Account account : Trigger.New)
|
||||||
|
{
|
||||||
|
for (Account existingAccount : existingAccounts)
|
||||||
|
{
|
||||||
|
if (account.Name == existingAccount.Name && account.Id != existingAccount.Id)
|
||||||
|
{
|
||||||
|
account.Name.addError('Account name already exists!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>63.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexTrigger>
|
||||||
Reference in New Issue
Block a user