From 72f2541f583caf2ba8acfafe1121cf7041104179 Mon Sep 17 00:00:00 2001 From: "anasuya.jana" Date: Wed, 2 Apr 2025 17:50:49 +0530 Subject: [PATCH] completed assignment --- force-app/main/default/classes/Assigmnt2.cls | 3 + .../default/classes/Assigmnt2.cls-meta.xml | 5 + force-app/main/default/classes/assigment.cls | 166 ++++++++++++++++++ .../default/classes/assigment.cls-meta.xml | 5 + force-app/main/default/classes/training.cls | 93 ++++++++++ .../default/classes/training.cls-meta.xml | 5 + .../main/default/triggers/Assign1.trigger | 10 ++ .../default/triggers/Assign1.trigger-meta.xml | 5 + .../triggers/AssignAccountOwner.trigger | 13 ++ .../AssignAccountOwner.trigger-meta.xml | 5 + .../triggers/CategorizedOpprtunity.trigger | 18 ++ .../CategorizedOpprtunity.trigger-meta.xml | 5 + .../default/triggers/CreateCaseEmail.trigger | 3 + .../triggers/CreateCaseEmail.trigger-meta.xml | 5 + .../triggers/DiscountOpportunity.trigger | 31 ++++ .../DiscountOpportunity.trigger-meta.xml | 5 + .../default/triggers/DuplicateContact.trigger | 25 +++ .../DuplicateContact.trigger-meta.xml | 5 + .../triggers/GenerateInvoiceNumber.trigger | 3 + .../GenerateInvoiceNumber.trigger-meta.xml | 5 + .../default/triggers/PreventHighValue.trigger | 10 ++ .../PreventHighValue.trigger-meta.xml | 5 + .../default/triggers/TotalRevenue.trigger | 3 + .../triggers/TotalRevenue.trigger-meta.xml | 5 + .../default/triggers/UpdateAccount.trigger | 3 + .../triggers/UpdateAccount.trigger-meta.xml | 5 + .../main/default/triggers/UpdateCase.trigger | 25 +++ .../triggers/UpdateCase.trigger-meta.xml | 5 + .../main/default/triggers/ValidNumber.trigger | 14 ++ .../triggers/ValidNumber.trigger-meta.xml | 5 + .../default/triggers/ValidateAccount.trigger | 31 ++++ .../triggers/ValidateAccount.trigger-meta.xml | 5 + 32 files changed, 531 insertions(+) create mode 100644 force-app/main/default/classes/Assigmnt2.cls create mode 100644 force-app/main/default/classes/Assigmnt2.cls-meta.xml create mode 100644 force-app/main/default/classes/assigment.cls create mode 100644 force-app/main/default/classes/assigment.cls-meta.xml create mode 100644 force-app/main/default/classes/training.cls create mode 100644 force-app/main/default/classes/training.cls-meta.xml create mode 100644 force-app/main/default/triggers/Assign1.trigger create mode 100644 force-app/main/default/triggers/Assign1.trigger-meta.xml create mode 100644 force-app/main/default/triggers/AssignAccountOwner.trigger create mode 100644 force-app/main/default/triggers/AssignAccountOwner.trigger-meta.xml create mode 100644 force-app/main/default/triggers/CategorizedOpprtunity.trigger create mode 100644 force-app/main/default/triggers/CategorizedOpprtunity.trigger-meta.xml create mode 100644 force-app/main/default/triggers/CreateCaseEmail.trigger create mode 100644 force-app/main/default/triggers/CreateCaseEmail.trigger-meta.xml create mode 100644 force-app/main/default/triggers/DiscountOpportunity.trigger create mode 100644 force-app/main/default/triggers/DiscountOpportunity.trigger-meta.xml create mode 100644 force-app/main/default/triggers/DuplicateContact.trigger create mode 100644 force-app/main/default/triggers/DuplicateContact.trigger-meta.xml create mode 100644 force-app/main/default/triggers/GenerateInvoiceNumber.trigger create mode 100644 force-app/main/default/triggers/GenerateInvoiceNumber.trigger-meta.xml create mode 100644 force-app/main/default/triggers/PreventHighValue.trigger create mode 100644 force-app/main/default/triggers/PreventHighValue.trigger-meta.xml create mode 100644 force-app/main/default/triggers/TotalRevenue.trigger create mode 100644 force-app/main/default/triggers/TotalRevenue.trigger-meta.xml create mode 100644 force-app/main/default/triggers/UpdateAccount.trigger create mode 100644 force-app/main/default/triggers/UpdateAccount.trigger-meta.xml create mode 100644 force-app/main/default/triggers/UpdateCase.trigger create mode 100644 force-app/main/default/triggers/UpdateCase.trigger-meta.xml create mode 100644 force-app/main/default/triggers/ValidNumber.trigger create mode 100644 force-app/main/default/triggers/ValidNumber.trigger-meta.xml create mode 100644 force-app/main/default/triggers/ValidateAccount.trigger create mode 100644 force-app/main/default/triggers/ValidateAccount.trigger-meta.xml diff --git a/force-app/main/default/classes/Assigmnt2.cls b/force-app/main/default/classes/Assigmnt2.cls new file mode 100644 index 0000000..1d8dbdf --- /dev/null +++ b/force-app/main/default/classes/Assigmnt2.cls @@ -0,0 +1,3 @@ +public class Assigmnt2 { + +} \ No newline at end of file diff --git a/force-app/main/default/classes/Assigmnt2.cls-meta.xml b/force-app/main/default/classes/Assigmnt2.cls-meta.xml new file mode 100644 index 0000000..5f399c3 --- /dev/null +++ b/force-app/main/default/classes/Assigmnt2.cls-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/classes/assigment.cls b/force-app/main/default/classes/assigment.cls new file mode 100644 index 0000000..6c411ef --- /dev/null +++ b/force-app/main/default/classes/assigment.cls @@ -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> movieMap = new Map> + { + 'Action' => new List{'Mad Max', 'Gladiator', 'Die Hard'}, + 'Comedy' => new List{'Superbad', 'Step Brothers', 'The Hangover'}, + 'Drama' => new List{'The Shawshank Redemption', 'Forrest Gump', 'Fight Club'}, + 'Horror' => new List{'The Conjuring', 'Get Out', 'It'}, + 'Sci-Fi' => new List{'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 order) + { + Map menu = new Map + { + '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 employees) + { + Decimal bonusAmount; + Map bonusMap = new Map(); + + 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 patientList = new List(); +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 emergencyLevelList = new List{ + 'Critical', 'Severe', 'Normal' +}; + +// LIST TO STORE SORTED PATIENTS WITH EMERGENCY LEVEL +List sortedPatientList = new List(); + +// 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 sortPatientsByPriority = new map(); + + map Patients = new map(); + Patients.put('Ram', ' Normal'); + Patients.put('Gopal','Critical'); + Patients.put('Roshan','Severe'); + Patients.put('Sham','Normal'); + system.debug('Patient before sort patient:' +Patients); + + map emergencyLevel = new map(); + 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); + } + + + + + + +} \ No newline at end of file diff --git a/force-app/main/default/classes/assigment.cls-meta.xml b/force-app/main/default/classes/assigment.cls-meta.xml new file mode 100644 index 0000000..5f399c3 --- /dev/null +++ b/force-app/main/default/classes/assigment.cls-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/classes/training.cls b/force-app/main/default/classes/training.cls new file mode 100644 index 0000000..f4dd5e9 --- /dev/null +++ b/force-app/main/default/classes/training.cls @@ -0,0 +1,93 @@ +public class training { + public static void abc(){ + list cities= new list(); + cities.add('Delhi'); + cities.add(0,'Mumbai'); + cities.add('Kolkata'); + System.debug('cities'+ cities); + list fruits= new list(); + 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 num= new set(); + num.add(10); + num.add(15); + num.add(20); + num.add(25); + num.add(26); + system.debug(num); + system.debug(num.contains(20)); + set cities= new set(); + cities.add('Delhi'); + cities.add('Mumbai'); + cities.add('Kolkata'); + cities.add('Bhubaneswar'); + system.debug(cities); + list cities1= new list(); + cities1.add('Guwahati'); + cities1.add('Hyderabad'); + system.debug(cities1); + cities.addAll(cities1); + system.debug(cities); + //cities.clear(); + set cities2= cities.clone(); + system.debug(cities2); + system.debug(cities.size()); + } + + public static void method4(){ + map flowers= new map(); + 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 colors= new map(); + colors.put(6,'Blue'); + colors.put(7,'Red'); + colors.put(8,'Yellow'); + colors.put(9,'White'); + flowers.putall(colors); + system.debug(flowers); + map flowers2= new map(); + colors.remove(7); + system.debug(colors); + system.debug(colors.size()); + system.debug(flowers.size()); + + } +} \ No newline at end of file diff --git a/force-app/main/default/classes/training.cls-meta.xml b/force-app/main/default/classes/training.cls-meta.xml new file mode 100644 index 0000000..998805a --- /dev/null +++ b/force-app/main/default/classes/training.cls-meta.xml @@ -0,0 +1,5 @@ + + + 62.0 + Active + diff --git a/force-app/main/default/triggers/Assign1.trigger b/force-app/main/default/triggers/Assign1.trigger new file mode 100644 index 0000000..0cb0589 --- /dev/null +++ b/force-app/main/default/triggers/Assign1.trigger @@ -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'; + } +} +} \ No newline at end of file diff --git a/force-app/main/default/triggers/Assign1.trigger-meta.xml b/force-app/main/default/triggers/Assign1.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/Assign1.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/triggers/AssignAccountOwner.trigger b/force-app/main/default/triggers/AssignAccountOwner.trigger new file mode 100644 index 0000000..df662d5 --- /dev/null +++ b/force-app/main/default/triggers/AssignAccountOwner.trigger @@ -0,0 +1,13 @@ +trigger AssignAccountOwner on Account (before insert) +{ + Map industryUserMap = new Map{ + 'Technology' => 'UI1', + 'Healthcare' => 'UI2' + }; + for (Account acc : Trigger.new) + { + if (industryUserMap.containsKey(acc.Industry)) { + acc.OwnerId = industryUserMap.get(acc.Industry); + } + } +} \ No newline at end of file diff --git a/force-app/main/default/triggers/AssignAccountOwner.trigger-meta.xml b/force-app/main/default/triggers/AssignAccountOwner.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/AssignAccountOwner.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/triggers/CategorizedOpprtunity.trigger b/force-app/main/default/triggers/CategorizedOpprtunity.trigger new file mode 100644 index 0000000..345584f --- /dev/null +++ b/force-app/main/default/triggers/CategorizedOpprtunity.trigger @@ -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'; + } + } + } +} \ No newline at end of file diff --git a/force-app/main/default/triggers/CategorizedOpprtunity.trigger-meta.xml b/force-app/main/default/triggers/CategorizedOpprtunity.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/CategorizedOpprtunity.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/triggers/CreateCaseEmail.trigger b/force-app/main/default/triggers/CreateCaseEmail.trigger new file mode 100644 index 0000000..247b6c4 --- /dev/null +++ b/force-app/main/default/triggers/CreateCaseEmail.trigger @@ -0,0 +1,3 @@ +trigger CreateCaseEmail on EmailMessage (before insert) { + +} \ No newline at end of file diff --git a/force-app/main/default/triggers/CreateCaseEmail.trigger-meta.xml b/force-app/main/default/triggers/CreateCaseEmail.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/CreateCaseEmail.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/triggers/DiscountOpportunity.trigger b/force-app/main/default/triggers/DiscountOpportunity.trigger new file mode 100644 index 0000000..1bf5c85 --- /dev/null +++ b/force-app/main/default/triggers/DiscountOpportunity.trigger @@ -0,0 +1,31 @@ +trigger DiscountOpportunity on Opportunity (before insert,before update) { + Map discountTiers = new Map + { + 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; + } + } + +} \ No newline at end of file diff --git a/force-app/main/default/triggers/DiscountOpportunity.trigger-meta.xml b/force-app/main/default/triggers/DiscountOpportunity.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/DiscountOpportunity.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/triggers/DuplicateContact.trigger b/force-app/main/default/triggers/DuplicateContact.trigger new file mode 100644 index 0000000..fd2fa9e --- /dev/null +++ b/force-app/main/default/triggers/DuplicateContact.trigger @@ -0,0 +1,25 @@ +trigger DuplicateContact on Contact (before insert) { + Set emailAddresses = new Set(); + + for (Contact contact : Trigger.New) { + if (emailAddresses.contains(contact.Email)) { + contact.Email.addError('Email already exists!'); + } else { + emailAddresses.add(contact.Email); + } + } + + List 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!'); + } + } + } +} \ No newline at end of file diff --git a/force-app/main/default/triggers/DuplicateContact.trigger-meta.xml b/force-app/main/default/triggers/DuplicateContact.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/DuplicateContact.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/triggers/GenerateInvoiceNumber.trigger b/force-app/main/default/triggers/GenerateInvoiceNumber.trigger new file mode 100644 index 0000000..c4ce9b2 --- /dev/null +++ b/force-app/main/default/triggers/GenerateInvoiceNumber.trigger @@ -0,0 +1,3 @@ +trigger GenerateInvoiceNumber on Invoice (before insert) { + +} \ No newline at end of file diff --git a/force-app/main/default/triggers/GenerateInvoiceNumber.trigger-meta.xml b/force-app/main/default/triggers/GenerateInvoiceNumber.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/GenerateInvoiceNumber.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/triggers/PreventHighValue.trigger b/force-app/main/default/triggers/PreventHighValue.trigger new file mode 100644 index 0000000..b3cc12a --- /dev/null +++ b/force-app/main/default/triggers/PreventHighValue.trigger @@ -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!'); + } + } +} \ No newline at end of file diff --git a/force-app/main/default/triggers/PreventHighValue.trigger-meta.xml b/force-app/main/default/triggers/PreventHighValue.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/PreventHighValue.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/triggers/TotalRevenue.trigger b/force-app/main/default/triggers/TotalRevenue.trigger new file mode 100644 index 0000000..33e6057 --- /dev/null +++ b/force-app/main/default/triggers/TotalRevenue.trigger @@ -0,0 +1,3 @@ +trigger TotalRevenue on Account (before insert) { + +} \ No newline at end of file diff --git a/force-app/main/default/triggers/TotalRevenue.trigger-meta.xml b/force-app/main/default/triggers/TotalRevenue.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/TotalRevenue.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/triggers/UpdateAccount.trigger b/force-app/main/default/triggers/UpdateAccount.trigger new file mode 100644 index 0000000..3e67a03 --- /dev/null +++ b/force-app/main/default/triggers/UpdateAccount.trigger @@ -0,0 +1,3 @@ +trigger UpdateAccount on Opportunity (before insert) { + +} \ No newline at end of file diff --git a/force-app/main/default/triggers/UpdateAccount.trigger-meta.xml b/force-app/main/default/triggers/UpdateAccount.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/UpdateAccount.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/triggers/UpdateCase.trigger b/force-app/main/default/triggers/UpdateCase.trigger new file mode 100644 index 0000000..f8ea2cd --- /dev/null +++ b/force-app/main/default/triggers/UpdateCase.trigger @@ -0,0 +1,25 @@ +trigger UpdateCase on CaseComment (before insert) { + Map keywordToStatus = new Map { + '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; + } + } + } +} \ No newline at end of file diff --git a/force-app/main/default/triggers/UpdateCase.trigger-meta.xml b/force-app/main/default/triggers/UpdateCase.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/UpdateCase.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/triggers/ValidNumber.trigger b/force-app/main/default/triggers/ValidNumber.trigger new file mode 100644 index 0000000..aa8e4ae --- /dev/null +++ b/force-app/main/default/triggers/ValidNumber.trigger @@ -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!'); + } + } +} \ No newline at end of file diff --git a/force-app/main/default/triggers/ValidNumber.trigger-meta.xml b/force-app/main/default/triggers/ValidNumber.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/ValidNumber.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active + diff --git a/force-app/main/default/triggers/ValidateAccount.trigger b/force-app/main/default/triggers/ValidateAccount.trigger new file mode 100644 index 0000000..3e0df8b --- /dev/null +++ b/force-app/main/default/triggers/ValidateAccount.trigger @@ -0,0 +1,31 @@ +trigger ValidateAccount on Account (before insert) { + Set accountNames = new Set(); + + for (Account account : Trigger.New) + { + if (accountNames.contains(account.Name)) + { + account.Name.addError('Account name already exists!'); + } + else { + accountNames.add(account.Name); + } + } + + List 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!'); + } + } + } +} \ No newline at end of file diff --git a/force-app/main/default/triggers/ValidateAccount.trigger-meta.xml b/force-app/main/default/triggers/ValidateAccount.trigger-meta.xml new file mode 100644 index 0000000..e71d5ec --- /dev/null +++ b/force-app/main/default/triggers/ValidateAccount.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 63.0 + Active +