New answers tagged

0

In your Apex, your getter method takes a parameter: public List<Integer> getScoreList(List<JobOffer__c> offerList){ Visualforce does not have a parameter to pass to this method. Visualforce getters are required to take no arguments. You will need to either expose the instance variable directly, as J.Dillinger suggested in another answer, by ...


0

Your trigger will never execute because your unit test never inserts a DATEV1__AccountingDocument__c. The three fundamental components of a unit test are Perform data setup. Execute code path under test. Validate results. This unit test currently does only (1). You must cause your code to execute, and you must write assertions to validate the results. ...


0

I guess you have to specify {get; set;}property for the scoreList


3

There is no way to load more than a total of 50K records in a given synchronous session/transaction (as per the documentation), and certainly no way to do this in a trigger. The only way to deal with this sort of thing is to use async processing such as in a Batchable as you mentioned. It is possible to execute certain types of aggregate query across more ...


0

You don't need to have two queries on Task object, rather you can get them in a single query on account object. Account[] accounts = [SELECT id, (SELECT WhatId FROM Tasks where Subject = 'Sending' and Status != 'Completed') FROM Account WHERE Id IN :accounts]; Task[] taskList = new List<Task>(); for (Account acc : accounts){ for(Task taskObj: acc....


1

I suggest this sort of code if there is only ever one Task at most per Account: Map<Id, Task> whatIdToTasks = Map<Id, Task>(); for (Task t : [...]) { whatIdToTasks.put(t.whatId, t); } for (Account acc : [...]) { // Update existing Task or create new one Task gTask = whatIdToTasks.get(acc.Id); if (gTask == null) gTask = new Task(...


-1

If I understand your question correctly, you have to add record_type__c as below in your logic to execute the Order Invoice when Order's Record_Type__c = Billing Only Order. Hope this helps. if((ORD.Shipping_Tracking_Number__c !=null && Trigger.OldMap.get(ORD.Id).Shipping_Tracking_Number__c != ORD.Shipping_Tracking_Number__c)||ORD.Record__Type__c ...


0

You Can Also use the before insert context of the Trigger that will save the update statement in the end thus reducing a dml count. Sharing the below code: Map<Contact,Account> conMap=new Map<Contact,Account>(); for(Contact con:trigger.new){ if(con.AccountId == null){ conMap.put(con,new Account(name='Test'+con.lastname)); } } ...


-1

I think it depends on your requirements. Packaging should use for new implementation or separate requirements. But as I'm seeing, you got the same kind of requirement, So I would recommend you to use an existing trigger with a handler otherwise it will hard manage later on. or You need to migrate whole existing trigger logic into package org let me know if ...


2

You can create a record of parent and child object records in one go by using Reference and External Id. Create a String field(External) on case object for example: Query Case Object record with Workstream Child object records Loop on query Create a new instance reference on case object and assign caseId+'abc' A loop on child object records(Workstream) ...


1

I hope you do know how triggers work and what are they used for. The way I would do it is like this: In your after update trigger, I would loop through all the items Find the ones that were closed and store them in a list Then, query all their children Create a map(m1) with Case as a parent and a list of workstreams as children Loop over m1 to create new ...


0

Solved. This error was being caused by the approval process setting a value on Rejection that was invalid for this scenario. This value activated a Process which in turn activated a validation rule. The weird thing is that the error message "INVALID_CROSS_REFERENCE_KEY" provided zero help in discovering this issue, and led me on a search in a totally wrong ...


1

You cannot access second level fields through the trigger.new list. You need to query all 2nd level fields you need —e.g. cm.Lead.Primary_Campaign__c— and iterate through that query results instead. There's also a problem with how you are adding the leads to be modified to your lists, you need to add the entire records you modified and not just the ids. ...


0

Your DML operation needs to be in the execute method: public class InsertnewRecords implements Queueable { // Store all the records to process ProcessEmails__c[] recordsList; public InsertnewRecords(List<processemails__c> emaillist){ recordsList = emailList; } public void execute(QueueableContext context) { ...


0

You need to use the WhatId in order to get the related cases. See my comments inline: Trigger CaseClosed on Task(Before Insert) { Set<Id> caseIds = new Set<Id>(); Set<Id> closeCaseIds = new Set<Id>(); //get all the case ids that are related to the new tasks for (Task t : Trigger.new) { if(t.WhatId != ...


3

You need to filter by the WhatId for the records. The ID you got was some random case in the database that was closed. Here's what you're looking for: trigger preventTaskOnClosedCase on Task (before insert) { Set<Id> caseIds = new Set<id>(); for(Task record: Trigger.new) { if(record.WhatId != null && record.WhatId....


0

Salesforce will strip trailing new lines from text fields, That would be easy to fix by starting the message on a new line instead of ending it with a new line. Simply replace: c.Quick_Notes__c = log + '[' + DateTime.now() +']: ' + note + '\n'; With: c.Quick_Notes__c = log + '\n[' + DateTime.now() +']: ' + note;


0

boxToolkit.commitChanges() could be an asynchronous callout, so any returned errors are likely several seconds later and included in a different log.


1

This is indeed not possible, as you can't invoke real time events based on changes to subscriber status. Also, you have very limited possibilities of customising the standard Subscription Center to provide the ability to perform any API related activities. Hence, the best solution would be either to build the preference center within the system holding this ...


2

Even if a field is indexed a filter might still not be selective when: The filter value includes null (for instance binding with a list that contains null) From your debug logs, you're running this query: SELECT Id, OwnerId, LastName, AccountId, Email FROM Contact WHERE (Email = :tmpVar1 OR Personal_Email__c = :tmpVar2) LIMIT 1 Since these ...


0

From Salesforce's documentation found here: You may find that the query in question needs to be more selective in the WHERE clause. According to the Salesforce standards & best practices - the where clause needs to subset 10% or less of the data. Consider putting more filters on your WHERE clause(s) to reduce the number of records you're ...


0

There are couple of issues with your code: Trigger.oldmap is not available at the time of insert. SOQL query should fetch the latest India_Auto_Number__c from the database to decide what number should be assigned to new lead. Based on above points, below are the changes I did in your code: trigger LeadIncrementV2 on Lead (before insert, Before Update) { ...


0

From your last updated comment it seems that you have run the test method but your hackClipDisburse() which is called is not having isTest qualifier I only see one on class.


4

To deploy a trigger to production , you will need to ensure your trigger has a test class and the class needs to cover at least 75% of the lines of code . Looks like you are writing the trigger for first time . I suggest you go through Salesforce trailhead content and learn some of the best practices such as below bulkify your trigger do not write soql ...


4

There are lots of cases where a user shouldn't be allowed to update a field value, but that value may still be legal. For example, perhaps a Status field allows me to set the value to Pending or Canceled, but not Approved. In order to Approve a record, an Approval Process must be followed. In that manner, the manager can approve the record, but the user can'...


2

In answer to your direct question: why would you set up a field update to put in bad data on the object? Ideally, a field update that's automated would be using "correct" data Otherwise, I think the general question (using which automation tool) is a complicated one that has a degree of opinion and differences on a case-by-case basis. However, in ...


2

I think your problem is that in your Contact Trigger, the Trigger.New list only contains Contact field info. You cannot access parent object fields directly, you need to query them first. i.e, in your code, con.Account.Owner.Name will return null. You need to query the Account.Owner.Name so that it returns the actual value stored there. To Access the ...


4

The entire update will fail. From Apex Developer Guide - Apex Transactions: All DML operations in a transaction either complete successfully, or if an error occurs in one operation, the entire transaction is rolled back and no data is committed to the database. The boundary of a transaction can be a trigger, a class method, an anonymous block of code, a ...


2

In the case of an exception in a trigger, all records involved in that trigger will not be updated, regardless of if allOrNone is set, because Salesforce cannot determine which records were successful. Triggers are synchronous in nature. The "before update" and "after update" simply refers to the half-way point initial commit phase. This initial commit is ...


-2

Generally there are two ways to insert/update/delete/upsert records in Apex, the first is DML Statements and the other is the Database Class. "Use DML statements if you want any error that occurs during bulk DML processing to be thrown as an Apex exception that immediately interrupts control flow ..." "Use Database class methods if you want to ...


2

This won't work in a before insert trigger, because the Account does not yet have an Id. You will need to use an after insert trigger to detect those records, then perform a recursive update to set the new values. trigger populateParentAccount on account(after insert) { Account[] updates = new Account[0]; Set<Id> accountIds = new Set<Id>(); ...


2

Login events do not trigger User triggers, because it is not a real "edit" to the record. You can use a Login Flow to do all kinds of things, such as enforcing 2FA or, in your case, performing an update on a related record when a user logs in. Please read the documentation for more information.


2

The issue is simple: the User record is not updated when the user logs into the platform. Because of this your trigger will not run. I issued the following query in my orgs' developer console: SELECT Id, LastLoginDate, LastModifiedDate FROM User WHERE Id = '0054T000000sHrOQAU' And the result is: Id LastLoginDate ...


0

In case, if someone facing an issue now(v47.0) We do have an alternate solution. Please have those addError method in try-catch-finally block. Finally has higher preferences so it would execute anyway. Now you can publish a Platform event. Now write a platform event trigger which will have the code to send the email. Following is the dummy code working: ...


0

In case, if someone facing an issue now(v47.0) We do have an alternate solution. Please have those addError method in try-catch-finally block. Finally has higher preferences so it would execute anyway. Now you can publish a Platform event. Now write a platform event trigger which will have the code to send the email. Following is the dummy code working: ...


3

You can't display superscript in Apex code itself. If you want to display it elsewhere then you can use the sup HTML tag. This should display your # in superscript in rich text fields, HTML emails, and websites. Since normal text fields in Salesforce don't support HTML tags, you won't be able to use it there. Adding the tags is relatively easy: String str =...


3

See e.g. Disable Validation Rule with Apex Code. Add a custom field to the object that your trigger sets and unsets, and then incorporate a check of that custom field in the validation rules.


-1

Code looks fine to me. I guess you are doing Unit Testing incorrectly. The trigger point here is after an insert / update happens on any User Record. Then it would check for User.Name == Account.Name and then updates the Account Record. Are there any failures?


2

As Kris is saying, you should be looking to the processes, workflows and any other declarative operation that may be firing on the same transaction. You can also try a couple of things to see if you can control a bit the transactions that are operating on this classes. I will suggest to make a clear cut between before update and before insert operation. ...


8

When you perform DML on a record, the "in memory" instance (i.e. your c variable) of your object is not automatically updated1. If you re-query the record, and debug the email value, you would see "tstcontactjan11test123@test.com.com" as you expect. If you don't re-query the record, the in-memory field values remain untouched. As a side note, explicitly ...


0

Managed to accomplish this by doing the following: trigger opportunityLineItemTrigger on OpportunityLineItem (Before Insert, before update) { if(Trigger.isExecuting && Trigger.isInsert && Trigger.isBefore){ for (OpportunityLineItem oppItems: Trigger.New){ ProductLineItemClass.updateLineItemDiscount(Trigger.new); }...


2

I have faced with similar issue in my omnichannel implementations and found triggers on this object can be created but they do not fire, or at least shows up in apex debug logs.


0

You would want to create an HttpCalloutMock implementation for your test class. From the documentation: Example: @isTest global class MockHttpResponseGenerator implements HttpCalloutMock { // Implement this interface method global HTTPResponse respond(HTTPRequest req) { // Optionally, only send a mock response for a specific endpoint ...


3

There's quite a few issues to look at here. Syntax Error The syntax error is because you're missing a () to create an instance of sbox_ContactUtil with new: contactsPendingOwnershipChange = new sbox_ContactUtil.getContactsPendingOwnershipChange(Trigger.new, Trigger.oldMap); However, that would be invalid for a different reason: that method is static, so ...


0

Just comming back on this question with the actual workaround. You will have to use process builder to subscribe to the event and call an invocable method in order to perform logic on BatchErrorEvent insertion. This can be packaged.


1

A few things: 1. System.QueryException: List has no rows for assignment to SObject This is generally caused by assigning an SObject to a SOQL dynamic query, like you are doing in: Task t = [SELECT Id, Subject, CreatedDate, WhoId FROM Task WHERE Id IN: Trigger.newMap.keySet()].get(0); I suggest assigning the SOQL to List<Task> and doing a ....


1

Regardless of the cause of that specific failure (which does not appear to be within the code shown here), this trigger and its unit test most certainly need to be rewritten anyway. Since none of this code uses Batch Apex, presumably some other code or automation in your org is doing so. It is likely, but not certain, that the presence of seeAllData=true is ...


4

You could do this using a Process Builder (the downside is this uses more CPU so you could later hit CPU limit issues if you have a lot of other processing going on when contacts are updated). If you stick with this trigger-based approach note that you are doing far more iteration than needed and there's no need to query the account instances. I recommend ...


0

For your VAccountTriggerHandler class, yes, you'll need to enforce CRUD/FLS checks (as well as sanitation and other protective measures) manually for security review purposes. Consider using WITH SECURITY_ENFORCED in your SOQL for a quick catch-all CRUD/FLS fix, or consider .stripInaccessible(), both of which are going GA soon. See (and do) the Develop ...


4

Since you're new to Salesforce, I'd recommend that you ditch this approach. It's highly inefficient and manual. Instead, you can use BusinessHours and Custom Metadata to provide a configurable setting for your trigger. BusinessHours In Setup, create a new Business Hours setting. You can just specify the start and end times as 12:00AM on each end to make ...


Top 50 recent answers are included