+ Start a Discussion
Spencer EdieSpencer Edie 
If I have a formula field whose formula is "= TODAY() - Account.Last_Contact_Date__c", is there a way for me to use apex/soql to access that field such that it returns the formula as a string rather than the date it would otherwise return?
Best Answer chosen by Spencer Edie
Alain CabonAlain Cabon
String selectedObject = Account.sObjectType.getDescribe().getName();

selectedObject = 'MyObject__c';


Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType objectSchema = schemaMap.get(selectedObject);
Map<String, Schema.SObjectField> fieldMap = objectSchema.getDescribe().fields.getMap();
for (String fieldName: fieldMap.keySet()){  
    Schema.DescribeFieldResult df  =  fieldMap.get(fieldName).getDescribe();
    if (df.isCalculated() &&  df.getCalculatedFormula() != null) {
         system.debug('field name:' +  fieldName + ' label:' + df.getLabel() + 
        ' type:' +  df.getType() + ' formula:' + df.getCalculatedFormula().replace('\n',' ').replace('\r',' '));


Julie CurryJulie Curry 
I am trying to create a simple reference table that our support agents can see on the case record.  I don't need it to contain data from Salesforce only pre-defined text.  I would like it to have 2 columns and 4 rows.  It will be somewhat similar to the image I have inserted.  I'm not a developer so I was wondering if someone could provide a sample of something similar they have to help get me started.  Thanks in advance for your help!User-added image
Best Answer chosen by Julie Curry
kumud thakur 20kumud thakur 20
<table style="width:100%">
    <th>Header 1</th>
    <th>Header 2</th> 
  <tr>  <!-- Tr to create row --->
    <td>Header 1 data</td> <!-- data to the column --->
    <td>Header 2 data</td> 
    <td>Header 12</td>
    <td>Header 22</td> 
    <td>Header 13</td>
    <td>Header 23</td> 
    <td>Header 14</td>
    <td>Header 24</td> 

You can add CSS style to make better look and feel. This is very basic table to start. Hope it will help you to start.
Subodh Kumar 42Subodh Kumar 42 
we can not call one asynchronous process to another asynchronous process but how can we call from one batch to another batch since batch is also asynchronous process?
Best Answer chosen by Subodh Kumar 42
Khan AnasKhan Anas (Salesforce Developers) 
Hi Subodh,

Greetings to you!

There's no rule that says that "asynchronous cannot call asynchronous". There are specific rules in place, such as "future cannot call future". A Queueable can call another Queueable, a Batchable can call another Batchable in the finish method, and Scheduleable methods can call Batchable and Queueable methods. There are usually lesser limits allowed for asynchronous contexts (e.g. a Queueable can call only one Queueable, while a normal synchronous transaction can call 50 of them).

Reference: https://salesforce.stackexchange.com/questions/204896/calling-async-from-async-process

To call another batch class from a batch class: 
1. Call another batch class in the finish method as execute method is called many times but Start and finish method only once.
2. So once your main batch is completed and the finish method is called and then it will call another batch.

Please refer to the below link which might help you further:


I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Subodh Kumar 42Subodh Kumar 42 
How can we track failed records in batch apex? suppose we are updating 100000 records out of that 20000 records are failed so again I want to update only failed records.How can we achieve this?

Best Answer chosen by Subodh Kumar 42
Jan RevetJan Revet 
I have this json string i am pulling in with the code below:


The code in Developer Console:

Http http = new Http();
HttpRequest request = new HttpRequest();
HttpResponse response = http.send(request);

if (response.getStatusCode() == 200) {
    Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
    List<Object> rows = (List<Object>) results.get('data'); 
    for (Object row : rows) {
        System.debug('TEST ' + row.kleur1);


This code produces an error: Line: 13, Column: 36
Variable does not exist: kleur1. Houw should I access the field 'kleur1' of the object row?
Best Answer chosen by Jan Revet
Ahmed Ansari 2Ahmed Ansari 2

  for this work around you replace for loop code  with below code 

//access json data
    for (Object row : rows) {
        Map<String, Object> rw = (Map<String, Object>) row;
        System.debug('TEST ' +  rw.get('kleur1'));

I am trying to optimize my working code. When i tried to convert a set into a Map, I am getting an error -  
Line: 10, Column: 22
Method does not exist or incorrect signature: void add(Id, String) from the type Map<Id,String>

Map<ID, String>  mapAccountBillingAddress = new Map<ID, String>();
for (AggregateResult aggregate : [Select count(Id),BillingStreet str,BillingCity ct, BillingState stt, BillingPostalCode pc 
From Account                                                                Group By BillingStreet,BillingCity,BillingState,BillingPostalCode
HAVING (count(BillingStreet) > 1  AND count(BillingPostalCode) > 1 )
] )
mapAccountBillingAddress .add(aggregate.id, ((String)aggregate.get('str')+(String)aggregate.get('ct')+(String)aggregate.get('stt')+(String)aggregate.get('pc')));

Best Answer chosen by RarLopz
Hi RarLopz,

You cant use "add" to put values in Map chnage this line.
mapAccountBillingAddress.Put(aggregate.id, ((String)aggregate.get('str')+(String)aggregate.get('ct')+(String)aggregate.get('stt')+(String)aggregate.get('pc')));


I could use some assistance with an apex error Im receiving from a batch process. Im trying to filter my batch using System.now() but am getting an unexpected token: "(' error from the getQueryLocator line. How do I get System.now() to translate properly so the query will execute? Thanks ahead of time.
global class BatchTempName implements Database.Batchable<sObject>, Database.Stateful {

	String query = '';
	global BatchTempName() {
		query = 'SELECT Name,Custom_Date_Time__c, Unavailable__c FROM User where Custom_Date_Time__c <: System.now() and Unavailable__c = true';

	global Database.QueryLocator start(Database.BatchableContext BC) {
		return Database.getQueryLocator(query);


Best Answer chosen by user23232323
Raj VakatiRaj Vakati
Try like this

Refer this link 


global class BatchTempName implements Database.Batchable<sObject>, Database.Stateful {

	String query = '';
	DateTime currentTime = System.now();

	global BatchTempName() {
		query = 'SELECT Name,Custom_Date_Time__c, Unavailable__c FROM User where Custom_Date_Time__c <: currentTime and Unavailable__c = true';

	global Database.QueryLocator start(Database.BatchableContext BC) {
		return Database.getQueryLocator(query);


Best Answer chosen by Radhika Kondapally 8
Raj VakatiRaj Vakati
You have to the flow actions in that case .. Or 

. You can add a hyperlink in a Display Text field and use HTML:

<a href="http://www.hyperlinkcode.com/">Hyperlink Code</a>


flow action References 
Lionel KamdemLionel Kamdem 

I am moving an Apex Trigger from Sandbox to Production and this is the error I am getting in the Apex Test: 

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user: 0120v000000TPT9AAO: [RecordTypeId] 
Stack Trace: Class.RequireRejectionCommentTest.generateAndSubmitObject: line 166, column 1 Class.RequireRejectionCommentTest.testApprovalWithoutComment: line 49, column 1

It's telling me as the Salesforce Admin I do not have access to this record but I do I checked and I have access to these record types. 

This is the code right here: 
testBatchIS.add(new Case(Hours__c=15.12,RecordTypeId='0120v000000TPT9AAO',AccountId='0017000001XpguKAAR',                               Status='New',Concession_Category__c='Scope Change',                     Explanation_for_Business_Reason_Choice__c='stuff'));

I think it might have to do with the way I reference the Record Type as an ID.

instead of referencing it as RecordTypeID how would I reference it by the RecordTypeName instead? 
Best Answer chosen by Lionel Kamdem
Ahmed Ansari 2Ahmed Ansari 2
For this You can Use 
Replace 'DeveloperNameOfRecordType' with Case Recortype Name
Id RecordTypeIdCase= Schema.SObjectType.Case.getRecordTypeInfosByName().get('DeveloperNameOfRecordType').getRecordTypeId();

and use RecordTypeIdCase in replace of '0120v000000TPT9AAO'
himanshu huske 7himanshu huske 7 
How to insert value in Salutation, FirstName, Lastname, Account(LookUp) in contact object using Apex, help me with code
Best Answer chosen by himanshu huske 7
Hi himansu,

I have understanrd your requirement.
In below i have provided Apex Code for inserting the Contact object records from Apex class.
public class ContactRecordInsertion {

    public void Data()
        // Creating New Account To provide Account Lookup in Contact 
        Account newAccount = new Account ();
        newAccount.name = 'AcName';
        newAccount.BillingCity ='TestCity';
        newAccount.BillingCountry ='TestCountry';
        newAccount.BillingStreet ='TestStreet';
        insert newAccount;
        // Creating New Contact record.
        Contact Con = new Contact();
        Con.Salutation = 'Mr.';
        Con.FirstName = 'Community User';
        Con.Lastname = 'Developer';
        Con.AccountId = newAccount.Id ; //Account Lookup
Please let me know If it helps you.

Thanks & Regards