Questions tagged [code]

Code indicates that a question is to do with pages, controllers or similar, and not the declarative aspects of the platform.

Filter by
Sorted by
Tagged with
36
votes
7answers
26k 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 ...
28
votes
1answer
3k views

What's the best way to check if person accounts are enabled via Apex Code?

I need to be able to check if an org has Person Accounts enabled via Apex Code as part of package. What's the best way to do this without making the package require Person Accounts be enabled in any ...
15
votes
3answers
11k views

Can we access class properties dynamically with Object class?

Is it possible to access Apex class properties dynamically? While we can create Object's, and assign any other class to an Object, I'm not sure how I can access the properties of these Object's. Can ...
15
votes
3answers
8k views

Visualforce and Apex Theme for Notepad++

Are there complete themes for Visualforce and/or Apex for Notepad++? Ideally with autocomplete for all parameters and methods and code highlighter? I made custom a theme for Visualforce only but ...
14
votes
3answers
10k views

Verification code - when is it asked?

I've read a lot of docs for this and I'm not completely sure of what are the conditions for the login verification code be asked. Can someone please help with this question and clarify me? Thanks
11
votes
4answers
2k views

Source control tool for Salesforce development

I am looking for a source control tool like Github which can do the following for us. Provide a cloud based source control repository like subversion, etc. Provide web based view to track changes. ...
10
votes
2answers
159 views

Incomplete code blocks vulnerability

I've submitted my application for Security Review and I've got this problem in the report. I'm not sure how to fix it. Let's see the First case: I have some classes that don't have any code like ...
9
votes
2answers
4k views

Best version control for salesforce -eclipse and Mavens mate

Which is the best version control for force.com projects. Currently we are not using any version control and we are planning to follow some practices. We predominantly use eclipse and Mavens mate. We ...
9
votes
4answers
2k views

Detecting dead code in Salesforce

In Java, there are several effective tools for detecting dead code like CodePro. I have tried but probably they won't work for Salesforce project. It is not usually an easy job to figure out the dead ...
7
votes
5answers
4k views

96% code already used. How to manage it?

We are using a developer sandbox for development. When i go to System OverView > Business Logic > Code Used, i see that we have already use 96% of the amount of code we can write. Can we get it ...
6
votes
3answers
795 views

How can I rewrite this method with efficient SOQL queries

public List<phonesterDat> getCompanyData() { List<phonesterDat> var1 = new List<phonesterDat>(); for (Keyword__c keyword : [select kw__c from Keyword__c]) { phonesterDat var = new ...
5
votes
2answers
152 views

Is there a more efficient way of getting an object by related list?

I've started programming in Salesforce in January 2015. Most of my code uses this methodology : : List<String> accountIds = new List<String>(); for(Account account : accounts) { ...
5
votes
2answers
2k views

Test Classes are included in code coverage

I've looked at a few questions but couldn't find the responses that worked for me. I've attached a screenshot of my classes and all of their code coverage. Any class ending in test is a test class. ...
5
votes
1answer
103 views

Tools for code Evaluation [closed]

is there any tools to test the logic at what point will hit the saleforce governor limits (applicable only)?? Any sophisticated tools other PMD to evaluate your code against the salesforce best ...
5
votes
1answer
2k views

Fuzzy Matching for Duplicate Address Checks

A good duplicate checker - for checking if the same address has already been entered - needs to take into account misspellings or spelling variations. We have implemented our own APEX methods which ...
5
votes
1answer
12k views

Structure for classes to call inner or sub classes

I don't have a Java background and am working on a class where I'd like to be able to call inner classes from withing methods of the outer class. As much of Apex is implicit and I'm still learning, I ...
5
votes
1answer
257 views

Apex Bug (?) Null Field Values of Cloned Instances Don't Persist?

I want to take the state of a source record, clone it, and apply the clone to a target record. But I'm encountering an issue in which a null field on the clone does not nullify the field on the target....
5
votes
1answer
2k views

Can abstract classes have non-default constructors?

Abstract class: public abstract class FilterCriterionAbstract { protected Object leftComparableElement; protected Object rightComparableElement; public FilterCriterionAbstract() {...
5
votes
0answers
452 views

Team Foundation Server as source control for Salesforce Project?

Does anybody has experience on using Team Foundation Server as source control for Salesforce project? We are currently using Git but management wants to start using TFS as source control going ...
4
votes
3answers
1k views

Is there an Apex Linter out there?

I haven't seen an Apex linter and was wondering if anyone knew of one or had repurposed a Java linter? I'm so used to having this available when writing JavaScript or Ruby, it would be awesome to see ...
4
votes
2answers
856 views

How can I hide my code in visualforce page?

I developed my app, The controller is complete, and also the visualforce, but I need to hide my code at installing the app in another salesforce account. How can I make this possible? Is there any ...
4
votes
3answers
6k views

How to make triggers not fire when we use API tools like Data Loader?

I have written and deployed a Contact Trigger in our production environment, and whenever I would have to use Data Loader to mass update contact records, I would always have to go into the code and ...
4
votes
3answers
7k views

Passing list from Controller to VF page

I'm trying to pass a list from controller to page and use it in Javascript as an array to form html content. But, when I pass a list of objects, an exception is thrown. Uncaught Syntax error : ...
4
votes
2answers
242 views

Code review checklist to identify governor limits exceptions

I am reviewing apex and visualforce code from a client org and would like to know if anybody has a code review checklist which is focussed on governor limits. I want to identify key areas in ...
4
votes
2answers
173 views

Offline tool that can show dependencies between different metadata files

I was looking for a some kind of app (other than ant migration tool) that could analyze a code base pulled from a Salesforce org and show all dependencies between the files (for example – between apex ...
4
votes
1answer
51 views

Ghost Text in Apex Class Editor [duplicate]

I seem to have turned some weird setting on in Salesforce that "highlights" the line of code that the cursor is currently at. Whatever it is, it doesn't work very well and covers up text that I need ...
4
votes
2answers
935 views

Ctrl Click doesn't work in Force.com Ide?

I get used to ctrl+click code assist which would find the declaration of a variable/class/method in Eclipse, Visual Studio, Borland\Embarcadero Delphi. It is an extremely useful feature when dealing ...
4
votes
1answer
328 views

What can I use instead of <apex:tabPanel> in Lightning Experience

I am using in a Visualforce page to displaying of fields from an object that contains more than 100 fields and it is working as expected. I want to create a version of this sort of layout in ...
4
votes
2answers
204 views

Uploading file to Facebook from Salesforce

I'm trying to upload an image file to Facebook from Salesforce and current this is my codes and it is not working can anyone help me fix it? Please Note that my Image file is inside the Accounts ...
3
votes
1answer
1k views

Code Coverage question

I saw for the first time in one of my orgs where there is a 29% (61/208) what does that number in the brackets say ? I have never seen it in any other org. Is this a new release for winter 13 or has ...
3
votes
3answers
2k views

Getting dynamic Record Type name/id

Is there a way I can find out what recordType the user have selected? I have put together the apex code : private String getRecordTypeSelectedId(String recordTypeName) { String rtId; ...
3
votes
2answers
82 views

Accessing Object properties

When accessing Object properties like 'Account.Name' multiple times throughout the code, is it better to create a variable and assign the property value to the variable once or is it fine to ...
3
votes
4answers
3k views

Code Formatting

Has anyone gotten code formatting (Ctrl+Shift+F) to work in Eclipse? I know it's basically a Java feature but it would be neat to format Apex code according to rules. I also can't get some hotkeys ...
3
votes
4answers
5k views

How to print a quote or invoice from salesforce

How do I print a Bill, or an Invoice on a custom object on the click of a button. Things I've thought of Printable view : it does not give me the control to change the formatting Visualforce Page : ...
3
votes
2answers
478 views

Is this an abuse of ternary operator and inline SOQL or is this acceptable?

I have written a function like the one below to check if there is atleast one occurrence of a given Id in either of the two objects. I am having doubts on if I should use an if branch or use a ternary ...
3
votes
2answers
469 views

Email Alerts to Customers using Work Flow processes

Creating a work flow email alert. Would like to send out to customers email found in opportunity under contact roles. Currently, the only options are to select from drop down recipient type. Is there ...
3
votes
2answers
391 views

Are there any automated Apex refactoring tools?

With reference to a Stack Overflow question from 2009... In the last six years, have any automated Apex refactoring tools been developed? I'd like to do simple refactorings like "extract method", ...
3
votes
1answer
2k views

Using RegEx Pattern Match to create DateTime fields in trigger

How do I write code with the correct syntax to run a pattern grouping match within a string, then replace the pattern groups found in the result so that they follow a desired pattern? I've never done ...
3
votes
1answer
6k views

How to initialize date type variable

I am using date type variable public Date arrivalDate {get;set;} now my question is how we will initialize this variable in constructor in proper way, if I use this whats the meaning of 1,1,1. ...
3
votes
1answer
2k views

Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []

I am trying to add users to the chatter groups based on region field on User object using trigger and apex class. When ever I am creating or updating a user it is giving Invalid Cross reference key ...
2
votes
3answers
2k views

How to check the field value is same for all the records in the list?

I am retrieving records in the list and I want to check if the field Code__c is same for all the records. If not I want to give an error and make sure the field value is same for all the records in ...
2
votes
2answers
6k views

How do I cover 'addError' in test class

My Requirement is I have to cover so.AddError() in the test class. Apex Class: if(accountToUpdate.Inactive__c== true && accountToUpdate.Inactive__c <> accountBeforeUpdate.Inactive__c) ...
2
votes
2answers
1k views

In System Logs what does the false|true mean for Variables

There's a lot I don't understand about the Execution Logs from Salesforce. Maybe some of it is just my limited programming experience (Apex mostly, smattering of Python). I feel like there must be ...
2
votes
1answer
2k views

Is this Apex coding similar to Java scripting?

I don't have prior knowledge in coding. But would like to know and learn more about Salesforce Development and coding in Apex. I heard that Apex is more or like Java script, Is it true? Whether a ...
2
votes
1answer
869 views

Nested IF Statements

We are moving to use X-Author to upload our planner information into Salesforce via their excel app. The excel spreadsheet has been set up prior and fields are pretty fixed. We are trying to map their ...
2
votes
1answer
443 views

Queue Color Modifications

Our inbound emails are worked out of the Service Console. Messages coming in will end up in a Support Queue and then escalated/passed to different queues or technicians when appropriate. We receive ...
2
votes
2answers
292 views

Can you code on an iPad?

I've been thinking of buying an iPad and I was wondering if I could write my apex classes on an iPad? My iPhone's browser redirected me to the Salesforce1 app after I tried logging in to my sandbox. ...
2
votes
3answers
3k views

Workbench Rest Explorer Apex Code Coverage Query - Wrong Results

I ran a query in REST Explorer ( on ApexCodeCoverage ). Im getting duplicate (and wrong) results. Few classes/triggeres are repeated with different results. A class ApplicationInfoHelper is being ...
2
votes
1answer
91 views

Code coverage too low

I created a class the will return set and get the parameter to rest service here is the class public class LeadUtils { public String First_nm; public String Last_nm; public String Phone; ...
2
votes
1answer
124 views

Structure and fuction for picklist's values

I'm tring to optimize the code below. I'm looking for a structure where i can put the picklist's values and after (with just a condition) i want check the condition for all the values in the ...