ads

Sunday 23 June 2019

Roll Up Summary field filters in Salesforce

Roll up Summary fields in Salesforce. Note : Roll up summary field can only be defined on the master object. While your formula fields calculate values using fields within a single record, roll-up summary fields calculate values from a set of related records, such as those in a related list.

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);

Thursday 30 August 2018

Custom Permission using in Workflow Rule in Salesforce

Select formula evaluates to true in the Workflow Rule.



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.

Create New Sub Folder in Salesforce Reports and Dashboards

1. Go to Reports tab.


2. Select the Folder where you wan to create the Sub Folder.

3. Click New Folder inside the Parent folder.



 Sub Folder view in Salesforce



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,
 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:

Convert String to sObject using Apex in Salesforce

Code Format:


//Setting String str as Contact

String str = '
Contact';

//Casting String to sObject

sObject objc = Schema.getGlobalDescribe().get(str).newSObject();
objc.put('LastName', 'Test');
objc.put('
AssistantName', 'Testing');
objc.put('Department', 'Testing');

system.debug('objc is ' + objc);

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();
    }
}

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');

Line Break in Formula Field in Salesforce

Formula Field:


IF( CONTAINS(Name, 'SFDCForyou'),
'SFDCForyou' & BR() &  'Department',
'Not belongs to SFDCForyou department'

)

Formula Editor:












Output: