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
7
votes
3answers
7k views

50,000 query row governor limit

I have a read query in a batch class which in orgs with a lot of data can bring back over 50,000 records and violate the governor limit. My question is it possible to do a count query, realise that ...
4
votes
3answers
3k views

Visualforce Charting: Line Chart Intervals with Dates

I have a custom object, MrCustomObject__c, which I am making into an apex:chart. Mr_Custom_Object__c has a Date field, Date__c, and a Number field, Number__c. The Dates should go along the x-axis ...
4
votes
2answers
2k views

How to create Account from Contact detail page?

I know we can create detail object from the master object by default. Like we can create contacts from account. But now I got a requirement to create Account from a Contact detail page. As we know, ...
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
92 views

What is a good way of guarding against NPEs while recalling attributes of objects in lists?

An as example, say I have a trigger (list object) with accounts in it, and I want to compare the "Status" attribute of an account to a String. This is how I do it right now: if (trigger.oldMap.get(...
0
votes
2answers
2k views

Creation of Batches from CSV resulting in erroneous state

I'm trying to make batches from a CSV file written using CSVWriter of opencsv as: CSVWriter writer = new CSVWriter(new FileWriter(filePath+createFileName), ',', CSVWriter.DEFAULT_QUOTE_CHARACTER); ...
1
vote
1answer
98 views

Creating a custom “Developer API Name” field on a custom object

I need to have a field that takes the text value of another field, and creates a developer API name out of it. Ie. Object__c.Name = 'FAQ: How to use salesforce?' gives Object__c.APIName__c = '...
2
votes
1answer
70 views

Report based on 4 Objects inc junction object

I have the following object structure Store (parent) : Investment (child) Site : Impact (junction object) : Store I'm trying to construct a query to display the results in a pageblocktable. The ...
10
votes
1answer
13k views

How to populate a list of Ids from a soql query without using a for loop?

I'm trying to populate a list of Ids using a soql query but can't seem to get there. Currently I have: Public List <Id> listOfGroupIds (id userId) { List <Id> ...
-3
votes
1answer
2k views

What's the basic setup for an invoice solution

Say, I have a basic invoice, with the name iv_i where i is the number of the invoice. Each invoice can have n items that should be added via a Visualforce page. The items later can come from a ...
9
votes
4answers
5k views

How to eval string expression in salesforce

Boolean b1 = true; Boolean b2 = true; String b3 = 'b1 && b2'; Boolean b4 = Boolean.valueOf(b3); system.debug('test Bool '+ b4); Given a string how can you convert into expression without ...
2
votes
1answer
70 views

Calendars malfunctioning in Spring '13 release?

In the sandboxes i've tested that have the Spring '13 release, I think there's a bug when the user creates an event in either the public or personal calendar. I navigate to the calendar, double click ...
2
votes
1answer
3k views

How List all the Properties of Validation Rules through Metadata Api

I need to list all the Properties of Validation Rule like Status, Description, Error Message, Error Formula inside the Salesforce through Metadata API. As per my understanding, we can retrieve only ...
3
votes
4answers
1k views

RegExp to extract namespace prefix from SObject name

I want to get a potentially empty namespace prefix from arbitrary sobject names by using Regexp. All following cases should be covered: 1. StandardObject 2. CustomObject__c 3. ...
0
votes
2answers
2k views

How to send Weekly Email to email-fields of records?

I have rejected Workflow Rules, since email alerts can't be sent at the exact same time every week. I have rejected schedulable Reports/Dashboards since emails can't be sent to email fields of records ...
7
votes
2answers
753 views

Is a list from a subquery modifiable?

I am trying to modify a list of sobjects that I get from a subquery but it appears that adds to the list are simply silently ignored. sample code: Account acc = [select ID, (select ID from Contacts ...
2
votes
2answers
1k views

How to build a Stackexchange-like search while typing in Salesforce

We have an internal defect tracker in Salesforce which should have much more of the charming features of Stackexchange. One feature that I love the most is the live-search for duplicates while ...
0
votes
2answers
1k views

Unexpected Null Pointer exception in testing

My Test Class is global class Feedpost9 { // your methods here... static testMethod void testRest() { // set up the request object System.RestContext.request = new RestRequest(); ...
1
vote
1answer
216 views

How is the presence or lack of managed package version data in APEX and VF meta files controlled?

From time to time I noticed that my meta files for Apex and Visualforce get changed to include specific references to managed packages version information as shown below. However, my classes don't ...
8
votes
4answers
2k views

Learning development with Force platform. Any good books?

I'm a bit familiar with Java and SQL, any good books to get on coding in Apex for salesforce?
4
votes
1answer
2k views

Weird issue with inner class not being covered via Test Class?

I have a test class that is basically covering a class which has structure like public class classA { public class classB implements Triggers.Handler { public void handle(){ ---...
2
votes
1answer
7k views

Call static method from the same class

What is the equivalent of this when calling a static method in Apex, besides the class name? For instance class A { public static void foo(){ this.bar(); //what to use here, instead of ...
0
votes
1answer
239 views

SOQL query produces different result with same input

In the process of writing a unit test on Opportunities, I'm inserting a custom object Journal_c. This custom object, Journal_c, has an after insert trigger associated with it. When running the test, I ...
2
votes
1answer
160 views

Required Picklist from Custom Object view

When you add an new field to an object in Salesforce.com, it is possible to check the "Required" checkbox to make it mandatory for every data insert/update. I know it is possible to make it required ...
0
votes
2answers
2k views

how to cover Id!=null part in test Class

public class democlass{ public string invoiceid{get;set;} PUBLIC DEMOCLASS(apexpages.standardcontroller controller){ invoiceid=apexpages.currentpage().getparameters().get('id'); **if(invoiceid!=...
-2
votes
1answer
770 views

Perfrom CRUD operation on salesforce database using web based java application [closed]

I want to create a web based java application that connects to Salesforce and need to perform CRUD operation on salesforce database. The java application will open as a web tab inside my salesforce ...
0
votes
1answer
670 views

Can you Help me understand what I have done wrong with this trigger?

The trigger should look at all contacts on an account and find the median NPS Score and update the field on the account called Median NPS score. trigger NPSScore on Contact (before insert) { for ...
2
votes
1answer
1k views

Rerun a Async Apex Job

When I get an error on some of my @future methods and would like to dynamically rerun the records that have failed at a later stage or have a list of records that failed and click rerun button to ...
4
votes
1answer
1k views

how to host attachments outside of salesforce

Does anyone have experience hosting attachments outside of salesforce? I have a customer portal that allows file uploads via an authenticated sites user and it could potentially be a large number of ...
5
votes
2answers
8k views

Forming SOAP header through apex class if the WSDL provided has no information regarding the header

<soapenv:Header> <wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:SOAP-ENV="SOAP-ENV"> <wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/...
2
votes
1answer
942 views

Chatter in test case behaves different from actual usage, why?

I'm doing something in a visualforce controller for every attachment and chatter contentpost that is related to a particular case. Hoping to open-source it (pending employer ok), but for now I'll just ...
17
votes
2answers
7k views

Convert HTML to PDF in APEX

I am trying to convert an HTML email that is sent to an Email Service into a PDF file. Some of the options I have explored: attachment.fileName = fileName + '.pdf'; attachment.mimeTypeSubType = '...
1
vote
1answer
195 views

Visualforce :- I am facing some trouble while rendering page

I have a page of my website.. In that page I have a registration forms and videos and some text... When I register in registration page and then come back to this page already registered, then ...
7
votes
2answers
552 views

Case sensitive highlighting of keywords

we have a rich text field in one of our objects that contains an html-document. I have created a search page and a user can click on a 'preview'-button which opens the html in a lightbox. I want to ...
1
vote
3answers
8k views

Disable custom button on detail page on some condition..?

I have custom button on standard detail page...I want to disable that button/gray out if my status picklist value is "Approved". Java script on button click var newRecords = []; var o = new sforce....
2
votes
1answer
277 views

Does API version matter when creating custom classes/triggers?

I noticed you can choose/change which version of the Salesforce.com API when you create a class or trigger. Are there are benefits to using a new or older version?
2
votes
1answer
7k views

How to get Case Id of current case when button is clicked on case page?

I made a class that assigns cases to the correct person's queue when they click a button. That button runs some javascript that executes a method in a global class. This button resides on the Case ...
1
vote
1answer
2k views

A new tab for a record Type!

Hello Folks, I have a question which might be more on the admin side of the force.com platform but involves development. Question: If I create record types for an object, how can I ...
25
votes
4answers
12k views

Using SOQL apex bind variables for date literals (e.g. LAST_N_DAYS, TODAY, THIS_QUARTER)

Is there anyway I can use a variable value for LAST_N_DAYS. For example, I am trying to do something like: Integer lastDays = 7; //... //... List<Opportunity> opportunities = [SELECT OwnerId, ...
3
votes
1answer
207 views

custom lookup filter using GeoLocation

Does anyone have any experience of creating a "roll your own" look-up filter? Essentially i'd like to be able to use the new geoLocation functions to restrict the options available to the user e.g. ...
6
votes
1answer
576 views

JSON serialize is not handling aggregate results properly in Spring 13

string testSerialize = JSON.serialize(database.query('SELECT COUNT(Id) custTot, Industry Indus from Account Group by Industry')); system.debug('test '+ testSerialize); Ran this query in ...
0
votes
1answer
2k views

Use an intermediary Custom Object in Trigger handler class

I have a rather simple Trigger. When fired it determines its own type and calls an appropriate function in Trigger handler class. trigger Project_Trigger on Acme_Project__c (before insert, after ...
4
votes
3answers
2k views

Is there an xml equivalent for the JSON formatting methods in apex?

Is there any method to take an xml string or a DOM.document object and get a nicely formatted string of the xml (like serializepretty does for JSON)? I'm fairly certain the answer is no but just ...
1
vote
3answers
900 views

actionSupport not rendering siblings

Here is my code the idea is when the user picks a value from the drop down i want to render siblings. I looked at http://wiki.developerforce.com/page/Visualforce_DynamicEditPage but i can't get mine ...
3
votes
1answer
2k views

What is the type of Trigger.oldMap?

I have a trigger with following code - trigger Project_Trigger on Project__c (before update) { PepsiProjectManager.projectBeforeUpdate(Trigger.oldMap, Trigger.new); } And a class with methods ...
4
votes
2answers
3k views

SerialBatchApexRangeChunkHandler : Too many email invocations : 11

I am working on sending mails to 50 clients at one go( basically at lead genration). I was able to send 11 mails until I used static body through SetHtmlBody() of my Batch class having Database ...
27
votes
2answers
9k views

How to check if any error has been added to a record?

I have created a method which is being called through a trigger. I am adding error to a record if it is a duplicate one using 'addError()' method . Now , I want to cover this method in my test class. ...
1
vote
3answers
2k views

CSS isn't being applied uniformly across browsers

SETUP: I have a page where I'm putting in a lot of fields. The output labels are being rendered on several lines Here, social security # is going onto 3 lines <apex:pageBlockSectionItem ...
11
votes
3answers
8k views

Convert UTF-8 to ASCII

How can I convert a text file or a String from UTF-8 format to ASCII? For example, the following string "ZÜRICH-ZOLLI" once outputted into a text file. If the file has the format UTF-8 is has 13 ...
2
votes
2answers
438 views

Check whether an object is in a standardsetcontroller

If I have a StandardSetController and an object ID, is there a way to check whether the object would be included in the StandardSetController, short of looping through all of its objects? Best ...