New answers tagged

0

If you're using wire methods, and cacheable=true, and the cache isn't stale, the data won't be retrieved from the server again. You may not need to do anything. If you want to pass data specifically, you can use NavigationMixin and provide data via the state property.


0

I changed this section of the code String sch = '0 0 23 * * ?'; Crontrigger ct; ccScheduledProductIndexBuilder myClass = new ccScheduledProductIndexBuilder(); String jobId = System.Schedule('Test Sched', sch, myClass); ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId]; System....


1

There is no way to query with a list of IDs. You can either try to work around it playing with the query id greater / less than parameters, or you can just do READ operations for each prospect. Use the Query if you have large contiguous blocks of Prospect IDs, otherwise READ will be better performant (especially if you use output=simple). Down side to the ...


3

You can't upload files that large in Apex. Use lightning-file-upload to upload files up to 2GB in size.


2

Right-click on the validation rules folder for the object, and click SFDX: Retrieve Source from Org.


3

This has a ton of problems with it. You check for nulls for things that will never be null, you skip iterating over empty lists (which is harmless), you call a massive loop for every record when a map would have sufficed, etc. It's no wonder that this could have problems running in bulk. I'm not sure how much work needs to be done to optimize, as you've not ...


0

As per the comments, your issue was that you could not see the product name. This is because your template is using: <p key={product.Id}>{product.Id} {product.Name} {product.UnitPrice}</p> However, the returned data from your Apex code actually includes the Product2.Name. To see this please update your template to: <p key={product.Id}>{...


1

@Robs i am not sure if you manage to find best possible solution. I use to do like this, so at least user know possible values for the parameter. @InvocableVariable(label='Season' description='Type one of these WINTER, SPRING, SUMMER, FALL' required=true) public String season;


2

The details are fairly well covered in What are the parameters for the Salesforce WebServiceCallout.invoke method? From Jeremy's answer: If the variable represents another XML element or a text node, then there needs to be a matching _type_info String[] e.g. bar_type_info. The elements of this array are: XML element name Schema XML type minOccurs maxOccurs ...


-1

SELECT Id ,Body ,Name ,NamespacePrefix ,Status FROM ApexClass WHERE NamespacePrefix = NULL


0

By default files object created under related list will follow this behavior . In short , files will not be accessible by Community user license ( External users) but only Standard user license (Internal Users ) because those file visibility properties value was set as "InternalUsers" on SFDC database level To escape from this problem , like your ...


2

I tried to retest the performance of the 3 approaches (added getSObjects(SObjectField) approach). Org Params: ApiVersion: 51.0 InstanceName: CS100 IsSandbox: true OrganizationType: Developer Edition Results for 50 trials each of 20.000 calls: Approach MIN CPU (ms) MAX CPU (ms) AVG CPU (ms) STD (σ) acc.Contacts 10.00 16.00 12.63 1.83 acc.getSObjects('...


2

Your Apex unit tests have no access to data outside the test context unless @seeAllData=true is specified (which you should almost never do). Even if you have visibility to the data through that annotation, changes made to data during test context is always rolled back at the end of the test. Running a test should never impact your real org data. If you were ...


1

This is a question that's haunted me throughout my time in Salesforce. What's the best practice for "running scripts", whatever that means. Here are methodologies that our team has found to be effective: Build the script into an apex trigger that runs when a checkbox is checked. In the before trigger, the checkbox is automatically unchecked. Next (...


2

What are the different ways in which to ensure the old records are also displaying this new information correctly? Data Loader, Import Wizard, Batch Class, Queueable Class, Execute Anonymous, etc. Anything that can modify every record in the database in a single pass. It'll be different depending on if you have 5k records or 50m records as to which approach ...


0

In the test class, you have to assign some value to "quantity" and "scdDate" then it will automatically cover the OpportunityLineItemSchedule.


1

From the help page on the JWT flow: Salesforce requires that a JWT is signed using RSA SHA256, which uses an uploaded certificate as the signing secret. HS256 is not accepted by Salesforce (via a connected app and the Salesforce-provided services/oauth2/token service).


1

The issue is that the PushTopic name must be unique. Could you please try to generate the random name and then set that as a name in test class context. Sample code to generate random string. Integer len = 20; Blob blobKey = crypto.generateAesKey(128); String key = EncodingUtil.convertToHex(blobKey); String Name = key.substring(0,len);


0

The documentation for apex properties does not mention using automatic property syntax for static variables. This means you will want to have a private static variable to contain the value of boolvar. global without sharing class ClassA { private static boolean boolvarValue; global static boolean boolvar{ get {return boolvarValue;} set { boolvarValue =...


1

The Map surveyIdToSum is a Map from Site_Survey_Response__c Ids to Site_Survey_Response__c. However survey.Id is the Id of a Site_Survey__c. This is a different object, so it's Id won't be used as a key for surveyIdToSum. Hence aggSum is null, so calling aggSum.get(...) is giving you a NullPointer.


1

If zero rows would be returned, there's no entry in the map for the record, so you need to check for that first: private static void updateRiskScoreTotalOnSiteSurvey(List<Site_Survey__c> newSurveys) { Map<Id, AggregateResult> surveyIdToSum = new Map<Id, AggregateResult>([ SELECT Site_Survey__c Id, SUM(Score__c) riskScoreTotal ...


1

Your issue is here Leadconvert.setAccountId(Linked_Account__C); You need to query for the Leads before you enter the for loop Map>Id, Lead> leadsById = new Map<Id,Lead> ( [SELECT Id, Linked_Account__c FROM Lead WHERE Id IN: leadIds] for (Id currentLead: LeadIds) { ... LeadConvert.setAccountId(leadsById.get(currentLead).Linked_Account__c)...


1

Okay I figured it out, I was using a SingleEmailMessage object, and according to this documentation I have to add an attachment using the following code: email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); instead of doing Mail. attachment This worked!


2

FIELDS(ALL) works in the Developer Console ("Query" tab) and other APIs (REST, SOAP, etc), just not Apex. You can use FIELDS(STANDARD) or FIELDS(CUSTOM), but not both (or ALL). This is an Apex-only restriction to prevent blowing up heap limits.


2

savePartAStaysDetails isn't looking for any old DataWrapper, it's looking specifically for the DataWrapper class defined as an inner class of your SeekPartAStays class. When you define an inner class, you're committing yourself to using OuterClass.InnerClass everywhere outside of the outer class. SeekExtension.DataWrapper is a different class/type than ...


3

InvocableMethod can have at most one input parameter, but it could be A list of a user-defined type, containing variables of the supported types above or user-defined Apex types, with the InvocableVariable annotation. Create a custom global or public Apex class to implement your data type, and make sure that your class contains at least one member variable ...


0

OAuth's flow is meant to be an interactive experience with the login server. What you're meant to do is to redirect the user to the endpoint. Once the user clicks "Yes" to confirm access, an access code is sent back to the origin server to complete the final steps. That looks like this: Salesforce Microsoft Redirect --------> ...


5

As at Spring '21, 2GP managed packages do not support component deletion, as covered in the 1GP vs 2GP gap documentation. A rename is equivalent to delete (old name) and add (new name). Salesforce plan to add this ability in the future according to webinars and presentations around 2GP. Your solution, therefore, is to add back in the ExampleCtrl class to ...


1

On production: Check that the Process Builder is activated Look through the debug logs to see if any governor limits are being exceeded In the meantime, here's a bulkified version of the code (it doesn't address ensuring that you don't exceed per-transaction sendEmail call limits - for that you need some async processing): public class ...


1

You can check if you're near the limit with something like: if(Limits.getHeapSize() > 0.9*Limits.getLimitHeapSize()) { This puts you at 90% or more usage, typically a safe value, but you may want to experiment for your use case. When you're done with a record or other data, you can "free" it by clearing the variable; you don't necessarily need ...


3

Updating an OrderItem automatically causes the implicit Rollup Summary on Order.TotalAmount (i.e. the Sum of OrderItem.TotalPrice) If you have any other RSF on Order that reference OrderItem children, they will be recalculated in Step 16 of the Triggers and Order of Execution If the record contains a roll-up summary field or is part of a cross-object ...


1

let userCity = getCityCurrentUser(); An imperative Apex call returns a Promise, because it has to go to the server and back. JavaScript won't wait by default, giving you just the Promise, so you have to wait until the Promise resolves. You have two options here. You can either use Promise.then, or await. // If you use await, the function must be async. ...


0

sfdcfox's answer about needing it to be a rich-text field is correct. If you do change the field type though, your trigger would still not work for two reasons: The value you're setting for the href attribute is not contained in double quotes You're not checking to see if Location is already a link (any subsequent edit would make your Location be <a href=...


1

You can only create hyperlinks in fields that support it (they must be Rich Text Fields). As such, you're only going to get HTML in your Location field, as it is a normal Text field.


1

I would expected the Apex call Network.getNetworkId() to return an Id that you can then used to query the Network object to e.g. return the community name. (But watch out in unit tests - this method will return null there. So you will have to use e.g. Test.isRunningTest to add test-only fake code.)


3

this is used to remove any ambiguity between a function-level property and a class level property. A few examples: public class X { public String Y; public void ex1(String Y) { this.Y = Y; // assign parameter to class member } public void ex2() { String y = this.Y; // assign class member to local variable } public void ex3() { System....


0

From a technical perspective, you can call your webservice API in a Developer Edition org just fine either way. You would need to read the Force.com Sites Terms of Use (and Order Form Addendum) and Site.com Terms of Use (and Order Form Addendum) to see if your use case may be a legal violation or not (and I am not a lawyer, so if you're unclear, make sure ...


3

You only need to qualify a variable with this when there is a parameter variable, in a method of the class, with the same name as the instance variable. This allows the language to pick up the parameter without any context while allowing you to still access the instance variable/property via the use of the this context. It is always permitted to qualify ...


0

If the migration needs to be done in same org then there is no need to download the files in the local, you can create a apex script to query the documents and create files on the basis of the data queried. In case if there are lots of documents then you would need to run the script in batch Also in case if you want to download the data in file format over ...


0

You could use a map and check for any overrides to the schema field names. Something like this: Map<String,String> fieldNameOverride = new Map<String,String>{ 'BillingStateCode'=>'BillingState' }; //from your previous question for(String fldName:fieldLst){ //if there is an override, use that. fldName = fieldNameOverride.containsKey(...


5

Apex in general is not case-sensitive. Because of that, when you defined your String json variable, it caused you to "shadow" the JSON class. The hint that this is what's happening is in the error message. "Method does not exist ... from the type String" You can fix this by using the fully qualified name for the JSON class, System.JSON....


1

Field permissions require the identifier to be ObjectAPIName.FieldAPIName.


0

Rather than having to directly call the method through the controller like sfdcfox mentioned in his response, you could change the method from void to List<SelectOption>, rename to getVendorAccountNames, declare vendorAccountNames inside the method itself instead of outside, and return vendorAccountNames in order to take advantage of Visualforce Getter ...


0

Any specific reason why you are adding the map to a list here? List <Map<String, String>> a = new List <Map<String, String>>(); a.add(objPromociones); You can just do this: public static agregarAdicionales(Map<String, String> objPromociones) { String value = objPromociones.get('ApexNombrePromo')...


1

You need to call Test.stopTest() before assertions. That said, you could increase your coverage a bit by calling scheduler instead of batch directly: Test.startTest(); System.schedule('TEST PB SCHED', '0 0 * * * ?', new UpdateContractPBSched()); Test.stopTest(); Also, consider removing your try-catch block if you are only going to System.debug() the results ...


0

First of all, I have to call this out: this is a very poor data model. By storing data in CSV in a text field, you are sacrificing much of the innate capability of the Salesforce database or indeed any database to effectively relate, index, query, and search structured data. That's going to make all further implementation you do more expensive, less ...


0

New Answer If this is a user prompted activity, then you need to confirm the old password to make sure that they are indeed who they say they are. Otherwise, your Users may change each other's passwords. If you need to strictly update a users password then you can use any of these three methods in the system class. This one will send the specified email ...


1

It seems to me that: let value = name.value; Should be: let value = event.target.value; I don't see any other reason why this code should necessarily fail, though I haven't seen this error before. You can reduce your code to just: public with sharing class VisitsController { @AuraEnabled(cacheable=false) public static Id createVisit(Visit__c ...


3

I think you meant: if(Test.isRunningTest()) { instead of: if(!Test.isRunningTest()) { Please be aware that this is definitely not considered a best practice. In addition, your query is malformed: + 'WHERE CreatedDate >=:' + startDt + 'AND CreatedDate <=:' + endDt; Ends up rendering as something like: WHERE CreatedDate >=:2021-04-16AND CreatedDate ...


0

I'm not sure if this top voted answer workaround is valid anymore. It didn't work for my below Exec. anonymous code. Feel free to copy-paste and try. Map<Id, ContentVersion> mapCV = new Map<Id, ContentVersion>(); Set<Id> setId = mapCV.keyset(); List<ContentDocumentLink> listCDL = [SELECT LinkedEntityId, ContentDocumentId, Visibility ...


Top 50 recent answers are included