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.

learn more… | top users | synonyms (1)

0
votes
0answers
3 views

Logging batches?

I have a scheduled batch class which runs repeatedly over some groups of accounts. In the finish-method I start the next batch if some condition is true. Simplified code: global void finish(Database....
0
votes
1answer
11 views

Show error message in Visualforce Page

I have a visualforce page with custom controller. I have added apex:pagemessages in a helper static class and for some reason the messages are not displaying on my Visualforce page and I'm not sure if ...
0
votes
1answer
13 views

Datetime Format Method not working as desired

I came across a weird scenario. The format method is replacing month with '00' in its result. A portion of my code: (Executed Anonymously to test) System.Debug(logginglevel.error,'****m....
0
votes
1answer
10 views

Call rerender in middle of call-stack to navigate to new record on create

So I have a controller which creates a record and an ID is set on create. I have a controller reference that works after the stack is complete but not in the middle: example that works: 1) button ...
0
votes
1answer
15 views

Passing Select Option value

I have the following drop down, and I want to send the value of the selected file to my controller .. so if the user selects parent account1 my controller should get that value or if they select ...
1
vote
1answer
15 views

Trailhead Apex Super Badge JSON Parsing

Working on the Trailhead Apex Super Badge.... There is a section that requires writing a rest callout that returns a chunk of JSON that you are to use to update Product2 records with. Reduced Chunk ...
0
votes
1answer
15 views

Updating controller reference variable for access via Javascript

I have a controller which creates a record (and consequently an ID). After the record is created, variables are set. However, when I attempt to access the variable after the controller action has ...
7
votes
0answers
22 views

getPopulatedFieldsAsMap() Doesn't Return All Fields: Bug or Expected Behavior?

I was very excited to learn about the new getPopulatedFieldsAsMap() method added to the SObject class with Summer '16. Unfortunately upon testing I found what appears to be a bug based on my ...
0
votes
1answer
9 views

Is there an easy way to sync the Default Account Team of an User to all accounts he owns by APEX?

I'm trying to keep the Account Team defined on a user (UserAccountTeamMember) in-sync to all the account this user owns (AccountTeamMember). It starts usually in-sync when a user creates a new ...
0
votes
1answer
17 views

Deleteing multiple SObjects in batch apex

I have the following code that executes exactly how I need it to, the only issue is I receive "Apex CPU time limit exceeded" when I run the delete on Accounts, EmailMessage and update Cases. After ...
0
votes
1answer
12 views

can we provide access to user access from any IP ranges through permission set

Hi friends I stuck in a place called. I have a profile with 10 members are assigned.And we set up some Login IP ranges for this profile. My requirement is i have to give access for one user in the ...
0
votes
1answer
27 views

How to send email with records before modified and after modified?

From below code i am going to send an email with modified records. But i need to send an email with both old values and new values. Here is my code: public static void onAfterUpdate_updatedAnswers(...
2
votes
2answers
60 views

Put value of a field other than ID from list to set

Below trick works for only ID field, but if I need a field other than ID field? List<SObject> results = Database.query(someSOQL); Set<Id> resultIds = (new Map<Id,SObject>(results))....
2
votes
1answer
31 views

Apex Trigger to create Opportunity Contact Role based on Contact Lookup field

I have created the following Apex trigger that will create, update and delete Opportunity Contact Roles based on a Contact Lookup field placed on the Opportunity. Everything works great currently. I ...
0
votes
0answers
15 views

Send email using template to queuemembers

I need to send an email to queuemembers using emailtemplate retrieve from queue in apex .currently i am using body in apex for(User u:[SELECT Email FROM User WHERE Id IN (SELECT UserOrGroupId FROM ...
0
votes
1answer
17 views

Salesforce formula field - get current date as percentage of overall timeline

I have the following fields on my object: startDate__c and endDate__c. The length of time between these 2 dates is equal to 100% of the overall timeline. In a formula field, how can I get today's ...
3
votes
2answers
44 views

Product2id is not writeable Any work around for that

I am trying to clone an opportunityLineItem but I am getting an error : Field is not writeable: OpportunityLineItem.Product2Id public class OppLineItem { public OpportunityLineItem ...
0
votes
1answer
25 views

How do we pass record's page as a link in apex class?

I have one apex class somehow i need to populate a link. That link should be open records detail page. This is what i've given in Email Templete. Whenever i send a mail through this Templete i can ...
0
votes
1answer
26 views

Comparing values using maps

There is One Account to Many Opportunities. There is Amount field in Opportunity. I am trying to find Opportunity with Minimum Amount against Account Id. I need a map like this Map<Accid,...
0
votes
0answers
11 views

How to create a table of data in Heroku and fetch it from Apex

I am new to Heroku. I installed Heroku and the sample order application. I am able to make a call from Apex class and get data from the application. However is it possible to just create a table with ...
0
votes
1answer
17 views

How can we divide lines in emails

I am going to send an email with with few records. I need to divide each record data for each record. I think some html tags can be help but i am not able use. Can any one help me? Here is my email ...
0
votes
1answer
17 views

How to check richtextbox is empty in salesforce?

Whenever we have display record on vf page , when we have decided record cannot display when richtextbox is empty. I am using apex class.
0
votes
1answer
24 views

Need help with bulkifying code [on hold]

global with sharing class LOYMemberServcies { public Map<Membership_card__C,Member__c> postMemberEnrollmentActivities(Map<String,Member__C> newMem) { //Get the base tier system....
1
vote
2answers
13 views

Use DAteTime.parse to parse date which is NOT based on my locale

I need to parse date which come from service and is not at my time zone template. For example : '12/12/1990 2:08:24 AM'. Given that code : DateTime.parse('27/06/2016 09:07 AM') Got this error : ...
0
votes
0answers
19 views

Trigger to Pull related contact's details on Task page when new task creates

I have a requirement. Contact related to Task, I need to pull his functional role (custom field) on Task page layout. So whenever I create or edit a Task and relate with any contact so his/her ...
2
votes
1answer
22 views

Create a record from Visualforce Page

I have a custom object with 5 Questions and field Api Names are Q1__c, Q2__c, Q3__c, Q4__c, Q5__c Requirement : This is a Question answer from with question having more than 40 characters so i am ...
1
vote
1answer
31 views

How to check the map key value with field value?

I am trying to write condition in the class if " field1__c is not equal to map1 key value and field2__c is not equal to map1 key value " then it should throw an error. After assigning when I checked ...
1
vote
1answer
20 views

Inactive Trigger Test Code Question for potential solution

I was reading this: Are inactive triggers counted against test coverage? And I had an idea pop into my head: Can I cover several apex triggers, using a single test function, if they all contain the ...
0
votes
1answer
13 views

Can we create List controller for CampaignMember

When i try to create a List Controller, i get the "List controllers are not supported for CampaignMember" error. Does SFDC does not allow to create List Controller for Campaign Members
0
votes
0answers
24 views

Running Tests in Production WHILE Deploying to Production - Row Lock Error

In our test classes, we utilize testSetup methods that create and insert records in preparation for their use in the test methods of the class. I found today that if I'm running tests in Production ...
0
votes
1answer
17 views

Keep records in master Set with no Ids

I'm using a master Set to keep all created records and to remove duplicates before insertion. The problem is that once the record gets inserted, it gets Id assigned to it and records in master Set get ...
1
vote
2answers
30 views

Send email to queue members using apex

I need to send email to queue members of queue on update case record based on some conditions. There are multiple queues and on case there is one field based on that I need to send email... How can I ...
3
votes
2answers
57 views

SOQL to retrieve all contacts for an Account (related and direct)

I have an account with 4 contacts, two are direct and two are indirect contacts. I'm trying to retrieve all 4 contacts in an SOQL query but can't seem to get it to work . For example if I run this ...
1
vote
1answer
43 views

Bind Data to Lightning Design System in a Visualforce Page

How can I bind data to controls built in the lightning design system within visualforce. It seems that it's more HTML/CSS based vs apex:control based. Changing my question to refine and make more ...
3
votes
1answer
19 views

Getting Streaming (or alternative) to work for customer community user profiles

We want to enable PushTopics for customer community users. I see here that it was not possible. I also see that the external user licenses (customer and partner community) do not have access to the ...
2
votes
3answers
31 views

Trigger to update the owner of child record to the owner of parent record (look up relationship)

I have a custom object called "Recurring Storage Revenue". This object is populated via integration so the owner of the revenue records is the system user. I need to build a trigger so that the owner ...
0
votes
1answer
22 views

Prevent task deletion by anyone other than task creator

I need to create a trigger that will prevent the deletion of a task by anyone other than the creator. I don't know about writing code so I'm hoping someone can help me out with this. It would be an ...
0
votes
1answer
23 views

How to add map value to the object field?

I am inserting records using excel file on VF page. So based on the values I want to map the product names while inserting. I am trying the below code it is inserting all (I want to insert record if ...
0
votes
0answers
13 views

Send mail to Queue members using Apex [on hold]

I have multiple Queues and I need to send emails to specific queuemembers on update of case based on some conditions. I am not updating Case Owner,Only need to send mail to queue members. Please ...
-3
votes
1answer
26 views

How can we run a class [on hold]

I have one class that is sending emails to users. That class needs to execute after update a records. But the i am not receiving emails. Now i need check debugs of that class.
1
vote
1answer
19 views

Create chatter post with mention for API version 37.0

I want to create chatter post with mention for API version 37.0 Have a look over this link Chatter Api Saying Feed item methods aren’t available in version 32.0. In version 32.0 and later, use ...
0
votes
2answers
27 views

Need to increase code covergae [on hold]

I have 61% coverage i need to increase saveAccount() method. public with sharing class AccountCustomLookupCntrl { public Account account {get;set;} // new account to create public List<...
0
votes
0answers
3 views

Contact Related Object list buttons not displaying on opportunity,Cases in Lightning Experience [on hold]

Contact Related Object list buttons not displaying on opportunity,Cases in Lightning Experience. Can you please guide me .....
0
votes
1answer
16 views

Createdby cannot reference custom field?

I am struggling with the createdby reference and hope someone could help me out. I have a custom object and as everyone knows there is a standard createdbyId created on every custom object. We can use ...
-1
votes
0answers
19 views

Summer'16 - Slow asynchronous transactions are experienced

After the summer'16 update I am experiencing very slow asynchronous call. The code remains the same and was working perfectly fine. But after update the asynchronous call is taking more time then the ...
0
votes
2answers
26 views

Pre-Populating text field based on picklist

Very new to SalesForce so apologies if this is a basic question! I'm using the Case object and have a custom field - "Case Sub-Type" which is a picklist. I also have a custom long-text field - "...
-1
votes
0answers
13 views

Apex Sending email to Distribution list [on hold]

I have requirement that i need to send an email to Distribution List, i am using contact email of distribution list in toaddress method, it is not giving any error perhaps Distribution list of users ...