Stack Exchange Network

Stack Exchange network consists of 175 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

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
2answers
52 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
53 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 ...
3
votes
3answers
32 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
118 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
39 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
26 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 ...
0
votes
1answer
27 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 ...
-1
votes
2answers
33 views

Disclaimer Popup on Chatter Group [closed]

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
94 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 ...
0
votes
1answer
63 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 ...
0
votes
2answers
60 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
39 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
44 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
248 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 ...
0
votes
1answer
34 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
64 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()&...
1
vote
2answers
46 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
49 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
71 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
48 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
349 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
19 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
44 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
48 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
56 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
38 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
35 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
25 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 ...
0
votes
1answer
30 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
39 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
50 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
94 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
22 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
126 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
40 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
30 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
22 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
37 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
30 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
25 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
28 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 ...
3
votes
1answer
137 views

Apex class invalid for community user but not standard

UPDATE: this might be a Spring 19 only issue. Will try to confirm this. If I create an opportunity with a standard Salesforce license, no problem. But if I try the same operation as a community ...
6
votes
1answer
52 views

Weird Behaviour of Bulk ContentDocumentLinkTrigger in Test Context

I know that ContentDocumentLink triggers are not bulkified by Salesforce. I was expecting that behavior and was writing test classes accordingly. It looks like, ContentDocumentLinkTrigger doesn't ...
0
votes
0answers
32 views

How to parse JSON String through apex [duplicate]

I want to get 'guid' and 'attachednotes'The attachedNodes is in different format. I think it is string array, but I am getting an error. { "messageHeader": { "triggeredBy": "manual", "...
0
votes
1answer
32 views

How to limit record creation on multiple objects

I am working on the requirement where I have to setup the limit on number of records created on 10 custom objects. So I have created one object called Limit__c which contains available_limit__c and ...
-1
votes
1answer
57 views

Apex Trigger After insert

For any account if we are inserting contact, then for the first contact primary__c check box becomes true, when we insert second contact then secondary__C check becomes true irrespective of primary__c ...
0
votes
0answers
45 views

trigger not working on update on picklist values

I am working on a trigger which will count the child records to parent basing on some picklist value conditions. If picklist field values= "son, Daughter, Husband, Wife, Partner" then I need to count ...
0
votes
1answer
51 views

i want to update the password into ***** after inserting the record.am acheivinng it using before update how can i do it using before insert [closed]

please bare with me am new to triggers. lead and account are the two objects. by using before insert i have to update the fields like lead object: name,password into account : name,password. my ...
0
votes
2answers
63 views

Bulk data loader operations:: System.LimitException: Too many SOQL queries: 101

I am getting an error while performing data loader operations on the Leads object as I get this error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:LeadTrigger: System.LimitException: Too many SOQL ...
0
votes
4answers
55 views

Trigger counting twice on child records

I wrote one trigger which will count the number of child records and update it to parent object field. If I create 2 records then count is giving 4 instead of 2... Please help me to overcome the ...