Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-1
votes
0answers
4 views

Auto populate Contact and account on Case record in salesforce

Auto-populate Contact lookup and account lookup fields on Case record in salesforce, when record created through Email-to-Case functionality.
0
votes
1answer
14 views

Trigger.New value to compare with all records

I has objects Contracts__c with fields(Start_Date__c and End__Date__c) and related obj Actor__c. When i insert new contract i trying to check does the actor already has a contract on specified dates. ...
-2
votes
0answers
15 views

Need Help in Writing Unit Test Class

//Could any of you kindly help me with the test class of below Class global class LicenseBasedRouting{ public static ServiceChannel channel; @InvocableMethod public static void ...
0
votes
2answers
22 views

Get first index and last index for each ID

I want to calculate the user online time, from the API response, by taking the first and last login time.. I tried to parse the JSON and store it in array of strings.. Theres UserID, Start Time, End ...
0
votes
1answer
23 views

Methods defined as TestMethod do not support Web service callouts - Unit Test

We have a custom object called 'support' - we have process builder configured for this object. in one of the process builder action it will invoke Apex (Invocable Method). This will trigger a callout ...
1
vote
0answers
20 views

Getting field names from QueryResult when child records are empty - How does Workbench do it?

I'm querying via the REST API (in Apex, because I'm calling another org, amongst other reasons) and using a wacky recursive algorithm on the first returned record to parse out the field names. And no, ...
0
votes
1answer
33 views

Insert Array of strings to object

I want to upsert some record, and the data stored in array of strings.. for example, the array below has 2 ID, which mean there`s only 2 data that will be updated.. how do I loop the array, so I can ...
0
votes
1answer
29 views

I'm new to VF and apex. Trying to create a custom clone functionality.

Unable to pass contact from VF to the controller. I have to check if the contact is inactive on VF page if it inactive, allow user to change the contact and pass the changes to the controller. If ...
1
vote
1answer
26 views

Parsing Using JSON2Apex

Im trying to use the JSON2Apex to get the parsing class for my API response.. I only need the metrics data for each userId, but I cant get the variable and the system always giving error Variable ...
1
vote
1answer
33 views

Iterate over a few objects in a single loop?

I have a few objects that have the same fields (referring to Article Types) such as: FAQ__kav, Tutorial__kav, Video__Kav Is it possible to add all of these records to a single list (I guess of type ...
0
votes
0answers
15 views

Unable to create a Community User following an insert to Person Account

The following code is how I create a record into Person Account then create a Community User : @HttpPost global static void createAccount (String lName, String fName, String email) { RestResponse ...
0
votes
1answer
13 views

How to access transient variable value in apex which inputted from vf page?

I have VF page with Standard Controller and extension. I have declared one variable as transient with getter and setter. VF page has input tag where I am allowing user to input transient varible value....
0
votes
1answer
25 views

Possible to calculate number of days between when records are created?

Is it possible to calculate how many days has passed since the last record has been created? For example, shipments are children to Contacts. We want to calculate how many days has passed since the ...
-1
votes
1answer
20 views

Test Class/Method for TriggerHandler - Negative scenario

For this class below, which essentially counts the number of Open cases on an Account, on update/insert/delete of a Case, can anyone help me write/provide a scenario of a test method that can hit the ...
4
votes
1answer
23 views

How to avoid duplication when using Apex Dropbox API Framework or any other Frameworks/SDKs?

BACKGROUND I need to implement an integration with Dropbox using its REST APIs. I don't want to reinvent the wheel so I decided to use Apex Dropbox API Framework. Although it's a bit outdated (it ...
0
votes
2answers
43 views

Learn Parsing JSON

Im trying to get values from API request.. there`s 2 user data from the response and I want to get the data of each user and put it on the list.. but my code only store the last user data from the ...
-2
votes
1answer
29 views

how to allow in to if loop if deciamal value is (1,0,2,0 etc)

I have one requirement I have two values week(formula with decimal place 0) and Frequency( decimal with place 0), my requirement is that whenever the Week/ frequency is calculated, if the output is (1....
0
votes
2answers
25 views

System.QueryException: expecting a colon, found New

String emailBlastQuery = 'SELECT Id, Inquiry_Type__c, Product_type__c, Solution__c, Reason_For_Calling__c, '+ 'Problem_Category__c, Duplicate_Case_Problem_Category__c,...
0
votes
1answer
19 views

deploying destructive changes

i'm deploying a destructive change (includes apex classes) into a production environment and it kick starts running all tests. This didn't happen when doing it on the sandbox environments. Any way I ...
0
votes
2answers
35 views

Json parsing in rest service apex

I want to know how Apex parse rest post data.. Like in the following example: // Apex code for Post service @HttpPost global static String doPost(String n,String site, String name) { Account ...
0
votes
0answers
12 views

Redirect to edit mode from Visualforce at Lightning Experience

I created a button that opens a Visualforce (this page runs only at Lightning and Salesforce app) whit a form to do some validations. The button Close task runs an Action and OnComplete function: <...
0
votes
1answer
33 views

Visualforce: Pass checked checkbox items to Apex list?

I have a table with one of the columns being a checkbox. I want to be able to pass all the checked items values into a list in another apex controller. VFP <apex:repeat value="{!data}" var="...
0
votes
2answers
25 views

Retrieve Page Layout using Metadata.Operations.retrieve

I have seen the answer to this post: Retrieving Packaged Page Layout in Apex I am using the same code with my values substituted: List<String> componentNameList = new List<String>{'...
0
votes
0answers
10 views

Custom Report Filter logic in VF page

I have created VF page that get data from report and bind in VF page. There is also filter functionality implemented for this custom reoport. Now I have requirement to add Report Filter Logic like we ...
5
votes
0answers
41 views
+100

Cannot subscribe to platform events using cometd

I am trying to subscribe to a platform event using cometd. I have asserted that the event is getting published just fine but its subscribing that is an issue. I have placed console logs in the cometd....
0
votes
1answer
19 views

Button to open a different visual force page opens a blank / broken page

I have a visual force page and a button called that is supposed to take the user to another visual force page. A problem however is this page is completely blank or just isn't loading it seems. ...
1
vote
1answer
22 views

How to call a web service with base85 encoded data?

I need to make a call to a 3rd party SOAP web service from Apex that accepts images encoded in base85 rather than the more standard base64. I don't see that this is supported in Salesforce, any ideas ...
1
vote
1answer
30 views

Can we avoid 'Attempted to schedule too many concurrent batch jobs in this org' error using Apex flex queue?

We have a batch class AccountDeactivationBatch from whose finish() method we run 3 more batches, including AccountDeactivationBatch again, but with new set of Ids. These new set of Ids are all ...
4
votes
1answer
64 views

cant use Apex bind-variable (String) to filter by recordId in SOQL

I have a Lightning Component controller doing the following: inserting a custom object Audit__c record via LightningDataService. on successful insert calls a server-side controller method, passing ...
0
votes
2answers
19 views

How do I query an AccountContactRelation object based on its AccountId and Contact Id and assign it to a variable?

I need to update a field value on an AccountContactRelation record in an Apex class, so I need to get a reference to the record that gets created based on the Account and Contact I just created. So I'...
1
vote
2answers
26 views

Problem with Regex/Pattern/Matcher

I'm trying to implement the ideas in this post in my org. However, the provided regex seems to never match anything in any email I throw at it. The simplest possible test case I can muster is: ...
3
votes
3answers
434 views

Help With A Null Pointer Exception

I am hoping that someone can teach me a little about how to work through this null pointer error. The class is called from a trigger handler on After Update because I need access to all ID fields. The ...
0
votes
1answer
31 views

Not map a field when a value is null

I have a helper class that upserts custom object records based off the Opportunitylineitem. In October we switched a lot of logic around and are using new picklist/lookups and we did not update ...
0
votes
1answer
22 views

Testing Error System seems to not recognize test class

ERROR: Unable to run tests synchronously: [This class name's value is invalid: Opportunity_EmailServiceTest. Provide the name of an Apex class that has test methods.]. @isTest private class ...
0
votes
2answers
14 views

Authenticate Docusign API using APEX

We have been working on org where there's a one-time manual setup page to authenticate with Docusign API using Oath flow and store the Access token and Refresh token in a custom setting. If any other ...
0
votes
2answers
29 views

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

I need help troubleshooting the below apex. I have this class being called in a custom JSON Builder on a custom object. I'm logging successful runs in the log in the developer console, but in the ...
1
vote
2answers
314 views

Regular Expression matches returns false

I am using this regular expression: String regex = '(\\d{11}|\\d{5} \\d{6}|\\+\\d{12})'; Pattern compiledPattern = Pattern.compile(regex); Matcher match = compiledPattern.matcher('Inbound Call at 5:...
1
vote
1answer
34 views

Complex SOQL: I need help with a dual join

Since there are way too few options to do literally anything with Account Team Members, we want to use the following approach to track Account Team Member history: Have a custom object ...
-1
votes
1answer
32 views

My test class keep failing. Moving the rev scheduler with the close date

Im not getting any coverage with this test class. YOu'll see the trigger and the class handler are here. ============================================================== @isTest private class ...
-3
votes
1answer
35 views

is there any way to solve the following case with out using maps

Create Custom field called “Number of Locations” (Its API Name: NumberofLocations__c) on the Account Object (Data Type=Number) The following trigger creates the number of contacts which are equal to ...
-2
votes
0answers
26 views

Insufficient Privileges on Update trigger

I am calling a managed package method from a user trigger. When I create a new record it is working as expected but when I update a record it is throwing Insufficient Privileges error. Please suggest ...
4
votes
1answer
73 views

How to check Blob objects for equality?

Rather disappointingly for Blobs this assertion fails: System.assert(Blob.valueOf('abc') == Blob.valueOf('abc')); though the Apex Expression Operators documentation over ambitiously says that: ...
0
votes
2answers
37 views

Add a new key-value to a json string

The scenario is as follow, I got a json which was converted to a string, I need to add to that json another key-value pair. I assume it requires to convert the string back to json, how would that ...
0
votes
1answer
25 views

How to use if(!Test.isRunningTest()){} for a specific test

I have a class with a callout and a unittest mock for the callout. The callout has a scheduler. If I create a unittest for the scheduler the scheduler tries to do a callout If i use if(!Test....
0
votes
2answers
26 views

Apex - break list into multiple small lists before processing

I have a list of 15,000 records. I can maintain the count in a flag. Integer Counter = 15000; I want to break my main list into 3 small lists. Each list should contain 5,000 records. First list ...
0
votes
2answers
17 views

Wrong IsNillable flag for Name field while querying FieldDefinition object

I am trying to retrieve the list of fields which are mandatory and running below query: SELECT id, DeveloperName,EntityDefinitionId,IsNillable,Label FROM FieldDefinition where EntityDefinitionId= '...
0
votes
2answers
21 views

How to write a unittest for scheduled apex

I have a scheduler for a callout class. I am trying to write a unittest for my scheduler but do not know how to test the execute part Class global class or_guestsSchedulable implements Schedulable{ ...
0
votes
0answers
13 views

Not able to see the schedulable class while scheduling the class from UI interface

I have a class which implement "Schedulable" interface but when I am trying to schedule this job using UI I can't find it in the lookup search. BUT when I edit and save this class then it visible and ...
0
votes
1answer
24 views

How to create a custom search component using lightning [on hold]

I have been struggling trying to create a custom component for searching through objects using lightning. I have been on trailhead and the only reference to such is the Lightning Communities: Create a ...
0
votes
0answers
21 views

Run flow in APEX class

I've created a list button for cases, and I´ve included it in accounts related lists. The button has a visualforce page as its content resource, where I run my flow for creating a new Case. The idea ...