Questions tagged [trigger]

A trigger is a feature of the Salesforce platform consisting of Apex code that executes before or after DML operations.

Filter by
Sorted by
Tagged with
0 votes
0 answers
19 views

Automatic trigger to print shipping label when opportunity record reaches a specific stage

Our small business recently purchased a shipping label printer. We have our own delivery team that delivers window replacements so we do not need to integrate to specific shipping carrier format like ...
user avatar
-1 votes
1 answer
25 views

Change to which email address email is sent

I have a task to create funcionality that will select To Address based on Preffered email picklist value. Example: Contact has 2 emails - private and business. Contact has picklist value of Prefferred ...
user avatar
0 votes
1 answer
37 views

Before insert trigger List has no rows for assignment to SObject

I want with this before insert trigger to get for the first the last OBJ__c created for my Account(Compte__c) and put the value in the field (Last__c ) and also get the other information (Compte__r....
user avatar
-2 votes
1 answer
26 views

Apex Test Class assertion fails on mismatched strings

Actual Class: trigger AvoidDeleteRequirementRecordWhenStatusIsApproved on Requirement__c (before delete) { for(Requirement__c r : trigger.old){ if(r.Status__c == 'Approved'){ ...
user avatar
  • 1
0 votes
1 answer
12 views

how to copy value from a account field in my case type_of_customer__c of picklist datatype to contact field of same field name?

public class contactTriggerHandler { public void beforeInsert(List<contact> newList) { set<ID> s= new set<ID>(); for(contact con: newList) { ...
user avatar
0 votes
1 answer
16 views

Send Marketing Cloud email out when RSS Feed updates

I have a working email that populates with the RSS feed code, but I am now wondering how can I automate this email to send out to its subscribers whenever there is a new post/article on the RSS xml. I ...
user avatar
  • 13
0 votes
0 answers
43 views

How to remove duplicate value in an salesforce custom object

KYC is a custom object, Kyc is having a lookup with account and lead. I have written 2 triggers to create KYC records one on the lead and another on the account. Now when the lead is created KYC ...
user avatar
-1 votes
0 answers
24 views

How to implement a logic that stores on fields how many child records are on the parent entity

I am novice in anything connected to salesforce(I mostly learn Java). So, the task is to Create two custom fields on the Account object: a. Contact Count (Contact_Count__c) b. Opportunity Count (...
user avatar
-1 votes
1 answer
26 views

check if record with same mobile number exists in two different objects

I am learning salesforce. I need to check if record with same mobile number exists in two different objects. So how can i achieve this. Kindly help, efforts are appreciated
user avatar
0 votes
0 answers
19 views

Issue in capturing approval comments in trigger

Helper class: Public class HelperClass_ApprovalTrigger{ Public static void afterTrigger(List<Grant_Contract__c> newList) { User gUser = new User(); gUser=[SELECT ...
user avatar
  • 11
0 votes
0 answers
25 views

Send a post request after an update

I'm trying to send a post request after an update from a record, and then is going to generate a link for the post request, I had the idea to create the post request after an insert using a trigger ...
user avatar
1 vote
0 answers
42 views

Difference in behaviour of a class when invoked in Platform Event Trigger vs Anonymous Apex

Hello SF StackExchange community, I am currently encountering a strange behaviour with Platform Events Trigger and couldn't find an explanation. I am getting the "attempt to de-reference a null ...
user avatar
  • 75
0 votes
0 answers
21 views

Before insert trigger based on a field

I want by my code to Retrieve the Last Object inserted by its creation date in the LastObject__c field in a before insert Trigger . I don't now if this code is correct or now . Some help please ...
user avatar
0 votes
1 answer
34 views

Hello there this is my Trigger on Account and have to convert this code for mass usage using batch class can anyone help with that?

trigger AccountTrigger001 on Account (after insert, after update) { if(trigger.isInsert == true && trigger.isAfter == true){ AccountTriggerHelperClass001.accData(trigger.new); }...
user avatar
0 votes
1 answer
43 views

Trigger to detect user password change

When a user change the password, the API field, LastPasswordChangeDate, on the User got updated. This can be seen with SOQL query. However, the UserTrigger never fires. The UserTrigger fires properly ...
user avatar
  • 1
0 votes
0 answers
39 views

How to write a trigger that is used dynamically [closed]

Here i created a trigger that is for rollup b/w account and contact , now i need to rollup on different objects ,here what evere the trigger that am using need to work for Account & Contact as ...
user avatar
-2 votes
0 answers
32 views

Add 10 business days in Opportunity.CloseDate [closed]

New Object: Holidays__c fields: Name, HolidayDate__c Requirement: If Opportunity close date comes in next 3 days then we need to update Opportunity CloseDate with new date by adding 10 working days. ...
user avatar
-1 votes
0 answers
26 views

Prevent insertion of record in trigger without using addError() [closed]

I have two Object. 1] Team Members 2] Extra Members. What i want is, i want to store records of member to 'Team Members' Object. if there is already 11 members then 12th record should be stored in '...
user avatar
-1 votes
0 answers
35 views

I create a Trigger on Lead Before Crate And Update . This Trigger Works on Single Record but When i try to Insert Multiple Record it Fails to FIRE

I create a Trigger on Lead Before Crate And Update . This Trigger Works on Single Record but When i try to Insert Multiple Record it Fails to FIRE Please help to improve my Knowledge And skills ...
user avatar
0 votes
0 answers
24 views

facing Error while updating updating the field [closed]

I created a trigger on the Invoice which is Child of Order form, and Order form is a child of Brokerage. Once Invoice Status is 'Paid' then the total 'Number of User' (Field) which is available in ...
user avatar
-1 votes
0 answers
18 views

What will be the test class for it [duplicate]

public static void leadShareWithSales(map<Id,Lead> newLeadMap){ Map<Id, List<Lead>> mapLeadOwnerIdToLead =new Map<Id, List<Lead>>(); Map<Id,...
user avatar
0 votes
1 answer
29 views

APEX Trigger Help: Create a New Task when Task Status is Completed and when certain field in Contact Object is not met

everyone! I just started learning APEX last week, and I'm now learning APEX Triggers. I need help for the task below. Overview: I created a new field in Contact Object: "Details Completed" (...
user avatar
0 votes
0 answers
17 views

Salesforce API when will trigger fire on updating multiple dependant fields

I am updating multiple fields within a single sobjects/customobj__c Salesforce client Patch request. All these fields are on the same customobj__c object for a single record. I have say 2 fields in ...
user avatar
0 votes
1 answer
47 views

Database.executeBatch cannot be called from a batch [closed]

it gives "Database.executeBatch cannot be called from a batch start, batch execute, or future method." error . I'm trying to resend the request for all failed callouts for every once in a ...
user avatar
2 votes
1 answer
69 views

Is it possible to use a date range as map's key and then use a date to find the entry?

I have a list of records that map to a particular date range. For eg: 1 Jan 2020 - 31 Dec 2020 -> Toyota, Aston Martin 1 Jan 2021 - 31 Dec 2021 -> Red Bull, Mercedes, Ferrari 1 Jan 2022 - 31 ...
user avatar
  • 195
0 votes
1 answer
34 views

Update record type on the basis of field change

I have custom object example - Agreement and I would like to change the record type if my field type value is changed, below is my code ( I am able to save the code but while testing I am geeting ...
user avatar
  • 1
0 votes
1 answer
23 views

What is the best way to send notification after a field change? [closed]

I want to send a notification to the user every time a specific field (SecondName__c) is changed What would be the best way to do this? Trigger or flow?
user avatar
  • 35
0 votes
1 answer
28 views

How to dynamically use Object Name in the List in Apex?

I am trying to pass a dynamic value in the List to store the data from a respective object. But, this code is throwing me an error - 'Unexpected <'. Please help. public static void delRecords(List&...
user avatar
0 votes
0 answers
39 views

Last Modified By is getting updated without user logging in

I am recently, seeing an issue in my production org, that cases records are coming from external systems & they were assigning to different users due to assignment rules were configured & ...
user avatar
2 votes
1 answer
59 views

Apex Trigger error message working for all languages except for one

I created a simple Apex Trigger that shows an error message when user tries to create an event without adding any attendee. I created a custom label for error message and its translations in different ...
user avatar
0 votes
1 answer
30 views

Delete records when a field is updated [closed]

I am having a condition where we are having a field called number of employees in Account object and we have to create same number of contacts associated with the perticular account. And If we update ...
user avatar
-1 votes
2 answers
46 views

I am unable to send email to gmail and yahoo from Salesforce trigger

I can send email to any where in Test Email Deliverability in sales without any problem. But if i use trigger to send email out, it does not send to yahoo email and gmail but i can send email to any ...
user avatar
  • 1
0 votes
2 answers
51 views

Automated Process User in Salesforce

We are trying to automated some of the data maskign activities as part of our post sandbox refresh activity. We have achieved this by implementing sandboxpostcopy interface. I found out that the apex ...
user avatar
  • 87
1 vote
0 answers
29 views

The price book entry is in a different price book than the one assigned to the Work Order, [closed]

hi i'm trying to test a class with price book entry and work order and Product Consumed but i got this error when i insert a product consumed: FIELD_INTEGRITY_EXCEPTION, The price book entry is in a ...
user avatar
  • 11
0 votes
2 answers
37 views

Trigger to generate contract numbers for each record type

I am working on a trigger which should generate grant contract numbers according to a particular format. For each RT: RT starting Number Ending Number WF 2300021 2301999 SAT 2304020 2306999 ...
user avatar
  • 11
0 votes
1 answer
54 views

How to dynamically query any Field's Picklist values using Apex

In the line - objApi.fieldApi.getDescribe().getPicklistValues(), I am trying to pass ObjApi as Object API and fieldApi as Field API in the parameters. So that it will form like this - Account....
user avatar
0 votes
1 answer
31 views

Error: Compile Error: Unexpected token

Error: Compile Error: Unexpected token 'acc.Name'. at line 8 column 56 trigger duplicaterestriction on Account (before insert) { list<Account>acclist = new list<Account>(); ...
user avatar
  • 1
0 votes
1 answer
39 views

Asset Trigger Handler to update Fields on asset object in After Insert/Update

Am having a scenario where Assets is being created using orchestration definition Auto task and assets linked to the billing account of the customer. In the Asset Trigger, For afterInsert: Retrieve ...
user avatar
0 votes
0 answers
25 views

Trigger for restricting profile edit

I am currently putting together trigger to prevent users to edit their own profile. This version is working trigger PreventUserDetailUpdate on User (before update) { Set<id> updatedUsers = ...
user avatar
  • 11
0 votes
2 answers
62 views

Best practice: formula field in child record to reference parent field

I found this question Best Practice: Formula field Vs new (duplicate) field but it's a bit old and it didn't get much traction anyway. I have a field Minion__c in the parent record and I need a field ...
user avatar
0 votes
0 answers
30 views

Hi, I am stuck in one addError method

If any opportunity does not have OpportunityContactRoles with role as "Primary Contact" at the time of making opportunity stage as closed should give error message. public static void ...
user avatar
  • 17
0 votes
1 answer
40 views

MALFORMED_ID error after an update

I have two custom objects with a lookup relationship which are Voucher(parent) and Certification Request(child). I want to assign the first available valid Voucher to the Certification Record after ...
user avatar
0 votes
1 answer
46 views

Apex Trigger on Related Object - Updating wrong field

I'm trying to create a trigger on the Task object that would stamp a field from a related object (Account), the field is Account Type. I'm unable to use flow for this requirement since there are ...
user avatar
  • 3
-1 votes
1 answer
37 views

Before Trigger or After Trigger when DML needs to be performed on two diff objects [closed]

I am confused on which Trigger event to use, Before or After. Say, for eg. I have a trigger on Account. In trigger handler logic I need to update a field on Account (same object, hence we would prefer ...
user avatar
  • 3
0 votes
1 answer
46 views

Can we call a batch class from trigger only after trigger has finished processing all the records

I have a trigger from which I am calling a batch class. When I insert a bulk amount of data the trigger is fired for every 200 records and the batch is getting executed. Hence multiple batches are ...
user avatar
0 votes
1 answer
52 views

How to insert custom object record by using platform event for error logging?

We want to insert an error log record in the org whenever we receive any error in trigger execution but we want to do it by using platform event. We have tried to insert a record but were not able to ...
user avatar
  • 3
0 votes
1 answer
27 views

Custom field being assigned during account insert is coming up null in custom object trigger test

I am trying to test a new check added to a custom object trigger (if (!String.isBlank(ap.Patient__r.ExternalId__c))). When running the test, ExternalId__c is coming up null. It is being assigned when ...
user avatar
  • 27
-1 votes
1 answer
45 views

Can someone please help me on this one.If zip code is changed account owner should be changed to the sales representative

public class AccountHandler { public static void AccountOwnerChange(List<Account> lstAccs) { Set<String> setOfZipcodes = new Set<String>(); Map<String, Id> ...
user avatar
0 votes
0 answers
21 views

Hide Email2Case email for specific User Roles

We are using different Email2case for different teams. The thing is that only specific teams should be able to see them for example Austria team will need to see Sales.austria@selina.com but not ...
user avatar
  • 313
0 votes
1 answer
38 views

write a trigger on the task object to restrict the users not to delete the tasks whose case status is escalated

trigger NewTask4 on Task (before delete) { List<Case> Cases =[select id, CaseNumber, Status from Case where Status= 'Escalated']; For(Case C:Cases){ for(Task t1:Trigger.old){ ...
user avatar
  • 1

1
2 3 4 5
153