Salesforce For YOU
ads
Sunday, 23 June 2019
convert sObject to JSON String and JSON string to sObject using apex in Salesforce
Sample Code:
Account acc = new Account(Name = 'TestAccountName', AccountNumber = '234567', Industry= 'IT');
/* Code to convert Account to test string */
String strTest = Test .serialize(Acc);
system.debug('Test String is ' + strTest );
/* Code to convert Test string to Account */
Account Acc1 = (Account)Test .deserialize(str Test , Account.Class);
system.debug('Account is ' + Acc1);
Account acc = new Account(Name = 'TestAccountName', AccountNumber = '234567', Industry= 'IT');
/* Code to convert Account to test string */
String strTest = Test .serialize(Acc);
system.debug('Test String is ' + strTest );
/* Code to convert Test string to Account */
Account Acc1 = (Account)Test .deserialize(str Test , Account.Class);
system.debug('Account is ' + Acc1);
Thursday, 30 August 2018
Workflow Field and Formula Fields Updates
Workflow Field Updates
1. Changes in Parent record cannot be updated in child records.
2. If the record was updated with workflow field updates, fires before and after triggers one more time. Custom validation rules, duplicate rules, and escalation rules are not run again.
3. It considers criteria before updating the field value.
Note: Workflow field update is recommended over formula field for better performance.
Formula Fields
1. Change in Formula field cannot invoke trigger or workflows.
2. Changes in Parent record will be automatically reflected in child records.
3. Formula field values cannot be modified manually.
3. Formula field values cannot be modified manually.
Find duplicate Accounts in Lightning Experience
1. Open Account Record.
2. Select Related record. If duplicate Accounts are exist, you will found View Duplicates button
to merge it.
Email to Case Assignment Rule not firing
This problem can be solved by making the Case Owner field blank in Case Settings.
Case Owner field is used to find the owner of the case, which can be either an individual user
or a queue. This field is optional.
Note:1. If you specify a case owner, auto-assignment rules are ignored.
2. You can’t delete a queue that a routing address refers to. Either delete the routing address,
Note:1. If you specify a case owner, auto-assignment rules are ignored.
2. You can’t delete a queue that a routing address refers to. Either delete the routing address,
or edit the routing address settings to point to a different queue.
Insert comma between two field value in formula field
Insert Fields:
To insert ',' between two field values in Formula field in Salesforce use &","& between two fields values.
For example: Account Name and Account number are two fields. Create a field as Description and in the formula editor type Name&",'"&AccountNumber to separate those values with comma.
Output:
Wednesday, 29 August 2018
Cover addError() in trigger in Apex Test
Sample Trigger:
trigger RestrictAccountByName on Account(before insert, before update) {
for (Account Acc : Trigger.New) {
if(Acc.Name == 'INVALIDNAME') { //invalidname is invalid
Acc.AddError('The Account Name "'+Acc.Name+'" is not allowed for DML');
}
}
}
Sample Test Class:
@isTest
private class RestrictAccountByName {
@isTest static void test() {
Account Acc = new Account(Name = 'INVALIDNAME');
Database.SaveResult result = Database.insert(Acc, false);
System.assertEquals('The Name "'+Acc.Name+'" is not allowed for DML',result.getErrors()[0].getMessage());
}
}
Cover Page Reference method in test class in Salesforce
Apex Class:
public class Reference {
public Reference () {
}
public PageReference SFDCForyou() {
PageReference pr = new PageReference('http://www.SFDCForyou.com');
pr.setRedirect(true);
return pr;
}
}
Test class:
@isTest
private class Testclass {
@isTest static void test() {
Reference r = new Reference ();
r.SFDCForyou();
}
}
public class Reference {
public Reference () {
}
public PageReference SFDCForyou() {
PageReference pr = new PageReference('http://www.SFDCForyou.com');
pr.setRedirect(true);
return pr;
}
}
Test class:
@isTest
private class Testclass {
@isTest static void test() {
Reference r = new Reference ();
r.SFDCForyou();
}
}
System.CalloutException: Method can not be null
IF error occur like System.CalloutException: Method can not be null issue, then u should use POST Or GET Or PUT in your request.
Sample Code:
HTTPRequest firstreq = new HTTPRequest();
firstreq.setEndPoint('Enter Your End Point URL');
firstreq.setMethod('GET');
Subscribe to:
Posts (Atom)