A trigger is an apex code, that can be executed before or after DML operations

learn more… | top users | synonyms

0
votes
0answers
5 views

Eliminating duplicate IDs in the Lead object records by throwing an error

I have to write a program where if duplicate id is inserted in the lead, it should be eliminated by throwing error. I have tried my best to write this code. Since I am a fresher , I have messed up ...
-4
votes
0answers
19 views

How to write a test class for trigger?

trigger updateActivity on Contact (after update) { public List<opportunitycontactrole> op; public List<task> opp; for(contact t : trigger.new) { op = [Select ...
4
votes
2answers
117 views

What is the best way to check whether lead belongs to Queue or User?

I'm trying to determine in a trigger, whether a lead belongs to a Queue or a User. What is the best way of going about this? I tried the method mentioned in a dev. force discussion: System.debug( ...
1
vote
1answer
27 views

Update same record in after insert/update in a trigger context

I searched a bit for some informations about the need to make an update on a record in after insert/update trigger context. I found that the common feedback was to move the Business logic in before ...
0
votes
2answers
25 views

MIXED_DML_OPERATION, DML operation on setup object is not permitted

I'm writing a Trigger that After Insert of a new User, I need to create a Contact with that same new User information. I'm getting this error: MIXED_DML_OPERATION, DML operation on setup object is not ...
0
votes
0answers
40 views

How to write a trigger to update activity priority based on the following rules:

First i have to check if a contact has closed opportunity,if it is then set priority__c field on Task(activity) to 4(priority is a custom field having picklist values 1 to 4).else if opportunity is ...
0
votes
1answer
27 views

Opportunity STAGE picklist value need to change

I want to remove the NONE value from the STAGE picklist (Opportunity Standard Fields)
0
votes
3answers
28 views

Converting Lead into Account (Trigger Before Insert, Before Update)

I've created a trigger on Account object to auto populate the Market__c field when user enters Country. The trigger is a before insert, before update. The trigger works as expected when I created a ...
0
votes
0answers
27 views

Update Checkbox by checking already existing field values

I'm creating an approval process in an account where I am checking the values of a related list, and if the value equals a certain value, I want to check a checkbox on the account object. I have it ...
1
vote
1answer
23 views

Help With Code: Picklist field

The Country__c field in my second FOR loop is a picklist field. How can I change my code to work with picklist? Thanks in advance. trigger oppMarketAssignment on Opportunity(before insert, before ...
0
votes
2answers
25 views

Apex Trigger Test Class Issue

I wrote a trigger that works, and wrote a test class, but for some reason in the developer console in the code coverage list my trigger doesn't show up. When I tried to deploy the trigger to ...
0
votes
0answers
21 views

Problems with Milestones, Entitlements and Apex Triggers

I’m working on implementing Milestones and Entitlements into my company’s Salesforce Org for the first time. No one on my team has any experience with this feature, so I’m on my own as far as that ...
-1
votes
0answers
28 views

create a trigger on Contact to update a custom field [on hold]

Update Account Custom field (contactassigned(text field)) with Contact (Assigned on(text field)) ex:if account has two contacts then account contactassigned=assignedon1(contact 1st ...
0
votes
1answer
19 views

How to set the user to whom we need to send approval request.

I have a trigger from where I need to submit a record for approval. With that I also want to set to how it should send for approval. Is this possible to do from trigger.
0
votes
1answer
31 views

Seperation of trigger with helper class

I got the below code written in a trigger and I need to separate it out to a helper class as a method and call that method in the trigger. trigger setCountry on Account(after update){ ...
2
votes
1answer
45 views

What's Wrong With This Apex Code (intent - to delete spam Leads)

I'm still pretty new to programming and especially to SalesForce programming, but I would have expected this suite of trigger, handler class, and test class to: test as expected and show the test ...
0
votes
1answer
35 views

Trigger for Sum Of Fees of Contacts on Account [closed]

I wish to write a trigger for to sum up Fees (Custom Field) on the Contact object. The sum needs to be displayed on the account object as a Total Fee. For Example - I have an Account A1 that has 3 ...
2
votes
1answer
26 views

Validate a decimal number typed with thousand separator

We've defined a custom field in our Tasks that is defined as a Number(8,4), our regional configuration is set to Spanish(Chile) where the thousand separator is period (.) and the decimal separator is ...
2
votes
1answer
34 views

Deploy Apex Trigger using Metadata API deploy() Method

I'm struggling to deploy Apex trigger using Metadata API from my connected app. I have created package.xml and the two trigger files - one with suffix .trigger and another - triggerName-meta.xml. I ...
3
votes
2answers
60 views

Unit Test is Providing 0% Coverage for Apex Trigger

New to Apex here. I cobbled together a trigger that creates a new task whenever a certain type of opportunity is Closed - Lost, but I can't figure out how to get ANY coverage with a unit test. Does ...
-1
votes
0answers
31 views

Trigger is not getting called for closed case [closed]

If the status is "New", the email is received to that case. But after the status is set as "Closed", email is not received. Because the email trigger is not even getting called. What might be the ...
3
votes
1answer
40 views

Is there a simpler way to traverse relationships to update cross object fields?

I have a trigger that works but it seems like there should be a better and simpler way to accomplish the result. I have a custom object that is a child of Quote and has a lookup to Product2. I am ...
0
votes
0answers
45 views

Apex Trigger Has 0% Test Coverage - What Am I Doing Wrong Here?

New to Apex here and having trouble getting ANY test coverage on a simple trigger I cobbled together to create new tasks when opportunities are Closed - Lost. Does anyone see what I am doing wrong ...
0
votes
2answers
25 views

Mass update instance name

We are moving from one instance(na2) to other instance(na27). Is there anyway to mass update all templates, triggers, pages,validation rules in one shot rather than going and searching for each and ...
3
votes
1answer
39 views

How to compare oldMap and newMap in a trigger

I have a multipicklist called relatedActivity on an SObject called premises. Every time there is change in the relatedActivity or an option is deleted from the relatedactivity, i want to execute a ...
0
votes
2answers
38 views

How to check if the current user in Public groups before insert new contact using trigger?

I have been trying to check the current user is exists in public groups or not using trigger on Contact object before insert. I was wondering whether this is right way to check it or not? Exactly what ...
0
votes
0answers
18 views

How to check if the current user in Public groups before insert new contact through trigger? [duplicate]

I am new to Salesforce development. I have been trying to check the current user is exists in public groups or not using trigger on Contact object before insert. I was wondering whether this is right ...
0
votes
1answer
48 views

Trigger(before insert) which generate's key/random string, after inserting the key, how connect to an external URL [on hold]

trigger which generate's random string: trigger setAppKey on dftly_app__c (before insert) { if (Trigger.isBefore){ For (dftly_app__c dac: Trigger.new){ Blob b = ...
2
votes
1answer
21 views

Update Salesforce 1 User Preference in an Apex User Trigger

I'm trying to update the User field "Salesforce1 User" (API Name = UserPreferencesHideS1BrowserUI /Boolean) programmatically in a user Trigger (Before Insert, Before update). I'm trying to disable ...
0
votes
2answers
26 views

Trigger not showing up in code coverage list

I created a trigger and in order to deploy it to production it needs at least 1% code coverage. I wrote the test class for the trigger, but I'm having a weird issue where the trigger is not showing up ...
2
votes
0answers
38 views

Time-based Workflow not triggering

I've been working on testing a time based workflow, that fires off an email 1 and 3 hours after a new contact is created. Of course, this is small scale testing, as I would eventually like to ...
-1
votes
2answers
26 views

Error Too many SOQL queries: 101 for trigger

I am getting this error Too many SOQL queries: 101 for this trigger when I tried to push it into production. Can anybody please tell what is wrong in the script below. I will really appreciate any ...
4
votes
1answer
32 views

How do APEX triggers reconcile allOrNone setting?

I want to use addError() to prevent some records from being inserted in a before-insert trigger, and want to ensure that other records in the same transaction are successfully inserted. This requires ...
0
votes
2answers
29 views

Updating two object in a page, one trigger doesn't fire up

I have a custom page where I update and insert two objects. The main object is the account, after inserting the record in the account. I get the account Id to reference to its associated object. When ...
0
votes
1answer
20 views

Block EmailMessage in before trigger

I am writing a before insert trigger on EmailMessage object to block emails if the fromAddress is in a list of email addresses I have put together. I'm not quite sure on what to set so that the email ...
3
votes
1answer
33 views

How to extract Text from a formula field before triger?

I'm trying to populate a field whith several others. I know nothing about coding so ... After few research I did that: 1 trigger Updatelookup on Event (before insert, before update){ 2 for (event ...
0
votes
0answers
26 views

Trigger Custom field

I'm very new with salesforce and with everything related to Apex triger. I have a little problem and I guess the solution is not complicated but ... So, When I create a new event, it's always liked ...
3
votes
1answer
24 views

Modify o/p date in email messaging

I have trigger where it sends email when record is deleted. It works fine but date format isn't getting right in email. It's showing yr-mm-dd 00:00:00 whereas i just need only date in mm-dd-yr format, ...
0
votes
0answers
15 views

Bug: Compose Gmail not triggering INSERT of Task

Wondering if anyone else has this issue. When on a contact, in their activity section there is a "Compose Gmail" button: At the moment when we use that, upon sending the email it inserts a ...
0
votes
0answers
31 views

test coverage for insert trigger

I have been trying for code coverage for the trigger, not sure what's wrong. please help. here is my trigger: trigger AppendAccountName on Opportunity (before insert) { List<Opportunity> opps ...
0
votes
1answer
46 views

Add Products to a New Opportunity

I have a trigger that is meant to fire when certain conditions are met on an edited Opportunity. The trigger is designed to create a new Opportunity using some values from the previous Opportunity. ...
2
votes
1answer
95 views

Apex Trigger giving “cannot specify Id in an insert call: [Id]” error

I'm pretty new to Apex and writing a simple trigger for when an account submits a form on our website (tracked on the formSubmit__c object) to create an Opportunity and am getting the following error ...
5
votes
2answers
81 views

QueryException: Non-selective query against large object type for custom object with no records

I have a custom object in a managed package that currently has no records in the customers org. Lets call it DFB__ProductUdfMap__c (namespaces etc... have been changed to protect the innocent). The ...
0
votes
0answers
23 views

@future method fired from trigger - order of execution [duplicate]

Quick introduction: I Approve one of many approval levels on my custom object the before update trigger is fired I'm searching for the approver comments but nothing's there yet (operations are not ...
3
votes
1answer
128 views

Are a trigger's actions limited by the user permissions of the user whose actions trigger the trigger?

I have a trigger on Opportunities to automatically assign certain opportunities to certain owners in specific contexts. If the user who edits the opportunity doesn't have permission to change the ...
-1
votes
2answers
42 views

require contact role for opportunities

How to make contact role required for all the opportunity. I need to write testclass, trigger and class for the same. Please help me on the same.
-2
votes
1answer
63 views

issue in process builder in salesforce

I have two relation A and B, A is parent of B.On update record B I want to update one field in A. I am using the process builder but getting the following error, Workflow Action Failed to Trigger ...
0
votes
1answer
26 views

Convert Leads Trigger Strange OwnerId Behavior

I have some code that automatically converts leads when certain conditions are met using the convertLead() method. This process is fairly well-documented in threads such as this: Convert Lead on ...
0
votes
3answers
38 views

Populating Lookup field from picklist on same object

trigger Wholesale_State on Account (after insert, after update) { for (Account a : Trigger.new) { if (a.Wholesale_State__c == null) { a.Wholesale_State__c = ...
4
votes
1answer
240 views

Too many query 101

I was trying to deploy a trigger from sandbox to production but was unable to do so as test run was throwing error Too many SOQL query. I tried all the best practices to avoid error too many soql ...