completed assignment
This commit is contained in:
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