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
479 views

How to write a trigger on campaign members to update a custom field in lead object as lead score

trigger newLeadscore on CampaignMember (after insert,after delete,after update) { Map<Id,CampaignMember> campaignLeads = new Map<Id,CampaignMember>{}; List<CampaignMember> ...
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
500 views

Trigger to create an attachment

I have a requirement where an attachment has to be auto created whenever a record on Object A is Created. The attachment is a child to Object A. And the attachment type is ".docx".I dont have a ...
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 ...
2
votes
1answer
43 views

How can I change the status of Trigger MetaData using Apex Programming(Tooling/MetaData API)

I am using this code to update metadata for trigger. public void createMetadataContainer() { HttpRequest req = createHttpRequest(endpoint+'/MetadataContainer','POST'); req.setBody('{"...
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 ...
0
votes
1answer
493 views

Trigger to clone object is throwing error

Apex trigger is throwing following error when tried to clone the record, Although there is no id inserted but still I'm getting complain about id. **Validation Errors While Saving Record(s) There ...
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 ...
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 ...
-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 ...
3
votes
1answer
507 views

ExactTarget - Salesforce Integration: Adding the report or Campaign to the 'Individual Email Results' record in Salesforce

I am asking the following on behalf a client. A features in a system requires the ‘Campaign’ and ‘Report’ field to be completed on the Individual Email Result (and for that matter on the ‘Email ...
-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 ...
-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
vote
4answers
4k views

Trigger before insert - Get the value of the record to be inserted

I have a trigger for inserting a record. the trigger : trigger myTrigger on Object__c(before insert) { if (trigger.isBefore && trigger.isInsert) { myTriggerHandler.isBeforeInsert(...
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: ...
-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
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 ...
5
votes
3answers
5k views

Compile All Classes?

Does anyone know of any documentation on this function, "compile all classes" on the Apex Classes page? I'm finding nothing on help.salesforce.com or elsewhere. (UPDATE regarding desire to automate ...
-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
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
1answer
546 views

Move email attachment(email to case) to Case files in related list

Files replaced Attachments in Salesforce. Now any type of document upload becomes part of Files/Content in Salesforce. With all the other advantages over Attachments, the best one is Files can be ...
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 ...
-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 ...
-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 = ...
-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()&...
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 ...
8
votes
4answers
6k views

Invalid API version 0.0 preventing me from saving trigger

I keep getting this error when trying to save a trigger, "Invalid API version: 0.0" I've googled this error and I haven't been able to find anything about how to resolve this, does anyone have any ...
2
votes
1answer
650 views

Trigger.new and Trigger.Old Map hold same values for a field on Opportunity

I have a trigger on Opportunity which calls a handler and Handler calls an apex class. here is the code: //Trigger trigger MasterOpportunityTrigger on Opportunity ( before insert, after insert, ...
0
votes
2answers
133 views

Trigger to Update Contact Email Address on Asset Custom Field

I'm having trouble with a trigger that needs to update my custom email field on Asset with the email address from Contact that is a lookup field. The code I have is below and I can't figure out why ...
2
votes
2answers
570 views

How to avoid creation of duplicate Opportunity Contact Role for every newly created Opportunity?

I have written a after insert trigger on Opportunity to create a Opportunity Contact Role. Here is the part of code if( trigger.isAfter && trigger.isinsert){ Set<Id> accIds = new Set&...
0
votes
1answer
556 views

How to check format of date in If condition & Convert that format to sfdc system format?

I am importing records from Data loader and there is date format in csv is : 27.08.2016 04:40:19 & Salesforce Does not support this format as it has English(United State) locale.. so, i am ...
1
vote
1answer
540 views

Update field depending on Record Type Selected

I need to update the field to another object (Accounts) with the value of the record type selected in the other object (Lead). Is it possible with workflow or trigger? Im new please help me.
1
vote
1answer
588 views

Disable sending email when close a case and change owner

I would like to know if it's possible to disable sending of an email when the case is closed and when the owner of the case changes? In the "support settings" for case, the checkbox "Notify Case ...
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 (...
1
vote
2answers
651 views

unable to fetch all Keys and Values in map?

i am unable to fetch all Keys and Value simultaneously using forEach loop.. for (Map<String,String> key : parameters) { queryParameters = key.values();//? }
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
549 views

Apex Trigger to create record on custom object from another custom object fields and related fields

I am looking to create a trigger off of a custom object (ObjA - Looks up to Accounts and Opportunities) that will create a record in custom object (ObjB) based on fields from ObjA and some related ...
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 ...
1
vote
2answers
167 views

Handling trigger recursion in bulk data load

Update 405 records on an object (So it executes the trigger 3 times 200+200+3 i.e, each batch holds 200 records) There is a process builder which in turn is updating the same object (Will fire the ...
-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
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 ...