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
3
votes
1answer
696 views

How to prevent inconsistent data when using @future methods in triggers?

Due to certain governor limits in my trigger I refactored it to work asynchronously with @future: public with sharing class CustomObject_TriggerHandler { public static void afterInsert(Map<Id, ...
1
vote
1answer
89 views

Why does this code always produces a “Internal System Error: 1731640370-112053 (-1981348559)”?

To add Ids to a Set without looping over a list of SObjects I tried to do the following. In every org I tried it leads to this error: Set<Opportunity> myset = new Set<Opportunity>([SELECT ...
0
votes
1answer
265 views

How to pass the current item of a list to another method when using apex repeat?

First of all, apologies if the question is not clear, I didn't know how to phrase it. Basically, I am working on this recipe : http://developer.force.com/cookbook/recipe/creating-a-sitemap-for-a-...
1
vote
1answer
317 views

“Triggers should contain no real implementation code, only callouts to utility methods”: agree or disagree? [closed]

This idea is so frequently quoted that I wonder if sometimes it is being blindly followed without much thought. Here are some points in favor of triggers containing implementation code: Keeping the ...
1
vote
2answers
423 views

Need help with test code

I was given this test code on here, and I'm having some problems with it. UPDATE : This is the current code with the static fix for generateTestUser() public with sharing class ...
3
votes
3answers
2k views

Hiding home page components

Home page components get added to a homepage layout that are assigned per profile, now if I want to hide the component for specific users in the profile is it possible to do so ? eg: sysadmin has ...
5
votes
2answers
3k views

Change account ownership and its affect on related records

Does changing ownership of an account through apex automatically change ownership of related records like opportunity, contact etc? While making the change through UI, there is a text which says ...
1
vote
2answers
4k views

Call Apex REST service from JS on same org VF page - how to get instanceUrl and authToken?

I have an Apex class implementing a simple REST GET method @RestResource(urlMapping='/myrest/*') global class MyResService { @HttpGet global static CustomObject__c doGet() { .. } } ...
0
votes
1answer
562 views

System.ListException: List index out of bounds: 22

I am getting this error when my FOR loop goes to the next row (I am writing a CSV parser). All executes fine for the first row, then it get's to this line and crashes: ftoHeader = headers[colIndex]....
1
vote
1answer
189 views

get user's current page

How do i get the current SF URL that a user is on when they click a link? The issue is that I need to put a link in the left nav, do some stuff, and then send them back to the page. The way I'm ...
2
votes
2answers
1k views

Apex - Calling Class Fails After Altering PUBLIC statement in Class

(thanks to @JCD for helping me clean up my Class for Trigger.old vs .new checking...) My call to the class/function below now fails. I presume that now that my PUBLIC statement is looking for two ...
0
votes
1answer
14k views

Apex - Checking Trigger.OLD versus Trigger.NEW

(thanks to @JesseAltman for help with the initial code) I am trying to make sure this fires once each time the IF comes true (checking if the field was previously something different). I am doing ...
3
votes
1answer
3k views

How can I upsert multiple new records based on a multi-value field?

I'm a total newbie who is essentially trying to write his first trigger. Right now, I have a multi-value field in an object. I would like to create a new record for each value in that field. This ...
1
vote
1answer
263 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 ...
4
votes
1answer
167 views

'DataDotComEntitySetting' is not supported

I am writing a custom email service. I can get the incoming csv file and parse it down to rows and then columns. I do my thing, then I try to insert the objects (I know they are all original, the data ...
5
votes
1answer
17k views

Apex - Example Of Creating Case Record When Field On Account Equals “xxx”?

Continuing my quest to get Apex and Triggers under my belt: Can someone offer either sample code or links to samples where (such as) when Account.ABCD now equals "Go", create a Case Record and write ...
1
vote
1answer
277 views

Should the undelete via Apex behave the same way as Recycle bin undelete

Does the undelete via Apex behave the same way as Recycle bin undelete?
0
votes
1answer
316 views

Need to get the ids of Multiple items

<apex:pageblock > <Apex:pageblockButtons > <apex:commandButton value="Process" action="{!savetemp}" rerender="thebtn" immediate="true"> <apex:...
0
votes
1answer
218 views

PageBlockTable + Save is not working

My Vf Page is <apex:page standardController="Temporary_contact__c" extensions="tempView" > <apex:form > <apex:pageblock > <Apex:pageblockButtons > &...
4
votes
1answer
5k views

Get the content between the nearest Square Brackets in a string

In the following string, ['*.*string1*.*'],['*.*String2*.*'],['*.*String3*.*'],['*.*String4*.*],['*.*String5*.*] how can get the content including the brackets which are in String 4 using Regex ...
3
votes
2answers
1k views

SOQL query help using specific combinations of two variables that also appear in another object

I have two different custom objects. Each object is related to both an Account and a Campaign via a lookup field. So both objects have the following fields: sObject.Account__c sObject.Campaign__c So ...
7
votes
1answer
2k views

What is max and min range for double.valueOf()?

what is max and min range for double.valueOf() in apex.
1
vote
1answer
32k views

How to Solve the List index out of bounds: 0 issue [duplicate]

How can I solve the List index out of bounds: 0 issue . ID Accid; Account[] acc = [Select id,name from account where name ='test']; -->1 if(acc.size() >0){ Accid = acc[0].id; }...
9
votes
2answers
6k views

How to invoke a method of an apex class at run time

We have a usecase where we need to invoke an instance of a class and invoke a method at run time using string. I know with reflection i can instantiate a class. But how do we invoke a method of a ...
2
votes
2answers
2k views

Why is this query producing a “List has no rows for assignment to SObject” error? [duplicate]

I'm attempting to put this into a VF page which will be the New page for an object. The code is supposed to run this query based upon the value of a field, but I'm getting this error when trying to ...
1
vote
3answers
239 views

Optimized way to update parent object

What is the most optimized way to update every parent object inside a list? For example: List<Asset> aList = [ SELECT Account.Name FROM Asset WHERE ...
1
vote
1answer
23 views

Update a bunch of relationships

I have two entities CustomA and CustomB and a look up relationship from CustomA to CustomB. I have a bunch of CustomA entities and want them all to point to the same CustomB object. So it is like: ...
0
votes
2answers
3k views

How to get a VF page to save and then close

I'm not trying to do anything really fancy. I just want a save button in a VF page with an extension to close the document after saving it. It doesn't necessarily have to go to a specific page. I ...
-4
votes
1answer
918 views

how to write soql query to fetch records <=1000 etc

Hai iam new to salesforce i need to write the query depending on the values entered by the user i.e, when a user enters the value 10,000 i need to display the all the record values <=10,000. how ...
4
votes
1answer
1k views

Ensuring Test Code Coverage when you have Insufficient Access Rights on an Object

I recently ran into an issue where we installed some Service Cloud pieces in our predominantly Sales Cloud org (including the Public Knowledge Base). This installed a few custom APEX classes and tests....
6
votes
3answers
5k views

Update custom object after insert trigger

I have created a trigger for a custom object for the event "After Insert" only. When running the test for this trigger the test fails with the following error: System.DmlException: Insert failed. ...
3
votes
1answer
1k views

Why does this batch method fail every time?

I am writing a batch method for a client that just updates a couple of field based on the date. I used this example as a guide. Here's my code: global class BatchUpdateFiscalMonth implements ...
1
vote
1answer
1k views

Organizational Chart in VF page

I am trying to make an org chart in VF page using google analytics, it working all well but facing a logical issue. There are some 50 child accounts to the parent and in org chart all the child ...
11
votes
2answers
8k views

Rolling back DML operation in Apex method

What is the best way to rollback some changes to the database inside an Apex method? For example, in an Apex method, I insert multiple records (Opportunity / Quote / QuoteLineItems). When I execute ...
9
votes
1answer
3k views

Custom icons in tabs?

I need to add custom icons in my tab. Suppose for home tab i need to include home image. Can we include custom icons in tabs that will be included in Packages?
2
votes
2answers
900 views

I just want the IDs? [duplicate]

I want to get the IDs for all tasks... I try: List<String> ids = [SELECT ID FROM Task]; But that's give an illegal assignment error. I can't just assign from Tasks to Strings. So what is the ...
2
votes
3answers
3k views

Returning PageReferences from Init - Not working in sandbox

So either I'm going nuts, or I'm overlooking something obvious, or I'm just encountering some very weird behaviour. The Setup I have a page which calls an Init action in the controller from the page ...
5
votes
1answer
2k views

Why does the url not change on my visual force page

I am experiencing an odd behavior on my visual force pages and i would like to know if others have experienced this. I have a multistep wizard where several visual force pages use one controller. On ...
6
votes
1answer
2k views

Node.js App takes 4-5 seconds to get response from Salesforce

I have a node.js canvas app that queries salesforce for accounts and there are only 10 of them , but for some reason it takes about 4-5 seconds before the response comes back. I have used both nforce ...
0
votes
3answers
1k views

Using a variable in dynamic sql [duplicate]

I have a set of IDs I wanted excluded from a Task query. I need to use dynamic sql for this. I try: Set <ID> unwantedIds = ... // ids I don't want. String query = 'select Id, ThirdPartyId__c, ...
3
votes
2answers
16k views

apex program to create and download a file

So I'm trying to find a way to download a report from salesforce programmatically, to a local machine. so, I've found the XMLStreamWriter class, and am writing the XML just fine... I'm just wondering ...
4
votes
1answer
7k views

How can I pass a List of Ids as a parameter using an ActionFunction?

Here's what I have so far. Controller public Id[] SelectedIds {get;set;} public void TestAction() { system.debug(SelectedIds); } Page <apex:outputpanel id="r"></apex:outputpanel> &...
2
votes
1answer
506 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 ...
3
votes
1answer
500 views

Determine via Apex if product schedules are enabled for an Org

For a given Organization, how can I determine if it has the Product Schedule feature enabled without adding a dependency on that feature to a managed package? In the UI under App Setup > Customize > ...
7
votes
1answer
3k views

Salesforce timezone issue

Hi guys we have a problem with DST (Daylight Saving time) We show the time in a Visual Force interface according to the time zone of the logged in user. However in the Salesforce objects we are ...
0
votes
1answer
2k views

How to get day from Datetime field [duplicate]

I want to extract my datetime value into different. I want to get day from the datetime value. eg: if datetime value is 2012/02/03 10:12:02 Tue. I want Tue from datetime. Is this possible.
8
votes
2answers
2k views

Force a Unit Test to run immediately inside Salesforce Web UI?

Is there a way to force a unit test to run immediately? You used to be able to go to App Setup > Developer > Apex Classes > [ClassName] > Run Test button. This used to begin processing a unit test ...
8
votes
2answers
8k views

How should I properly format a Date within an SObject parameter to a RemoteAction method?

I'm having trouble sending Date values from the client with remoted methods. If my RemoteAction method takes a plain Date value, everything works fine with the suggestion of using "toUTCString" which ...
5
votes
1answer
2k views

Access the Related List Label for a Lookup relationship

I've searched high and low, and I can't seem to figure out the Apex syntax I need to use to access the Related List Label for a Lookup relationship. It shows up in the objectTranslation XML as ...
7
votes
1answer
2k views

Adding a without sharing extension to a Visualforce pageBlock section

I am currently using VisualForce to display a table at the top of one of my forms. It is displaying data to users who do not have access to the object which it is displaying so it is therefore ...

1
637 638
639
640 641
649