New answers tagged

1

To take advantage of the DML-less record updating action in before insert and before update trigger contexts, you need to make the changes to an instance of the triggered object contained in trigger.new or trigger.newMap. In this case, that means that you need to update your field on a record in your lstIns variable. You're currently updating the field on a ...


3

you can set field values and they will be commited in before update only for records, which are from Trigger.new context variable. In your code, you are not referencing Trigger.new, but brand new queried records. Your code should be: public static void updateRec(List<Insurances__c> lstIns){ for(Insurances__c cp : [Select id,Reported_Complaint__r....


0

There are several problems with the code: You are queueing one batch per record inserted which I don't think is what you want to achieve (also a bad practice). I assume that you want to enqueue a single batch that will process all the records that have been inserted Your start() method of the Batch Class has no filtering. It is always querying for all the ...


0

First of all, if it's a minor 1:1 creation, you probably don't need Batchable. That's for mass updates. Secondly, you've written your query without a filter, so naturally, it will create one child record for every parent in the database each time you create one parent. Further, you're creating one batch per record in the trigger context, so you could end up ...


1

One way to achieve this just by using Salesforce administration would be the following one: Create a new text field and set it as unique Create a Flow and update the field that you just created with something like (OwnerId + Multipicklist Value) By doing this, you ensure that you can't have in the System two records with the same Owner Id and same values ...


1

I'd rather let the trigger framework loop my records and have it call something like for (SObject so : Trigger.old) { handler.beforeUpdate(so, Trigger.newMap.get(so.Id)); } Then in beforeUpdate you only alter the value on the single opp. Nonetheless you should be able to look them up in Trigger.new at this point. If the opp is in trigger context you don'...


1

Please drop a Salesforce link into your body details as follows, //set email content mail.setSubject('Fill your KYC Details for Verification'); String body = 'Dear ' + cus.Name + ', '; body += '<br> Please complete your KYC Verification process by filling the details to open your Bank Account.'; body += '<br> https:...


0

You use the standard Aggregate Query Update Pattern for this. You'll also want a trigger handler to avoid unnecessary recursion. trigger updateNotes on Demo__c (before insert, after insert, before update, after update) { DemoTriggerHandler.execute(Trigger.new); } ---- public class DemoTriggerHandler { static Boolean isRecursive = false; public ...


0

In order to discard the duplicate values for external field, we need select the "Unique" option which will not allow duplicate values to be stored in system by Treat "ABC" and "abc" as duplicate values (case insensitive).


1

I think you can combine fetching the CurrencyIsoCode with a different way of converting the field value to a String. E.g. fh.NewValue__c = o.get('CurrencyIsoCode') + ' ' + String.valueOf(o.get('sfims__Amount__c')) However, displaying the Decimal as a formatted String has some complex aspects to it which have been discussed in detail on sf stackexchange in ...


2

Trailhead is meant to be simple. A trigger framework would be an unnecessary burden when you're just trying to learn how triggers work. Almost all experienced developers use some kind of framework, either an Open Source version or a homebrew version (I've personally written a half dozen homebrew myself for various projects). A framework allows you to skip ...


0

You're incrementing i once at the end of the for loop, but you are also conditionally incrementing it inside the if statement. If the status or campaign changes, except for the first row, or on any insert of two or more records, you'll end up incrementing past the end of the list, and you'll get the ListException. You can, and should, optimize your code, it ...


0

First, your trigger must definitely be after insert, or you will be unable to "see" the new incoming records, and you'll likely run in to an infinite loop. Second, you cannot query may be effectively the entire database on line 15. You need to be more selective than that. It looks like you're trying to create the inverse relationship when a record ...


0

From your code it doesn't seem like any duplication is occurring. The issue is probably on a custom Validation Rule on the Account object which is somehow preventing an Account from being updated correctly. I'd suggest you check first the conditions for the duplicate account not allowed rule to fire and assure that the Account related to the Contact you're ...


0

Since you are expecting to work on 'after insert' and ' after update', you need to write DML statement as upsert. Below is my code and it worked: trigger ClosedOpportunityTrigger on Opportunity (after insert,after update) { list<Task> newTask= new list<Task>(); for(Opportunity oppWon :[Select Id from Opportunity where StageName='Closed Won' ...


1

I think that, although more roundabout than I would write, your existing code gets it more or less correct until you hit the final 3 if blocks like this one if(dripCount==mapMultiEuipType.size()) If my reading is correct, then mapMultiEquipType.size() is going to be the size of your starting map. That information is not going to be of any use to you here (...


1

At a basic level, you simply create a record, then change the value in memory, and update: Account record = new Account(BillingPostalCode='12345',...); insert record; record.BillingPostalCode = '54321'; Test.startTest(); update record; Test.stopTest(); // remember to check to make sure your logic ran.


0

As identigral mentioned, each will be a separate request. The Composite REST API Executes a series of REST API requests in a single call. You can use the output of one request as the input to a subsequent request. The response bodies and HTTP statuses of the requests are returned in a single response body. The entire series of requests counts as a single ...


2

Nested loops are not always evil. In cases like this where you're working with nested data, they're effectively unavoidable. Specifically for working with parent-child subqueries, accessing child records via a nested loop is the safest way to do so. As long as you keep the inner loop short, and keep dml and queries outside of all loops, there's really no ...


3

First thing you should do is add a filter to check if your BillingPostalCode has actually changed. Don't consume governors if you have nothing to process. This pattern is very common. public static List<Account> hasBillingPostalCodeChanged (List<Account> records, Map<Id, Account> oldMap) { List<Account> output = new List<...


2

By adding this code, you are introducing permission checks yourself. So yes, depending on the permissions set for the user that the code is running under, you will be executing whatever logical branches you add. Such guards in triggers added to standard objects are a very good idea. You can't assume that every user in the org has the access rights that your ...


Top 50 recent answers are included