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

Questions tagged [trigger]

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

-2
votes
0answers
7 views

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

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
22 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
18 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
16 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
23 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
39 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 [on hold]

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
45 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
47 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
29 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
36 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
123 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 [on hold]

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
41 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
49 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
27 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
297 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
47 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 ...
0
votes
2answers
32 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
18 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
32 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
30 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 ...
3
votes
1answer
101 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 ...
-4
votes
0answers
24 views

Apex Test class help! on junction object [duplicate]

trigger name application finding difficult to write the test class help would be appreciated trigger applications on Job_Application__c (after update) { set<id> candiadteIds = new set&...
4
votes
1answer
34 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 ...
-2
votes
0answers
27 views

Test Class for Apex Trigger: Need help to write a test class for the following Trigger: [duplicate]

I am new to Apex and don't have much experience with test classes. Can anybody please suggest as to how to cover this trigger? Which points should I keep in mind or share a sample code which can help ...
0
votes
0answers
30 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
28 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
49 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 ...