Tuesday 19 May 2015

REST API | New Resources | Summer 15 | Composite Resources in Salesforce

Composite Resources
Salesforce introduces two composite resources for improving your application’s performance by minimizing the number of round trips between client and server.

The Batch resource lets you execute a sequence of independent subrequests. For example, you can update the name on an account and get the account’s field values in a single request

"batchRequests" : [
    "method" : "PATCH",
    "url" : "v34.0/sobjects/account/001D000000K0fXOIAZ",
    "richInput" : {"Name" : "NewName"}
    "method" : "GET",
    "url" : "v34.0/sobjects/account/001D000000K0fXOIAZ"
The response contains the status codes of each subresponse and the responses themselves.
"hasErrors" : false,
"results" : [
    "statusCode" : 204,
    "result" : null
    "statusCode" : 200,
    "result" : { Account attributes }

The Batch resource supports batching for the following resources and resource groups

Resources by VersionvXX.X
SObject resources
Connect resources
Chatter resources
SObject Tree

NOTE:- It won't work, but that's because it will not be available until version 34 of the API.
But if you get a pre-release org, you can do the same with the updated API version

Source of Link :-


Thursday 7 May 2015

Creating a sales invoice with financial force (no current company)

Problem :-  Creating a sales invoice with financial force

How to set Current Company by UI:-

Go to a non-setup page where you can see the left sidebar. The left sidebar near the top should show your 'current company'. 

If you have no 'current company',  a link saying 'Current Company not set' should appear there instead.
Click on the link and select a company from the list of companies that you have created.

Then create your invoice(s) as required

Test Class for Sales Invoice in Financial Force ( How to set current company by Code ) :-

private class salesInvoiceTestClass
 static testMethod void salesInvoiceTest() 
 Group testGroup = new Group(Name='test group', Type='Queue');
 insert testGroup;
 QueuesObject testQueue ; 
 System.runAs(new User(Id=UserInfo.getUserId()))
     List<queuesobject >  listQueue = new List<queuesobject >();
   queuesobject q1 = new queuesobject (queueid=testGroup.id, sobjecttype='Case'); 
   queuesobject q2 = new queuesobject (queueid=testGroup.id,                                                                 sobjecttype='c2g__codaAccountingCurrency__c'); 
   queuesobject q3 = new queuesobject (queueid=testGroup.id,                                                                 sobjecttype='c2g__codaPurchaseInvoice__c'); 
   queuesobject q4 = new queuesobject (queueid=testGroup.id, sobjecttype='c2g__codaCompany__c'); 
   queuesobject q5 = new queuesobject (queueid=testGroup.id, sobjecttype='c2g__codaYear__c'); 
   queuesobject q6 = new queuesobject (queueid=testGroup.id, sobjecttype='c2g__codaInvoice__c'); 
   insert  listQueue;

   GroupMember GroupMemberObj = new GroupMember();
   GroupMemberObj.GroupId = testGroup.id;
   GroupMemberObj.UserOrGroupId = UserInfo.getUserId();
   insert GroupMemberObj;

 c2g__codaCompany__c company = new c2g__codaCompany__c();
 company.Name = 'Test Record';
 company.JDE_Company_Code__c = '123';
 company.GLS_JE_Group_Number__c = '123' ;
 company.c2g__CashMatchingCurrencyMode__c = 'Test Account';
 company.c2g__YearEndMode__c = 'Test Code';
 company.c2g__ExternalId__c = 'ABCDE1234567876';
 company.c2g__LogoURL__c ='ww.XYZ.com';
 company.c2g__ECCountryCode__c = 'AE' ;
 company.c2g__VATRegistrationNumber__c = 'Test 222.222.222 TVA' ;
 company.c2g__Website__c = 'ww.xyz.com';
 company.c2g__Country__c ='US';
 company.ownerid = testGroup.Id;
 insert company;

 c2g__codaYear__c yr= new c2g__codaYear__c();
 yr.Name ='2015';
 yr.c2g__AutomaticPeriodList__c =  true;
 yr.c2g__OwnerCompany__c = company.id;
 yr.c2g__ExternalId__c = 'yzsd1234';
 yr.c2g__NumberOfPeriods__c =11;
 yr.c2g__StartDate__c =  system.today() - 10;
 yr.c2g__Status__c = 'Open';
 yr.c2g__PeriodCalculationBasis__c = '445';
 yr.c2g__YearEndMode__c = 'Full Accounting Code' ; 
 yr.c2g__UnitOfWork__c = 12;
 yr.ownerid = testGroup.Id;
 insert yr;

 c2g__codaPeriod__c prd = new c2g__codaPeriod__c();
 prd.Name ='Test2015';
 prd.c2g__ExternalId__c ='abdc12345';
 prd.c2g__StartDate__c = System.today()-10;
 prd.c2g__EndDate__c= System.today()+10;
 prd.c2g__OwnerCompany__c = company.id;
 prd.c2g__PeriodNumber__c ='123';
 prd.c2g__Description__c ='test Desc';
 prd.c2g__PeriodGroup__c = 'Q1';
 prd.c2g__PeriodNumber__c = '1';
 prd.c2g__YearName__c = yr.id;
 insert prd;

 c2g__codaUserCompany__c userCompany = new c2g__codaUserCompany__c();
 userCompany.c2g__Company__c =company.id;
 userCompany.c2g__User__c = userInfo.getUserId();
 userCompany.c2g__ExternalId__c = 'ABCDE1234567876';
 userCompany.c2g__UnitOfWork__c = 111 ;
 insert  userCompany;

 c2g__codaAccountingCurrency__c accCurrency = new c2g__codaAccountingCurrency__c();
 accCurrency.c2g__OwnerCompany__c = company.id;
 accCurrency.c2g__DecimalPlaces__c = 2;
 accCurrency.Name = 'AED';
 accCurrency.c2g__Dual__c = true ;
 accCurrency.ownerid = testGroup.Id;
 insert accCurrency;

 c2g__codaExchangeRate__c exchRate = new c2g__codaExchangeRate__c();
 exchRate.c2g__ExchangeRateCurrency__c = accCurrency.id;
 exchRate.c2g__OwnerCompany__c = company.id;
 exchRate.c2g__ExternalId__c ='12323232';
 exchRate.c2g__Rate__c =44.55;
 exchRate.c2g__StartDate__c = system.today()-10;
 exchRate.c2g__UnitOfWork__c =10;
 insert exchRate;       

 c2g__codaGeneralLedgerAccount__c GLAcc = new c2g__codaGeneralLedgerAccount__c();
 GLAcc.Name = 'Retained Earnings';
 GLAcc.c2g__BalanceSheet1__c ='Balance Sheet'; 
 GLAcc.Description__c ='test Desc';
 GLAcc.c2g__ExternalId__c ='testID';
 GLAcc.Account_Level__c = 'CAB';
 GLAcc.Business_Unit__c = 'RG';
 GLAcc.c2g__ReportingCode__c = '1234567543333';
 GLAcc.c2g__UnitOfWork__c =123;
 GLAcc.Reconciliation_Frequency__c ='Quarterly';
 GLAcc.c2g__TrialBalance1__c = 'Balance Sheet' ;
 GLAcc.c2g__Type__c = 'Balance Sheet' ;
 GLAcc.X10_Digit_GLA__c = false;
 insert GLAcc;

 Account acc= new Account();
 acc.Name='Test Account';
 acc.c2g__CODAAccountsPayableControl__c = GLAcc.Id;
 insert acc;

 c2g__codaInvoice__c testInvoice = new c2g__codaInvoice__c();
 testInvoice.CurrencyIsoCode = 'USD'
 testInvoice.c2g__InvoiceDate__c = date.today().addDays(-7)
 testInvoice.c2g__DueDate__c = date.today().addDays(-7)
 testInvoice.c2g__Account__c = acc.Id
 testInvoice.c2g__OwnerCompany__c = company.id
 testInvoice.ownerid = testGroup.Id
 insert testInvoice;            

Problem link :- https://developer.salesforce.com/forums/ForumsMain?id=906F000000092RnIAI

Monday 4 May 2015

@testSetup ( Set Up Test Data for an Entire Test Class )

Use test setup methods (methods that are annotated with @testSetup) to create test records once and then access them in every test method in the test class. Test setup methods can be time-saving when you need to create reference or prerequisite data for all test methods, or a common set of records that all test methods operate on.

Test setup methods can reduce test execution times especially when you’re working with many records. Test setup methods enable you to create common test data easily and efficiently. By setting up records once for the class, you don’t need to re-create records for each test method. Also, because the rollback of records that are created during test setup happens at the end of the execution of the entire class, the number of records that are rolled back is reduced. As a result, system resources are used more efficiently compared to creating those records and having them rolled back for each test method

private class CommonTestSetup 
 static void setup() 
  Account acct = new Account();
       acct.Name = 'Salesforce.com';
       acct.Industry = 'Technology';
  insert acct;
  Contact cont = new Contact();
       cont.FirstName = 'Amit';
       cont.LastName = 'Chaudhary';
       cont.AccountId = acct.Id;
  insert cont;
 static void testMethod1() 
  Account acct = [SELECT Id FROM Account WHERE Name='Salesforce.com' LIMIT 1];
     acct.Phone = '555-1212';
  update acct;

 static void testMethod2() 
  Account acct = [SELECT Phone FROM Account WHERE Name='Salesforce.com' LIMIT 1];
  System.assertEquals(null, acct.Phone);

  1. If a test class contains a test setup method, the test setup method executes first, before any test method in the class
  2. Multiple @testSetup methods are allowed in a test class, but the order in which they’re executed by the testing framework isn’t guaranteed
  3. If the test class or a test method has access to organization data by using the @isTest(SeeAllData=true) annotation, test setup methods aren’t supported in this class.
  4. Available for API versions 24.0 and later
  5. If a fatal error occurs during the execution of a test setup method, such as an exception that’s caused by a DML operation or an assertion failure, the entire test class fails, and no further tests in the class are executed
  6. If a test setup method calls a non-test method of another class, no code coverage is calculated for the non-test method
  7. If a test method changes those records, such as record field updates or record deletions, those changes are rolled back after each test method finishes execution. The next executing test method gets access to the original unmodified state of those records

Amit Chaudhary

Friday 1 May 2015


The Summer’15 release of Salesforce.com is now in available under pre-release program. In May Sandboxes will be upgraded so that your organization gets the look and feel of Summer’15 release

Customer/User’s Point of view

1) Data Loader for Mac

The Data Loader, an easy-to-use graphical tool that helps you import, export, update, and delete Salesforce data, is now available for Mac OS X.

To download the Mac version, from Setup, click Data Management > Data Loader

2) Choose the Logout Page for Salesforce Users

Direct users to a specific logout destination that maintains your own branding experience after they log out of Salesforce. Or, send them to a specific authentication provider’s page

From Setup, go to Security Controls > Session Settings. Set the Logout Page Settings to provide the URL of the custom logout page. If none is provided, the default is https://login.salesforce.com unless MyDomain is enabled. If My Domain is enabled, the default is https://customdomain.my.salesforce.com

3) Convert Leads to Contacts (Generally Available)

Sales representatives on the go can convert qualified leads to contacts, as well as create accounts and opportunities. This option is available in all versions of Salesforce1.

It’s easy to make this option available to your sales reps. From Setup in the full Salesforce site, click Customize > Leads > Settings, and then select the option to enable conversions on the Salesforce1

4) Support Updating Picklist Fields Using Formulas

When your process updates fields, you can now use formulas and date functions as the value

5) Setup Assistant for Newly Activated Organizations

Setup Assistant helps you import data and customize your sales stages—all through easy-to-use wizards. And we’ve included helpful videos to get you and your teams on the way to increasing sales in Salesforce

6) Create or Edit Records Owned by Inactive Users

Previously, only administrators were able to edit accounts, opportunities, and custom object records that are owned by inactive users. With Spring ’15, administrators and all users with the create or edit permission can create or edit accounts, opportunities, and custom object records that are owned by inactive users. For example, you can edit the Account Name field on an opportunity record that is owned by an inactive user

7) Set Up Test Data for an Entire Test Class

Use test setup methods (methods that are annotated with @testSetup) to create test records once and then access them in every test method in the test class. Test setup methods can be time-saving when you need to create reference or prerequisite data for all test methods, or a common set of records that all test methods operate on.

Test setup methods are defined in a test class, take no arguments, and return no value. The following is the syntax of a test setup method.
@testSetup static void methodName() {


private class CommonTestSetup {

    @testSetup static void setup() {
        // Create common test accounts
        List<Account> testAccts = new List<Account>();
        for(Integer i=0;i<2;i++) {
            testAccts.add(new Account(Name = 'TestAcct'+i));
        insert testAccts;        
    @isTest static void testMethod1() {
        // Get the first test account by using a SOQL query
        Account acct = [SELECT Id FROM Account WHERE Name='TestAcct0' LIMIT 1];
        acct.Phone = '555-1212';
        update acct;
       Account acct2 = [SELECT Id FROM Account WHERE Name='TestAcct1' LIMIT 1];
       delete acct2;
    }                                                                          }

8) Enforce IP Addresses in Login IP Ranges

The Enforce login IP ranges on every request Session Settings option restricts the IP addresses from which users can access Salesforce to only the IP addresses defined in Login IP Ranges. This option affects all user profiles that have login IP restrictions

  • From Setup, click Security Controls | Session Settings
  • Select Enforce login IP ranges on every request

9) Administrators Can Log in as Any User

Administrators with “Modify All Data” permission and delegated administrators with “View Setup and Configuration” permission can log in as any user without asking end users to grant access. Previously, this option was available only if Salesforce enabled the Administrators Can Log in as Any User setting for your organization. To disable this feature, contact Salesforce.

Relates Link :-

1) https://developer.salesforce.com/releases/release/Summer15
2) http://docs.releasenotes.salesforce.com/en-us/spring15/release-notes/salesforce_release_notes.htm