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
6
votes
2answers
5k views

Case Assignment Rule workaround

Background I have an org where there are account teams. An account has a lookup field to a user that is the Customer Advocate for that account. I have triggers that add/edit/delete account team ...
3
votes
1answer
2k views

Related Custom List With Order and Inline Editing - Many to Many relationship and Junction Object

We are using three objects in this project: Contact (for authors), Paper, and junction object PaperAuthor. Paper holds all all attributes to describe an academic paper. Paper can have many Authors. ...
116
votes
1answer
6k views

Any reason to skip DML on empty lists?

In parts of my code I have DML statements with an if around to only do the DML if the list is not empty: if( !recordsToUpdate.isEmpty() ) { update recordsToUpdate; } Couldn't I just write? ...
2
votes
2answers
426 views

Salesforce as a Data Source

I'm completely new to salesforce platform. I'm yet to explore most of the features salesforce does have. Here, I'm trying to develop a mobile application which can display articles created over the ...
3
votes
1answer
4k views

How can I create a new Account any time an “orphaned” Contact is created?

I am trying to create a new Account any time a new Contact is created (where the Contact does not have an Account assigned to it) and assign the Contact to the Account via the standard Contact->...
3
votes
1answer
529 views

Embedded Visualforce Page causing custom buttons to render beneath it and cut off the page

I have some very strange behavior on a newly created Visualforce Page that is embedded in a standard layout. Custom buttons for that page will appear directly beneath it and the Related Lists will ...
4
votes
1answer
112 views

New Lead custom fields deployed, but not available when adding a new lead

I just deployed a flow that depends on new custom fields I created for Leads, The deployment was successful, And I can see the new fields in Leads and the new Page layout in Leads, But when I try ...
8
votes
2answers
2k views

Query parameter checking for related list size

Is it possible to check for a the size of a related list in a SOQL query? I am trying to find all Accounts that have no Contacts over the default Contact->Account Lookup.
6
votes
2answers
7k views

Difficulty Parsing XML

I am having difficulty parsing the XML returned from a webservice callout. In the past, I've always been able to use XMLstreamreader, but it does not seem to work with formatting of the XML from this ...
4
votes
1answer
1k views

Any way to determine HTTP verb (GET, POST, PUT, DELETE) in Apex controller?

I need to create a REST (or REST-like) API for my SF application. After reading https://salesforce.stackexchange.com/a/19058/3382, my thought was to simply use the @RestResource annotated classes ...
5
votes
1answer
373 views

How to intercept/hook into oauth flow

After a user authenticaes in our Org using the SSO oauth flow, and after the access token is created, we would like to hook into that flow to get that access token and set a couple of cookies. Is ...
4
votes
2answers
2k views

JSON.deserialize is not working as expected

I am passing a json string to this class. Then I try this: Account jsonRes = (Account) JSON.deserialize(jsonString, Account.class); I get this error: Error: Compile Error: Method does not exist ...
15
votes
3answers
2k views

3rd Party Code Coverage is below 75%, is this bad? What to do?

We have a bunch of installed apps which are just killing our code coverage. We're now down to only 77%, and all of the classes which are below 75% are from installed apps. Has anybody else had this ...
5
votes
1answer
4k views

Adding script includes with an apex:component?

I'm looking to call my scripts though an apex:component. So instead of having 3 includes on my page, I want <c:scripts /> and the 'scripts' component will contain the following. <apex:...
2
votes
1answer
2k views

Display a list, make an edit and then save

it sounds so simple, get a list of similar items and allow the user to edit one field, then click save and return to where you came from. I just do not understand enough to make this happen, can some ...
1
vote
1answer
2k views

test case for this deletion trigger

trigger deletecontact on Contact (before delete) { string uid=userinfo.getuserId(); for(contact c: trigger.old) If(c.CreatedById != uid ) { c.addError('This contact ...
1
vote
1answer
244 views

Apex record owner able to delete the record

VF PAGE: <apex:page standardController="Contact" extensions="deletecontact"> <apex:form > <apex:pageBlock > <m>Please make sure that you have removed links to this contact's ...
3
votes
1answer
447 views

Which server instance processes @future email sending? And can it be changed?

I've written up a process to send Email's with PDF attachments through Visualforce Email templates and Visualforce Components. Within the Visual Force component, it escapes and renders out a Rich Text ...
3
votes
1answer
3k views

Get/Set not getting triggered for Attribute in Custom Component

I have an attribute within a custom component, but it doesn't appear to be calling any get/set methods regardless of how I format either the attribute (specifying assignTo) or writing the get/set code ...
2
votes
1answer
873 views

A Wrapper's LIST<AnotherWrapperClass> isn't setting

I have a VF controller (similar to the following) with two types of classes: Outer Wrapper Class benefitSection - to hold section data Inner Wrapper Class benefitChoice - to hold Line Item data ...
1
vote
1answer
197 views

Resources to learn APEX

I am starting on with Salesforce, and having trouble finding good resources for learning APEX especially with some practice exercises. Any help is appreciated. Thanks.
6
votes
2answers
4k views

Custom Related List with Custom Object

I am quite new to Salesforce and have not yet any thing like the following. We have a Paper object which is looking up for authors in Contact object. We want to create to have custom related list of ...
3
votes
2answers
2k views

How to Get App Name

Is it possible to get an App's name (not just the label) in Apex? I looked into DescribeTabs() but that doesn't seem to give me the name.
12
votes
1answer
17k views

SObject row was retrieved via SOQL without querying the requested field:

I am getting this error with the code below. I've looked into the other cases on here. In my case I am referring to a relationship name (__r) which I am assuming is pulling correctly. It's a field ...
3
votes
1answer
1k views

Visibility of pageblocksection on visualforce page based on profile and status of record

I need to control the visibility of multiple pageblocksections based on user's profile and status of the record.Currently I am using rendered attribute on pageblocksection and adding conditions like ...
3
votes
2answers
469 views

Unable to a build an apex query string

I have a string where object names are enclosed in <>. Something like this-> String source = 'I have <name> and <id>'; Object name is stored in another String -> ...
6
votes
2answers
1k views

Create google drive file as attachment in salesforce

i am trying create a attchment in salesforce by fetching the content of a file from google drive. The file is a zip file stored in google drive. The contents are fetched and the attachment gets ...
3
votes
1answer
113 views

Is it possible to add questions in Tasks?

I have a requirement from my client saying that, set of questions should be populated in Task based on some criteria given by the customer. For example On creating a Task for an Account, then the ...
13
votes
1answer
15k views

How do I access the fields of a custom object with a standard controller?

I have a custom object called "Shows." I'm writing a VisualForce page to display some custom data. My code is: <apex:page standardController="Show__c"> <apex:pageBlock id="thePageBlock"...
3
votes
1answer
1k views

Transaction governor Limit reset

I have a simple Apex Class, method execute() which reads every 5000 (Queries everytime for next 5000 leads) leads and applies business rules and update 200 at a time. but we have triggers on the Lead ...
3
votes
1answer
347 views

Users able to circumvent sharing for custom object on visualforce page

We have an object which has private sharing settings. There are no sharing rules on the custom object. But if the user(not owner of the record) knows the Id and paste it in the browser ..he is able to ...
8
votes
1answer
6k views

Picklist value translation

I have am email body I'm generating in APEX and I want it to include the translated value of a picklist. How can I get the translated value in APEX?
30
votes
3answers
37k views

Use Set<Id> in dynamic SOQL IN-clause in method without Database.query()

I know and love that Apex is automatically converting Set to a valid SOQL string when it is used referenced like Set<Id> ids = ... String soql = 'SELECT ... WHERE Id IN :ids'; and passed to a ...
8
votes
1answer
1k views

Report object in Apex

I'm trying to query the report object and put it in the list for later computation. But i'm not able to assign it to the list. But if i use query editor in "Dev Console" then it'll fetch results. ( ...
7
votes
1answer
8k views

Getting current PageReference from Controller Extension in @future context

I'm attempting to get current pageReference for a VisualForce page (renderAs=pdf) that is being executed in @future context, but at the moment it is just returning a null. So I assume the problem is ...
8
votes
1answer
2k views

Catch Invalid QueryLocator exception

Salesforce QueryLocators have a number of restrictions, including that a user can only have 50 active at a time, and that they time out after about 15 minutes of inactivity. I'm trying to debug some ...
4
votes
2answers
3k views

How to reduce view state [duplicate]

I have implemented custom search and displaying 10000 records on page using pagination. Pagination is done by using StandardSetController only. I also have implemented sorting of data. Can anybody ...
14
votes
3answers
6k views

Can I throw an exception in apex and still log the caught exception?

I'm really wrestling with the best error handling strategy. My goal is to handle all exceptions that I can identify, log them to a table in the database, and surface a helpful message about what ...
12
votes
2answers
4k views

Execute an Apex class using Ant build script

We are in the process of setting up automatic build using Ant. We want to do some start up activities like read an xml file which is stored as a static resource and verify it with a custom object data ...
10
votes
2answers
1k views

Unable to deploy code to Sandbox as installed Managed Package test methods are failing

I am using ant tool to deploy code to Sandbox which has Managed package test methods failures. Build error shows the validation rule message. Build is executed by Jenkins schedule job, so turning on ...
2
votes
3answers
3k views

Accessing Salesforce Apex Class from External java Application

I have a java application which needs to access the Apex Class methods. So, I create a global Apex Class with WebService methods and created a WSDL for this class, and included this in my Java ...
3
votes
2answers
1k views

How to render pdf attachment in to html?

I have requirement to get all attachments of a Lead which are generally in pdfs, and merge them in to one single pdf document. I have tried below code. str=''; List<Attachment> atts=[select id,...
7
votes
3answers
3k views

How to access SQL, Oracle and Access databases from within Salesforce?

A lot my clients use different databases for different applications e.g. Sage Line 50, QuickBooks, Legacy database apps, etc. I have developed several utility apps that synchronizes data from those ...
2
votes
1answer
1k views

How to add a hyperlink to the body of a feeditem with apex code

I want to add a hyperlink to the body of a feeditem with apex code. I tried to with class of EncodingUtil.urlEncode but it is not work. So I`d like to know how shall I do. Thx!
-3
votes
2answers
525 views

UpdateOnStatusChange: execution of AfterUpdate caused by: System.StringException: Error

Trigger to insert record into another object based on criteria Code trigger UpdateOnStatusChange on Object1__c (after update) { List<Object2__c> ListOfIds = new List<Object2__c>(); for(...
3
votes
2answers
660 views

Why is CommandLink breaking Twitter Bootstrap styling?

Having some issues rewriting Twitter Bootstrap components in Apex. I had an issue with an img tag referencing a static resource but overcame that. Now I want to add an Apex action to a button. I ...
4
votes
1answer
3k views

Where are the Case/Contact/Opportunity access level stored for Account Team Members and how can I set them with APEX?

When adding a user to an account team you can set four separate access levels for accounts, cases, contacts, and opportunities. However, the AccountTeamMember object only has a field for ...
3
votes
2answers
4k views

Display all error messages

Visualforce page is displaying one error message at a time not all error messages if validation is failed for all fields.Below is my code in the controller.I have apex:pagemessages in visualforce page ...
5
votes
1answer
213 views

Expose features of portal application via api?

We have built a complex application and expose it using the high volume portal licenses. The users of this app have restricted access to our salesforce data, this is controlled by the application. We ...
4
votes
1answer
1k views

Auto Save in Visualforce page isn't getting data and failing validation rules while immediate = true is on

I have a visualforce page which needs to be auto saved.Currently have two issues with my page. I have some validation rule on some of the fields in visualforce page.I have set the validation rule not ...

1
554 555
556
557 558
596