New answers tagged

2

Putting Security.stripInaccessible in the mix addresses most (all?) object and field level filtering, though the class should also be with sharing to make sure row level sharing rules apply: @AuraEnabled(cacheable=true) public static List<Opportunity> getRecords() { List<Opportunity> opps = [SELECT ... FROM Opportunity WHERE ...]; ...


0

To create a mapping of Monitoring Id to tasks, you can do the following: List<Monitoring__c> objCase = [Select Id from Monitoring__c where ApplicationLicenseId__c = :appID]; Map<Id, list<Task>> monitoringIdToTaskList = new Map<Id, list<Task>>(); for(Monitoring__c a : ObjCase){ monitoringIdToTaskList.put(a.id, ...


3

If the lock from the first user gets released within 5 seconds, will the second user get access to the same record even though now the status of the record is 'unavailable'? I had to answer the same thing for some of my own architecture, and I can definitively say that if your other operation changes the Status__c to no longer equal 'Available', then your ...


0

As a simple exercise, you can: Decimal ratioA = 3.0, ratioB = 1.0; for(Integer value: values) { (setA.size()/ratioA>setB.size()/ratioB?setB:setA).add(value); } Or, the more verbose way to write this: Decimal ratioA = 3.0, ratioB = 1.0; for(Integer value: values) { if(setA.size()/ratioA>setB.size()/ratioB) { setB.add(value); } else { ...


0

Can you have it all be part of 1 page, broken into 3 sections/s? where each of the 3 sections appear/hide based on user's clicking the Next/Previous buttons?


0

Above given solution works as expected but I don't find it very efficient in the terms of performance: Each serialize/deserialize takes a lot of execution time. Here we are doing it 3 times. After deserialization, we need to run for loop. That would take O(n) in worst case. I would prefer get advantage of get;set properties like below however I need to add ...


2

In JavaScript, you can use the method String.prototype.includes, or String.prototype.match (or several others). String.contains is an Apex method (and Java, and other languages), but JavaScript does not have such a method. Alternatively, you can use a RegExp. includes if(result.getState() === 'SUCCESS' && resultApex.includes('Successfully')) { ...


0

In my scenario, I was calling refreshApex which was calling an Apex method getRecords which returned a List<Opportunity> But I was going from a record list size of 1 to 0 and my Apex method: @AuraEnabled(cacheable=true) public static List<Opportunity> getRecords() { List<Opportunity> records = [SELECT ... FROM Opportunity WHERE ...]; ...


2

You can provide a method that returns fields in a Map and a method that checks the map for null fields: class Wrapper{ String name {get;set;} Integer age {get;set;} EduWrap edu {get;set;} public Map<String, Object> toMap() { return (Map<String, Object>) JSON.deserializeUntyped(JSON.serialize(this)); } public ...


0

I came to know, salesforce released the new feature in-app guidance which I am exactly looking for. Below is the link. https://help.salesforce.com/articleView?id=customhelp_lexguid.htm&type=5


0

Array indices are Integer values, not Decimal values. You have to explicitly convert a Decimal to an Integer because it causes data loss, something you wouldn't want to accidentally do. Decimal a = 3.14; Integer b = a; // If this worked, would equal 3, not 3.14! Aside from that, do not use the List.get method. It is slower (CPU-wise), more tedious to type, ...


2

Well, I solved it and it turned out to be profile related, but the solution is mystifying to me, very unsatisfactory. In the sandbox in which I develop, the only profile that has access to the class XYZ is sysadmin. Other users can use the Apex class, because it is not accessed directly, but via the JS code in my LWC. But on the QA sandbox, I had to add ...


4

You're using the wrong index variable. opp.Highest_Priced_Competitor__c = competitors.get(highestPricePosition); opp.Highest_Price__c = competitorPrices.get(highestPrice); The second line should also be using highestPricePosition, which is an Integer- or simply assigning highestPrice directly, since you do gather that value in your loop. Arrays ...


1

The Scheduled Action is itself a DML transaction. The "zero" used DML shown is because the top level DML in a transaction is "free" (it never counts towards the limits). Try inserting a record against an object withno triggers or actions, you'll see the same type of log.You need to instead use a future or Queueable class to execute asynchronously.


0

You need to deploy the file (right-click > SFDX: Deploy Source to Org) before running the script. Alternatively, you can use an auto-deploy setting/extension, such as Mohith Shrivastava's extension. The readme describes how to install this (requires two steps).


3

You can't use Apex binds in the SELECT clause. They're supported in: The search string in FIND clauses. The filter literals in WHERE clauses. The value of the IN or NOT IN operator in WHERE clauses, allowing filtering on a dynamic set of values. Note that this is of particular use with a list of IDs or Strings, though it works with lists of any ...


0

If you want to test rollback in your code sample, your testmethod needs to inject testdata such that either: performLogic() throws an exception insertRecords() " " updateRecords() " " Since such an exception will occur before the callout attempt, the catch block will be executed. Now how you inject such an exception is dependent on your application. For ...


1

You missed a period to access the function. }).fire();


1

You need to include the namespace: const columns=[{label: 'Id', fieldName: 'Id'},{label: 'Field API Name',fieldName: 'bhdata__Field_API_Name__c'},{label:'Object API Name',fieldName:'bhdata__Object_API_Name__c'}];


0

You can use a parameter: public class FUSContactController { public static void FreshmanTeamAssignment(List<Contact> Contacts, String teamName) { for(Contact c : Contacts) { c.Team_Assignment__c = teamName; } update FreshmanTeamAssignment; } } Note all the optimizations; you don't need to create new ...


1

Yes, if Allow Merge Fields in HTTP Body is enabled, you can use the supported merge fields: <CustomInterface> <Header> <Environment>Sandbox</Environment> <Login> <User>{!$Credential.Username}</User> <Password>{!$Credential.Password}</Password> </Login> </Header> .... </...


0

Kris, thank you for the direction. After much thought and time, I have found a few things : Group DeveloperName is NOT unique - this was a bit of a surprise for me. You must query for all Groups and their members anyway to construct this for Queues, so I extended the functionality to include all active users for any group in the system. Group has an ...


1

Firstly make sure the JSON to be used is correctly formatted. @krigi's approach is good, but you can go one better and change this to: Map<String, Object> dataToSerialize = new Map<String, Object> { 'errorType' => 'javax.ejb.EJBTransactionRolledbackException', 'aBoolean' => true, 'aNumber' => 10, 'anObject' => new Map&...


3

In your class updateCheck method is static. you can't invoke static method from an instance of the class in Apex. It should be invoked from a class: instead of updateCaseRecord uC = new updateCaseRecord(); uC.updateCheck(std); should be updateCaseRecord.updateCheck(newCase.Id); you don't need any standard controller, as for VF controller. I recommend ...


0

if you are placing it on account page and you need account record id you can declare an attribute recordId and use "force:hasRecordId" interface it will automatically pick like this at the top <aura:component implements="force:lightningQuickAction,flexipage:availableForRecordHome,force:hasRecordId" controller="SK_AccountTreeGridCmpController"> and ...


0

I've found the way to fix it. You should add another setResumeCheckpoint in the end of your method after try catch for example with replayId of the last element. Then if you will have unhandled exception like LIMIT exception it will restart your events starting from saved + 1, otherwise it will stop restarting your events firing.


0

I am able to see the output. Here is the updated console.log code. for (let i = 0; i < result.length; i++) { console.log('Case Subject '+ result[i].Subject); console.log('Case Origin '+ result[i].Origin); }


0

The point of tests is to confirm that the code does what the requirements specified so start with that mindset when writing tests. Code coverage is just a crude indicator. The data already in your org is (except for some special cases) not visible to your test. So your test will need to insert data that causes your queryString query to return rows so that ...


0

To make this code more testable, you need to extract the loop body to a separate code unit. In your case there are 2 options: RecData constructor Just a separate method Then just write tests for that extracted unit. That would do the thing.


0

There is a product called Report Scheduler in appexchange which would let you schedule the reports to the external recipients. You could also pick the file type between excel and pdf while scheduling the report. Following is the product link in appexchange https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000FMkcdUAD I am part of the ...


3

you can do it by means of the while loop and checking the current size of the partition. Here is a class, that allows a splitting list of any list type. public with sharing class Lists { public static List<List<Object>> doPartions(List<Object> records, Integer size, Type destType){ checkNotNull(records); checkArgument(...


0

Make sure that on your duplicate alert rule onCreate and onEdit actions have "Allow" selected and not Block as shown in below screenshot


1

The problem is most likely here (we use sfab_xxx throughout our org): fabricatedrr1.setChildren('Routing_Rule_Parameters', new List<sfab_FabricatedSObject> {fabricatedrrp1}); You need to use the API name of the relationship, which is most likely fabricatedrr1.setChildren('Routing_Rule_Parameters__r', new List<sfab_FabricatedSObject> {...


-1

If your method declaration has a return type expressed in array notation (i.e TypeName[] as opposed to List<TypeName>) you will receive this error.


0

I think the best way to solve this is by using platform events instead of the custom objects in your design. With platform events note that you will still not be able to publish the event before making callout because of an issue mentioned here (I hope in future this issue is rectified because it does not look like a technology limitation at this point), ...


1

Salesforce says: Debug logs in apex code should not contain any sensitive data (usernames, passwords, names, contact information, opportunity information, PII, etc). The debug logs include standard salesforce logs using system.debug() methods or custom debug logs created by the application. Sensitive information should also be not be sent to 3rd party by ...


0

App Analytics is the newer API which was introduced in 2019. The data it provides is mainly event-based and thus different from Usage Metrics, which more or less contained snapshots. I outlined the process of requesting App Analytics data in How do you use AppAnalyticsQueryRequest? Alternatively to the Salesforce APIs, you can leverage a third-party tool ...


2

You shouldn't be manually creating (and escaping) a JSON Object String in your test method. Best to let the platform handle the serialization for you. Try: String json = JSON.serialize(new Map<String,String>{'errorType'=>'javax.ejb.EJBTransactionRolledbackException','message'=>'ORA-00001: unique constraint (ACCOUNT_SHORT_NAME_UNIQUE) ...


0

I suspect the insert DML is failing in the test method (possibly due to some missing required field). Due to insert failure, the SOQL query in your code might not fetch any record and the update DML never occurs. Did you check the test logs? Since you are testing the before insert operation, the test coverage will happen for the insert related method (even ...


4

This is because where groups__c IN :groupIds will only return against hard matches of each single value, instead of checking against a LIKE operator. Simply change your groupIds.add(gm.GroupId); line to groupIds.add('%' + gm.GroupId + '%');, and your IN clause to a LIKE, and it should function as you expect. List<String> groupIds = new List<String&...


2

First, I would recommend that If you are passing an Id to a method, you use the Id type, not the String type. :) Second, never pass a hardcoded Id to a method... that's just asking for trouble. Third, you may want to either try-catch the select query or to cast into a List in case the Id does not exist. It is significantly safer. Having said that, here is ...


3

You're most of the way there, and I think you have all of the code you need, but there's a couple of key misconceptions here that are holding you back. Let's start here: Test.startTest(); String moodleIdNull = MoodleApiLoaderController.getCoursePortalId(null); //also test '' String moodleIdExists = MoodleApiLoaderController.getCoursePortalId('...


0

For anyone who bumps into this issue. It seems that you cannot use :UserInfo.getUserId() directly into soql. First create a variable and assign :UserInfo.getUserId() to the variable then use :variable in soql.


0

The return value is a list, so you need to use that same type: List<SmartlyStreetApex> result= SmartlyStreetApex.parse(response.getBody()); Or, as I prefer, the shorter syntax: SmartlyStreetApex[] result= SmartlyStreetApex.parse(response.getBody());


0

Basically we are writing System.Assert to check the expected behaviour of the code. Test class covers because of the date we are creating as per the code but it's not guarantee you the expected outcome. For that reason we must need to include the System.Assert statement for each method at least one. Thanks !


1

Your filter condition needs to use quotes around literal strings. /services/data/v39.0/query/?q=SELECT+Id,Name,AccountNumber,Type+FROM+Account+where+rating!='warm'+limit+10


0

It is bulkified in the sense that it does not waste DML statements or SOQL queries against limits. It is however, still at limits risk. Specifically, it will fail if your query returns more than 10,000 records, and possibly quite a bit earlier depending upon what kind of CPU time consumption any automation you have on Lead incurs. I don't think this query ...


1

Let's break this down a little here: 1: first you should be checking if you even supplied a non-null object for entitlementRec Map<String,Object> mapObj = (Map<String,Object>)Json.deserializeUntyped(Json.serialize(entitlementRec)); 2: then you should be checking if you even have a mapObj and if you even have the keys for fields before you ...


0

I solved for this by specifying the exact criteria under which I wanted to make the callout, then using the separate API transaction to trigger the updates I wanted to make after the rules were run. Fortunately the API callout acts as an update the account object even though it is only changing the territory records. public static void ...


1

In case you are not sure about relationship API name then describe the object from Workbench and check the relationship API name. May be it is DB_Line_Items__r


Top 50 recent answers are included