Questions tagged [apex]

Questions relating to Apex, the native programming language for the Force.com platform. Use it for general questions on syntax, errors, constructs, and rules of use. Most questions should include a code *excerpt* to help answerers understand specifically what has gone wrong or why you need help.

Filter by
Sorted by
Tagged with
12
votes
2answers
10k views

NO_MASS_MAIL_PERMISSION Error from Unit Test on SingleMailMessage

I am currently working in a Config-Only sandbox. I have a unit test that is continually failing with the following error message: System.EmailException: SendEmail failed. First exception on row 0; ...
2
votes
1answer
470 views

Opportunity Trigger returns a child's size and is inaccurate

I have built a Trigger on the opportunity, my query looks at the Opportunity and it's child Service_Contract__r and validates the the child size is not greater than 0. for(Opportunity opp:Trigger....
14
votes
4answers
5k views

Combinations of fields to be unique

I have a custom object. I want to put in a business rule so that a combination of two fields must be unique. So I have Field1 and Field2 and want the combination to be unique: Field1=4, Field2=7 ...
6
votes
1answer
2k views

Where is the Apex URL builder?

Using apex:outputLink or URLFOR(target, id, params) is great in Visualforce. But in Apex land I always see people looping through lists using EncodingUtil.urlEncode(param, 'UTF-8'). If System.Url ...
3
votes
0answers
168 views

Anyone used apex-atom?

Has anybody used the apex-atom libraries? I think they were originally written by Dave Carroll but looks like they haven't been updated for about 4 years. We have a little point integration ...
101
votes
3answers
63k views

How can I efficiently generate a Set<Id> from a List<SObject> structure?

I have a bit of code where I've written a SOQL query that returns a list of SObject records, however I need a Set<Id> structure to pass to another method that I don't have control of (and thus ...
1
vote
2answers
688 views

Get Total Permutations of child objects in a list of lists

Let's say I have a list of questions that stores an object that has a list of it's possible answers, and I need to generate all permutation pairs with no duplicates where one element of the pair is in ...
14
votes
1answer
5k views

Inserting a link in an ApexPages message

I was wondering if there's a way to display a link in an ApexPages.Message. There's nothing mentioned in the documentation about it, so I simply did a : ApexPages.Message(ApexPages.Severity.CONFIRM, '...
12
votes
1answer
2k views

Programmatic capabilities for reacting to Account Merges

Who has dealt with merges in triggers? I know a merge operation (specifically Account merges) fires a delete trigger on the loser, and an update on the winner. To what degree can I, programmatically, ...
2
votes
2answers
3k views

Too many code statements: 200001 … why do this error occur?

I searched but didn't found anything about this error, but I'm facing it now. "Too many code statements: 200001" The error specifies "code statements", I was familiar with script statements but didn'...
1
vote
1answer
3k views

Trigger addError on before, will not pass my test class

I have created a trigger on Opportunity and managed to test it and it ran smoothly and even tried it out on the sandbox and everything ran fine. I then decided to use addError() along with the trigger....
4
votes
1answer
2k views

Metadata API through APEX using old API version

I've been looking online and noticed different ways people are attempting to leverage the Metadata API WSDL through APEX directly (and the issues around consuming the WSDL), but I was curious whether ...
4
votes
3answers
8k views

Is it possible to convert an SObject to a Map?

Is it possible to convert an SOBject to a Map in a very few short lines of codes?
6
votes
2answers
987 views

Testing code that depends on an SObject

I have a page which displays an entity that belongs to another package. In order not have a hard dependency to this package, I build a wrapper object and make this wrapper object accessible to the ...
2
votes
0answers
1k views

Navigate to Standard Layout or VF page dependent on recordtype

Im using a 'dispatcher' page to direct my users to either a Standard Page or VF page, depending on the recordType. This works fine in terms of sending the user to the correct page, however, if i add a ...
17
votes
1answer
18k views

How can I return JSON object from REST service?

I used JSONGenerator to generate a customized JSON String. I know I can return sObject or String using Salesforce REST. But now I am sure I do not want to return sObject because I want the customized ...
12
votes
8answers
5k views

Does Schema.GetGlobalDescribe() Account for Prefixes?

It seems to me that in my dev org at least, the keys for the map returned by Schema.GetGlobalDescribe() do not use namespace prefixes... so does anybody know what happens when there are two objects ...
1
vote
1answer
893 views

Getting revised map <id, string> data back into original list under same id

I seem to be having difficulty getting data from a map back into a list so that it corresponds to the correct Id and field it was originally associated with after it's been modified in a trigger. For ...
5
votes
4answers
7k views

Scraping text from email and storing in a field

I know that there is a web to lead form I can create to do something similar, but is there an easy way to get the inbound email address which can be monitored and the data from the email can be ...
0
votes
1answer
143 views

Running ApexClasses in PE with Security Review and Certification

I've a managed package which I would like to be installed in a Professional Edition. When I try to install the package in the PE, I get following error, of course my package has few ApexClasses/Pages/...
2
votes
1answer
220 views

Not grasping the error checking when dealing with a trigger

Hello and thank you for your time. I have created a trigger on an opportunity that 'should' only run my methods if the stageName = 'PO IN(100%) and a contract is not already created.. as well if ...
1
vote
1answer
498 views

Cannot use StandardSetController with ContentVersion?

I am trying to display a list of documents stored in Salesforce CRM Content on a VF page using JQGrid. I used OFFSET for paging. Since the number of records is more than 2000, I wanted to use ...
1
vote
3answers
2k views

how to remove span from pageBlockSection

i have one pageblocksection. i want to remove Required information displaying on right hand side. Thanks. <apex:pageBlockSection columns="2" title="Personal Data"> <apex:pageBlockSection ...
3
votes
3answers
5k views

Getting selected picklist values and moving them between two lists

I have 2 multi selectlists and 2 buttons in visualforce page and the buttons are Add and Remove. The first picklist has some fields, and when I select some fields and click on Add button than these ...
2
votes
1answer
326 views

unit testing custom email validations

I have a catch-22 issue that I have been unable to test fully. I am using a W2L form to input lead information remotely and its well documented that using an email field can cause the record to fail ...
3
votes
1answer
4k views

Test class is not visible. Can I not call a test class from a separate test class?

Hello and thank you for taking the time to read my question. I am getting near the end of finally testing my new trigger, and started to clean up my code. I decided(as recommended by others in this ...
12
votes
5answers
7k views

Organization Administration Locked…?

After having my Developer Console not be able to save a class that I edited, I faced this error message when trying to edit/save the class directly in the browser: Organization Administration Locked ...
3
votes
1answer
406 views

Visualforce w/ Custom Controller Not Behaving as Expected

I am trying to create a VisualForce page, with a custom controller, that displays the feed items from the chatter feed of the record provided by the user. The goal is to have the page start with ...
1
vote
1answer
711 views

dashboard to display 2 text values

Is there a way to create a dashboard that has the format : Region Status (Rich text) North America pending Japan o Yet to be approved o Waiting for ...
1
vote
1answer
3k views

Using a VF inputfield as a variable in a custom controller

I am in the process of learning APEX/VisualForce, and I'm working on a VF page that lists out all of the chatter posts from a specific record. Right now, the record that it displays the feed for is ...
6
votes
2answers
4k views

How to get the IsSyncing to TRUE on a QUOTE in test class?

Hello and thank you for taking the time to read my question, this may be a really stupid question but I have been banging my head all morning into finding the answer. I looked at the Quote Schema as ...
15
votes
3answers
9k 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 ...
8
votes
1answer
2k views

“Maximum stack depth reached: 3” when doing String.replaceAll()

I am getting a strange "Maximum stack depth reached: 3" when doing a String.replaceAll() with bigger Regex on a quite big string (40 lines of text). I am trying to remove any comments and literal ...
1
vote
2answers
122 views

Getting correct data from a list would a for loop be best practice?

Hello and thank you for taking the time to read my question. I have a simple call to the recordType object that will have to results. The reason I have two results is because I need to verify of the ...
23
votes
3answers
12k views

possible to access custom labels dynamically?

In apex you can reference a custom label with system.Label.labelName, but is there a more dynamic way to get a custom label for example system.Label.get(labelName)? I can't find anything like this in ...
7
votes
1answer
2k views

How to get list of All Objects enabled with Activities?

Is there anyway we can find all Objects which have Activities enabled, in APEX?
9
votes
1answer
6k views

Create CSV file from SObject records - How to Optimize Script Statments [duplicate]

I have following code which Create CSV file from any SOQL query, but the problem is its not very efficient (not optimized to execute with less number of statements). This code runs out of script ...
5
votes
1answer
4k views

Problem in commandbutton with immediate=“true”

I have <apex:commandbutton> in a repeat section. I want that when submit is peformed of a single section it does not encounter the validations of other sections, so I am using immediate = true. ...
29
votes
3answers
12k views

When should a static intializer be used?

I come from a C# background, so I was a bit confused when I encountered a static intializer today: public static final Integer MAX_VALUE; // in days static{ Common_Config__c config = ...
4
votes
1answer
6k views

Can I query the translated value and return the key in translation workbench?

Here is a breakdown of the problem I am trying to solve. In a web to lead form we are updating a custom picklist field on the record based on inputs from the form. The value is coming back in the ...
17
votes
5answers
5k views

Javascript remoting and apex date design pattern

I'd like a clever way to handle this in all my code from now on. I have some existing methods that do date calculations in apex...some use the businessHours object and some don't. Many surface ...
9
votes
1answer
18k views

convert time from a different timezone other than local to GMT

suppose i am a call center employee with IST time zone and want to fix a meeting with a US customer. I enquire about his time zone and time at which he will be available. Now i want to convert the ...
8
votes
3answers
4k views

No longer possible to mix testMethods in classes?

All of a sudden I am unable to call methods in any classes which are marked with @IsTest. The only thing I changed was all my *-meta.xml files (blindly) from ApiVersion 25/26 to 27. Until now all my ...
10
votes
1answer
3k views

Disable Validation Rule with Apex Code

Is there a way to disable Validation Rule with Apex Code? I need disable a managed Validation Rule in all customer orgs.
1
vote
1answer
2k views

Test Class for Xml Dom Document & WebServices

My Apex class public with sharing class helpTextClass { public string main(string url) { Http h = new Http(); HttpRequest req = new HttpRequest(); req....
5
votes
1answer
2k views

Formula to display the current week

Is there a formula to display the calendar week I want to display the following for the 2nd week of FEB,2013 eg: 02/10/2013 to 02/16/2013 and for 3rd as : 02/17/2013 to 02/23/2013 I want to ...
3
votes
1answer
1k views

How can I specify a record (or parentId) for a postFeedItem to be posted to?

I am trying to create a chatter post using an APEX trigger, and I'm almost there. I've gotten to this point: ConnectApi.ChatterFeeds.postFeedItem(null, ConnectApi.FeedType.News, 'me', feedItemInput, ...
4
votes
2answers
2k views

Getting Person Account Fields using Apex

Can we use describeSObject to get the fields from a Person Account? Normally we would use the following to get the fields from an Object: Map<String, Schema.SObjectType> gd = Schema....
6
votes
2answers
696 views

Regexp to extract parts of ApexClass.Body

I want to calculate some metrics on Apex classes. So I need to somewhat "parse" them with the means that exist in Apex e.g. regexp patterns, groups and regions. I want to match class declarations ...
12
votes
2answers
5k views

Is there a way to find out where a class is used, other than attempting to delete it with Eclipse?

When I have a class I believe I no longer use, I usually attempt to delete it and see if there is an error. This strikes me as one of those things that just must be wrong...but I don't see another way....

1 553 554 555 556 557 570