All Questions

Filter by
Sorted by
Tagged with
37
votes
5answers
86k views

list.IsEmpty() vs list.Size() > 0 vs list != null

I want to check the list is empty or not if not proceed further. So, which is preferable in apex and what are the differences between them? if(myList.size() > 0) or if(!myList.isEmpty()) or ...
37
votes
3answers
24k views

How to use fieldsets with Lightning?

Been trying to figure out how to create a salesforce Lightning input form, based on fields from a fieldset. As an aura enabled apex method is not allowed to pass an entire fieldset I tried by ...
37
votes
6answers
47k views

SOQL Alias a column

I am wondering how you would do something simple like this in SOQL. select first_name as name from tableA I can not find any documentation on Aliasing a column which is very common in all forms of ...
37
votes
5answers
39k views

Howto wildcard SELECT * to query all fields of objects in APEX?

I have created sObject and I need all the fields and I have many. Is there a way I can directly get all of them rather then typing each one of them.
37
votes
1answer
10k views

Testing AuraHandledExceptions?

It seems like when I call getMessage on a thrown AuraHandledException, I see "Script-thrown Exception" instead of the message that I have set. Any idea why this may be happening? Controller: @...
37
votes
2answers
3k views

Why Would I Not Enable Chaining?

The Apex Design Patterns is an awesome resource, and I learned many tricks from it. One of my favorites is method chaining, and I quickly developed an axiom: Any time you would return void, return ...
37
votes
6answers
4k views

Why do we still need to hack the Sidebar? Usecases - Workarounds - Alternatives

Since it seems to me, that a lot of people still need sidebar workarounds, I would be interested to learn about the use-cases, experienced challenges and (most important) possible strategies to avoid ...
37
votes
3answers
29k views

What standard and custom fields are indexed?

I'm trying to find a proper list of what standard fields are indexed by default in salesforce, as well as under what conditions custom fields are indexed. To start things off I know fields are ...
37
votes
2answers
3k views

Dev Console jumpy on mouse scroll

Since yesterday my dev console is jumpy when I scroll with the mouse wheel. I use windows on chrome at 80% zoom default. Putting it back to 100% zoom does not fix the problem. I only have this ...
37
votes
3answers
6k views

How do I get the intersection of RecordType and Picklist values inside Apex?

Context This question has been asked before in the past and I've found several discussions of it here on StackExchange and elsewhere (links below to pages I've found in my research). So far I'm not ...
36
votes
6answers
20k views

Using APEX to assemble HTML Letterhead Emails

I am looking to assemble an HTML Letterhead Email Template for an email service integration project. There are two sObjects that hold this information - EmailTemplate and BrandTemplate. ...
36
votes
5answers
70k views

How to check in Apex if a Text field is blank

I'm unsure what's the shortest and most robust way to check whether a Text field is blank / empty? /*1*/ Boolean isBlank = record.txt_Field__c == ''; /*2*/ Boolean isBlank = record.txt_Field__c == ...
36
votes
7answers
27k views

Copying metadata and code from one Production org to another

How do I copy(for want of a better word) metadata (i.e. Objects, Workflows, Validation rule etc), and code (Apex, Visualforce, Triggers) from one Production org to another production org? Is this ...
36
votes
4answers
304 views

Ideas that every salesforce developer should vote for? [closed]

I've noticed that Ideas around improvements to the apex language don't seem to get the same up-vote exposure as some of the admin-based improvements. Thinking this might be a good place to ...
36
votes
3answers
10k views

Is there any way of confirming that an @future method has been called/queued in a test class?

I have a Controller (FooController) which calls an @future method (bar()) belonging to another class (FooServices). Ideally in my test class for this Controller (FooControllerTest) I only want to ...
36
votes
7answers
16k views

Obtaining all ContentDocument records using SOQL

According to the Salesforce documentation on ContentDocument Users (including users with the “View All Data” permission) can only query files they have access I find this very strange. Why would a ...
36
votes
2answers
22k views

Dynamic number of columns in a pageBlockTable

I would like to be able to dynamically control the columns displayed in a page block table. This would mean that if new fields are added to the object the controller and page do not have to be updated....
36
votes
1answer
54k views

How do I build a SOQL query for records in a list of IDs?

Can some one correct my soql? I need to export records in data loader like: WHERE Id IN ('123123123','123123fsdf') But this following query does not work for me: SELECT Id, Syndication_Documents__c ...
36
votes
5answers
6k views

Documenting Salesforce.com Apex class files

[I asked this question on Stack Overflow but didn't get any answers there.] Since the Salesforce.com Apex language is "Java-like", I'd like to use javadoc or Doxygen to generate API documentation for ...
36
votes
1answer
16k views

How does SalesForce calculate Data Storage usage amount?

My company has recently exceeded our data storage cap (at 102% right now.. :/ ). A large portion of the data that pushed us over our limit was due to an import of records. The weird thing about this ...
36
votes
2answers
4k views

Ghost Schedulable Classes Blocking Deployment

Recently I've been running into issues where deployments were blocked due to a Schedulable job pending or in progress when I'd already cleared the Schedulable job from that class. Any tips for ...
36
votes
3answers
6k views

How to use GIT on multi dev environment

I have previous experience using GIT in other development environment and I never had much troubles using it. We where using SVN for salesforce, however we want to migrate to GIT for the uncountable ...
36
votes
5answers
3k views

Developer Accounts for ExactTarget

Has there been any progress made on granting a developer account for SF and HubExchange Devs? It feels conceptually wrong to me a SF product doesn't allow developers to perfect and develop a wider ...
35
votes
3answers
8k views

How to deploy apex classes that are scheduled

This is related to Is there any way to unschedule an apex scheduled job programmatically?. I noticed user320 mentioned there is a way to use Type.forName to decouple your classes from the scheduled ...
35
votes
5answers
17k views

Object Deploy fails with: “duplicate value found: <unknown> duplicates value on record with id”

When I try to redeploy an object that exists in source and destination orgs, the deploy fails with the cryptic and useless error message: duplicate value found <unknown> duplicates value on ...
35
votes
1answer
4k views

What are Lightning Web Components

Salesforce has just announced a new feature, Lightning Web Components. What is this? What does it have to do with Lightning Components and the Lightning Component Framework?
35
votes
1answer
25k views

Writing Test Classes for Apex RestService

I was writing test classes for my apex Rest Service that I had built for an Ipad app. I noted some very interesting things while experimenting. Before doing anything, I just did a google search and ...
35
votes
8answers
14k views

Apex Code Coverage: Test classes are included with 0% in overall code coverage calculation

We are making heavy use of stub and mock objects in our Apex tests. Most of the time we are defining the mocks as inner classes of our test classes. We have noticed, that test classes, which do ...
34
votes
5answers
71k views

Apex: Dynamically get fields for an SObject - no hardcoding

It states in Salesforce Apex docs that I can get fields for a particular SObject (standard or custom) in the following way: Map<String, Schema.SObjectField> M = Schema.SObjectType.Custom__c....
34
votes
2answers
33k views

HTTP Callout from Triggers

I have a trigger on the Custom Object that calls a class. That class makes an HTTP GET request to a Web Service. However I get the following error: Callout from triggers are currently not supported. ...
34
votes
6answers
5k views

What is a good set of coding conventions for Salesforce development?

I've looked around in the Apex and Visualforce developer guides and around the web and can't seem to find any coding conventions out there. The Apex Dev guide has a section on Naming Conventions that ...
34
votes
4answers
6k views

Namespace Prefix in JavaScript and Apex within Installed Package

When you have a dedicated Visualforce Page and can use modern JavaScript Remoting techniques, this is seldom an issue. But I'm looking at some historical code in a managed package like this: {!...
34
votes
3answers
12k views

Expression Functions for Lightning Web Components

How can expression functions similar to Visualforce and Lightning Aura Components be achieved within lightning web components? For example, <template if:true={index % 5 == 0}><br></...
34
votes
2answers
7k views

When To Use Set vs. List In SOQL

I have always assumed that it is better to use a Set in my query filters instead of a List. For example: Set<Id> parentIds = generateParentIds(); List<Child__c> children = [SELECT Id FROM ...
34
votes
11answers
23k views

Get Site URL from apex

Is there a way to get the URL of a salesforce site from apex I need this to send the url in an email message, so the apex is run outside of the site context. I basically want to expose a link to my ...
34
votes
2answers
13k views

Post Sandbox Refresh Steps

What steps should be taken after a sandbox refresh to avoid filling up the sandbox storage, sending emails, or outbound messages? I'm looking for steps to take such as disable scheduled Apex jobs, ...
34
votes
2answers
9k views

How to use Advanced Currency Management (ACM) in Custom Objects?

I've been searching for the last two weeks about how to implement Multi-Currency correctly in our organization. I'm pretty sure I'm not the only one who noticed that if you want to use the Advanced ...
34
votes
3answers
702 views

Spring 14 Limit change can break existing apps even when running previous version API

I'm looking for confirmation that what I'm seeing is real, and if this is a bug or an intentional breaking change. Create the following test class: @istest public class TestLimits{ public static ...
34
votes
2answers
327 views

Which kind of issues will be shown at trust.salesforce.com and which issues will be omited?

In the context of a different question, we encountered a deployment performance degradation on EU5 of between 6000% to 10000% using Metadata-API. This means that work (saving a single APEX file to the ...
34
votes
2answers
426 views

Related Objects in User.layout Metadata on Winter '14

What's going on with the layouts/User-User Layout.layout metadata file? I have scripts that snapshot all of my metadata every day. Ever since we upgraded to Winter '14, the following lines are ...
34
votes
1answer
861 views

Best practices for designing and maintaining Global classes?

We've always been conservative when it comes to exposing Globals for use by extension packages or subscriber extensions, and perhaps too conservative. We're considering being more proactive wth our ...
33
votes
10answers
2k views

How can I cause side effects outside an execution context?

I've got a scenario that relies on the system's "automatic rollback" behaviour to undo any DML, emails, futures and so on, in the case of an error. Basically, by allowing code to throw an unhandled ...
33
votes
3answers
16k views

Return Name of class from instance of that class

I need a quick approach to something like: MyClass mc = new MyClass(); String theName = ClassNameProvider.getName(mc); // returns 'MyClass'
33
votes
2answers
11k views

Two SFDX project folder structure questions

A default SFDX project is created with these folders: force-app/main/default force-app/test/default under which folders such as aura and classes and staticresources that contain components can be ...
33
votes
2answers
17k views

How to access profile permissions via API

If I know the name of a certain profile, I would like to obtain CRUD permission settings for each object in the profile using Apex. I see that there is an sObject called Profile, but this only ...
33
votes
1answer
6k views

Generic Apex Trigger

So I was kind of throwing round the idea of making a generic apex trigger that is callable by multiple objects. Say you have the following sObjects: Account Sales__c Sales_Contacts__c And I wanted ...
33
votes
1answer
6k views

Can I have a public APEX REST API?

Can I have a public APEX REST API e.g. APEX REST api that is accessible without authentication?
32
votes
2answers
23k views

Is there any difference in equals and == for String variables?

if ('text'.equals(str)) or if ('text' == str) Is there any difference? If yes, then what is it? Added, after answered. String q = 'teXt'; system.debug('teXt'.equals(q)); // true system.debug('...
32
votes
6answers
10k views

Target inner elements of standard Lightning Web Components with CSS

Say we have a LWC with the following template in a component named example: <template> <lightning-textarea class="test"></lightning-textarea> </template> And some css to ...
32
votes
2answers
49k views

Round a Decimal to two decimal places

How can I round an arbitrary Decimal to 2 decimal places (hundredths of a dollar)? My first thought was to use the Math Functions ROUND(number, numDigits): Decimal toRound = 3.14159265359; ...

15 30 50 per page