Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Make your voice heard. Take the 2019 Developer Survey now

Questions tagged [trigger]

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

0
votes
1answer
8 views

I'm having hard time bulkifying a code that attach similar deals to an opportunity when is created

the parameters are: amount within 10% of difference closed won last year Same industry I'm having hard time since is I have to validate 3 parameters instead one. Below you have the non-bulkified ...
0
votes
2answers
24 views

Trigger to prevent duplicate combination of 3 fields on insert and update

We have 3 picklist fields Dom1, Dom2, and Dom3. We want to write a trigger before insert and update to prevent duplicate records with the same combination of these 3 fields. For Example: Dom1 ...
2
votes
2answers
16 views

Trigger unit test or integration test

I have written some apex triggers along with some classes. The triggers are quite small because all the real work happens in the classes. trigger MyAccountTrigger on Account (after insert, after ...
0
votes
2answers
43 views

Apex Trigger on Attachment object not being fired

I wrote this apex trigger for Attachment sObject following the answer here. The trigger basically counts the total number of attachments for a record of type Assignment__c and updates the field ...
0
votes
0answers
16 views

Issue In platform event after Insert Calling twice due to Process builder

I have created one platform event and publishing the json in it on account creation. I have one Process builder which populating the field on account creation. the issue is my Platform event is ...
0
votes
0answers
13 views

Test Email-to-Case with mass emails and EMailMessage trigger

We are working on an org where cases are generated via Email-to-Case and a trigger on EmailMessage is carrying out some processes. A batch job then in a 5 minute rhythm works on these generated cases ...
-2
votes
0answers
34 views

how to get the id [on hold]

how can we get the id if records will be inserted from one object to another object here i created one custom object and Iam inserting records from custom object whenever that records inserted in ...
-2
votes
0answers
14 views

I need help with an apex trigger? I know that I should do something like this x.10/100 [on hold]

2-Create the object called “Books” and create field “Price”(data type is Currency) under this object. Whenever we enter some amount of money in the Price field and once we click on save button, the ...
0
votes
1answer
26 views

Trigger to add contact in Account Related list when contact is added through lookup on Account

I have one lookup field (Add contact) on Account. My requirement is that when we update the account lookup field and select a contact. Then that contact should get attached in the related Contact List ...
0
votes
1answer
21 views

Trigger for First/Most Recent Campaign on Contacts

trying to write a simple trigger for populating a couple of custom lookup fields on Contacts. We have 2 custom fields called "First Campaign" and "Most Recent Campaign". I'm trying to get "First ...
-2
votes
0answers
18 views

convert Bulk of Leads,ten thouand. one by one serially.my leads are in csv.any ..? [on hold]

global Database.QueryLocator start(Database.BatchableContext context) { return Database.getQueryLocator([SELECT Id,LastName,LastModifiedD__c FROM Lead ]); } global void execute(...
-1
votes
2answers
30 views

Disclaimer Popup on Chatter Group [on hold]

I want to add a disclaimer message on a chatter group. When new user join chatter group he/she needs to accept disclaimer message. Can anybody help me on this because there is no standard way to do ...
3
votes
2answers
64 views

Need help understanding this apex trigger example

I'm just starting out in apex. I want to create a trigger that counts the number of attachments in a record of a custom object. I came across an example here. Here's the trigger code: trigger ...
-4
votes
0answers
25 views

Convert Process Builder logic to code [closed]

I am trying to convert PB logic to Apex class and call the Apex class from a trigger on custom Object. Can anyone help me with writing the Apex class? The Process Builder updates a checkbox on ...
0
votes
1answer
53 views

Trigger to prevent Duplicate and add Add Task to Existing

I am trying to prevent duplicate Lead records from being created when users import Lead records into Salesforce that have the same email address. Here is the scenerio: A user imports leads using the ...
-1
votes
0answers
24 views

Create a task based on Date/Time field value [on hold]

I have a requirement where i need to create a task based on a field value: In case object I have a custom Date/Time field called 'call_me_Back__c' that I wish to create a new task ('subject= call', '...
0
votes
2answers
53 views

Not able to insert multiple records on other object by using trigger

I have two custom Object name Loan and EMI. Now whenever new Loan is created with Fields Loan_Amount , No_of_EMI and others fields , multiple rows(=number of emi accounts) should be created in EMI ...
0
votes
2answers
31 views

validation on lookup object

I have lookup on account of Sell_Request__c object. I want validation on Sell_Request__c to check if account-status is Inprogress then thrown an error.but i am not able to achieve this as not able to ...
0
votes
2answers
37 views

Removing record reference in class

Expansion to original question: Error: Future method cannot be called Need to remove record variable from reference. Can someone help me and explain the process? Error: Error: Compile Error: ...
1
vote
2answers
129 views

Error: Future method cannot be called

Getting the error below while introducing a new app. The new app is attempting to update all accounts and this is happening. Most likely because it is maxing out the callout limit. I can deactivate it ...
-3
votes
0answers
40 views

I need help with the below trigger [closed]

the trigger should be on account to check the assets and if ALL Assets where product family = "bla bla " and their status was "Canceled" the trigger should update bla bla Account stage (API Name = ...
0
votes
1answer
24 views

Setting a field value to the same object with a Trigger

I have two fields. Cost_price__c & Previous_book_value__c Currently, I use a Trigger on my Asset object to create a bunch of other objects and related records. However, I need to map the field ...
-1
votes
2answers
43 views

trigger to Preventing the users to create Duplicate Accounts im getting Variable does not exist: Name error

trigger AccountDuplicateTrigger on Account (before insert) { for(Account a:Trigger.new) { List<Account> acc=[Select id from Account where Name='a.Name' and Rating='a.Rating']; if(acc.size()&...
-2
votes
0answers
52 views

Execution of BeforeInsert caused by: System.ListException: Before Insert or Upsert list must not have two identically equal elements [closed]

Insertion failed : I have two objects Loan and EMI. When I insert record for Loan then number of records should be inserted in EMI Object based on number of EMI Counts. I am getting below error ...
1
vote
2answers
29 views

How to use trigger design pattern: ERROR Constructor not defined: [CaseTriggerHandler].<Constructor>()

I am trying to follow the best practice design patterns for triggers but get the error Constructor not defined: [CaseTriggerHandler].(). What am I missing? Trigger trigger CaseTrigger on Case (...
0
votes
3answers
34 views

Choose which records to insert/update in Apex Trigger

I have a trigger that is triggered before update or before insert for(CustomerProfile__c cp : listCustomerProfiles){ if(...){ cp.addError('A Customer Profile record has ...
3
votes
1answer
67 views

Combining similar code with different objects

I have 4 very similar code blocks in a trigger that deal with synchronizing record type changes from Opportunity to its children. The only difference between them is that they do work on different ...
0
votes
2answers
24 views

PrePopulate Task with related data even before creating a Task

I am trying to populate the Task with related data even before creating a task. For example in this Task creation, I have RelatedTo(Loan) autofilled, similarly I want LoanNumber and ClientName to be ...
3
votes
3answers
307 views

How can I know if it's the last execution of an After Trigger?

Imagine one object with 20 fields, field1 to field20. Some of these fields I have Process Builder in place, some of them I have Worflow Updates, and some of them are 'bare field' (i.e. PB and WF does ...
0
votes
1answer
14 views

Concatenate Related Contact Email field onto one text field on Account

I am trying to take the "Email" field on Contact records and concatenate it onto the "Related Contact Emails" field (long text field) on the related Account. I would like to have the email addresses ...
2
votes
1answer
28 views

MailingCountry contact field in before insert trigger

I have to populate a Contact field programmatically according to the MailingCountry field in the before insert trigger so the contact is created properly. But I noticed that the field MailingCountry ...
-2
votes
2answers
44 views

getting null pointer exception [closed]

here i want to insert some names which is having semicolon(;) in between two names iam trying to splitting code but am getting null List<Contactsample__c> cammemlist=new List<...
0
votes
1answer
48 views

Trigger to calculate number of times a pick list field has been used

On field lead source of opportunity object, if currently there are 4 records for the value 'Web', and the user tries to create or update an existing record the trigger should throw an error stating ...
-1
votes
2answers
34 views

autopopulate Opportunities in Account's custom number fields

need assistance regarding how to automatically populate the values of Opportunities from Opportunity object to custom number field in Account object? I have number_of_Opportunities, ...
0
votes
2answers
29 views

OpportunitySplit : send email to opportunity team upon any change

I'm stumped by this, because there may be multiple triggers fired. Really what I want is a trigger on the opp when any related opportunitysplit is inserted, updated, or deleted (that's how ...
0
votes
1answer
19 views

Heda - Affiliated Accounts

We installed the Heda in our org. Every time we create a Program Enrollment - an affiliate account is related. Since I don't have access to the managed trigger - If I want to change some fields ...
-1
votes
0answers
16 views

trigger to insert,update and delete contact's Last Name in Account record's custom field…Pls help [duplicate]

trigger populateContactLastName on contact(after insert, after update, after delete, after Undelete) { Map<Id, account> maps = New Map<Id, account>(); for (contact c : trigger....
0
votes
1answer
28 views

How to write a Roll-up trigger for Master - Detail Relation ship to summarize the fields on all detail records

We need an additional Set of Rollup fields which exceed Salesforce limit of 40 Rollup Fields on master detail records The trigger should take consideration into all the below scenario's. Should ...
4
votes
1answer
33 views

Trigger on ContentDocument showing identical values for Trigger.old and Trigger.new

I have a simple trigger designed to prevent updating the metadata for an existing ContentDocument but it's not working. Example code: trigger ContentDocument_PreventUpdate on ContentDocument (before ...
0
votes
1answer
40 views

Help with some code, Apex class not running when I think it should

Hey guys I have an issue I'm hoping you can help with. I'm a little new to Apex but figuring it out (I think). I have a really awesome unmanaged package that assigns leads/cases and it works great on ...
-3
votes
1answer
77 views

Anyone can optimized this code for better explanation and easy to understand? [closed]

The function of this apex code is when Account has no Contacts the first contact created become the primary contact and when there is existing primary contact it cannot assign a other primary contact ...
0
votes
0answers
18 views

Allow customer user to create case on behalf of other contacts

I've a requirement to allow customer users to create cases on behalf of other contacts from different accounts. Account are shared via apex sharing/manually. User is able to select contact in lookup ...
0
votes
1answer
25 views

Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Raj_provider_detail_page: execution of AfterInsert caused by: System.DmlException: Update failed. First ...
0
votes
0answers
35 views

How to create the first contact created on account to become primary contact? [duplicate]

My problem is this: If an Account has no Contacts, then the first created contact by default becomes the primary and that value should be set in reference. If the primary contact is deleted, the next ...
0
votes
2answers
26 views

Dynamic Generic Sobject multiple instances

I have a list of sobject and I am trying to add Account,Contact and Oppty records on runtime it's working fine.But how can I achieve it dynamically using sobjects type and describe methods i.e more ...
0
votes
1answer
18 views

Update Case status if all Orders related to Case have status “Approved”

Need some assistance in modifying my Trigger. My trigger works for every status changed in Orders. But since there are lots of Orders in every Case, I want the trigger to update the Case Status only ...
1
vote
2answers
33 views

Error on creating new account

I encounter an error when I creating new Account. contactFromAccounts: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Class....
0
votes
1answer
25 views

Help bulkifying a simple trigger

I'm trying to create a trigger that sets a case status to "closed" if there are more than 2 cases created that day associated with the same contact. This is so far what I have written, but I'm ...
0
votes
1answer
17 views

How to convert DateTime to Date, hh-mm

I wrote soql and retrieved DateTime. ie) '2018-11-21T10:51:12.421Z' I would like to split Date, hours:mins like '21-11-2018 10:51'. i tried like below, String value = '2018-11-21T10:51:12.421Z'; ...
0
votes
1answer
22 views

Updating Task field Type for all the Event

I have a scenario. A simple one but not able to understand the language of it. We need to update the Activity(Task\Event) field Type value with Meeting for all the Event. What could be the code ...