organization isn’t authorized to upload change sets

organization isn’t authorized to upload change sets

Many of you have seen this below error during metadata migration in salesforce by using changsets.

This organization isn’t authorized to upload change sets to other organizations. For authorization, contact the deployment connections administrators on the organizations where you want to upload changes.

This error is because of deployment settings. Seems like you have not created deployment connection between your source org and destination org.

To create deployment connection follow below steps.

login to target environment -> setup -> deploy -> deployment setting -> select source sandbox from the available list of sandboxes – edit -> check allow inbound change sets check box and save.

Now you can upload the change set to the target environment.

Which Salesforce Edition I am using?

How to find which Salesforce edition I am using:

To find which salesforce edition you are using. Follow below steps.

Go to set up ->click on Administer you will edition like below based on which edition you are using.

Salesforce Edition

What are the different Salesforce edition:

Group
Professional
Enterprise
Unlimited
Pro
Business Plus

There are many other Salesforce editions. there editions base don the which type of service you are using like Sales, Service, marketing and platform.

writing test class for Scheduler and Batches

How to write a test class for Scheduler and Batches:

Here is the example to Write test method for Scheduler and Batch Apex Classes:

Example: This batch Apex is to Approving the opportunities which are in submitted status.

// Scheduler
global class OpportunityScheduler implements Schedulable{
global void execute(SchedulableContext sc){
OpportunityBatch batch = new OpportunityBatch();
if(!Test.isRunningTest()){
database.executebatch(batch);
}
}
}

// Batch
global class OpportunityBatch implements database.batchable<sObject>{
global String opptyList;
global Database.QueryLocator start(Database.BatchableContext info){
String status = ‘Submitted’;
opptyList = ‘select name,AccountName__c from Opportunity where
status__c =\”+ status +’\” ;
return Database.getQueryLocator(claimList);
}
global void execute(Database.batchableContext info,List<Opportunity> opptyList){
List<Opportunity> opportunitiesList = new List< Opportunity >();
for(Opportunity oppty: opptyList){
oppty.status__c = ‘Approved’;
opportunitiesList.add(oppty);
}
Insert opportunitiesList;
}
global void finish(Database.batchableContext info){

}
}

// Scheduler test method
@istest
class OpportunitySchedulerTest{
public static testMethod void testschedule() {
Test.StartTest();
OpportunityScheduler testsche = new OpportunityScheduler();
String sch = ‘0 0 23 * * ?’;
system.schedule(‘Test status Check’, sch, testsche );
Test.stopTest();
}
}

// Batch test method
@istest
public class OpportunityBatchtest{
//query the activities to process
static testmethod void OpportunityTestMethod(){
Opporunity oppty = new Opportunity ();
oppty.name = ‘test Oppty’;
oppty.status__c = ‘submitted’;
insert oppty;
OpportunityBatch opptybatch = new OpportunityBatch ();
Status = ‘Submitted’;
opptybatch.opptyList = ‘select name,AccountName__c from Opportunity where status__c =\”+ status +’\’ and id=\’ AND Id=\”+claim.id+’\”;
Database.executebatch(opptybatch);
}

How to use system.runAs()|Apex test class Example

How to use system.runAs()?

Here is the example to use System.runAs() in apex test class: For example we have a class to create the campaign only if logged in user is marketing profile otherwise throwing error.

System
// Apex Trigger
trigger campaignBeforeInser on Account (before insert) {
for(Campaign campaign: trigger.new){
if(userInfo.getProfileId == ‘marketing profile Id’){
campaign.currency = ‘USD’;
}
else{
campaign.addError(‘you are not authorized to create campaign’);
}
}
}
//Here is the Test class for above trigger.
@isTest
private class CampaignTriggersTest{
private static testmethod void campaignTriggersTest(){
Profile prof = [select id from profile where name LIKE ‘%marketing%’];
User user = new User();
user.firstName = ‘test1’;
user.lastName = test2;
user.profileId = prof.id,username = ‘test@test.com’;
user.email = ‘test@test.com’;
insert user;
system.runAs(user){
Campaign campaign = new Campaign();
campaign.name = ‘laptop’;
insert campaign();
}
}
}

Write test class for trigger?-SimpleExample

How to Write test class for trigger:

Here is the example to write a test class for a simple Apex Trigger.
Following trigger is executed whenever account is created and creates sharing to the manager to that record.

Salesforce Wrting Test Class

Apex Trigger Code:
trigger accountAfterInsert on Account (after insert) {
string managerId= [Select Id, ManagerId FROM User WHERE Id = :userInfo.getUserId()].ManagerId;
for(Account acc: trigger.New){
AccountShare accShare = new AccountShare();
accShare .ParentId = acc.Id;
accShare .UserOrGroupId = managerId;
accShare .AccessLevel = ‘EDIT’;
accShare .RowCause = Schema.accountShare.RowCause.Manual;
}
}

// Test Class for above Trigger
@isTest
private class AccountTriggersTest{
private static testmethod void accountTriggersTest(){
Account acc = new Account();
acc.name = ‘NewAccount’;
acc.address = ‘USA’;
insert acc;
}
}

Keywords or functions in Test classes

KeywordKeywords or functions in Test classes:

@isTest Annotation:
This annotation is used to define the test class. If we use this annotation then data which we created inside the method doesn’t count against your organization limit. Can be created the method declared as “private” or “public”.

seeAllData:
If we use this keyword seeAllData=true , then we get all the data from database. This will be a problem because the data is vary from instance to instance.
seeAllData=false, is not access to the data in the system ,whatever the data need in the test class we have to create in class it slef. Always better to use this method because data will be same for all instances.

System.runAs():
This keyword/function is used only in test method, generally Apex code is running in system mode not in user mode and permission and record sharing of the current user are not taken as count.
If we have to call the piece of code which will be execute with specific user then we can use this function.

Test.isRunningTest():
This keyword/function we can use only in classes not in test classes.
When we have to call the piece of code only from test class then we can use this.
This is Boolean variable return true when calling from test class otherwise false.

What is Unit Test Class in Apex?????

Unit Test Classes in Apex

Unit Test Class

Testing is the major thing of the development. In salesforce, Apex Code requires the creation and execution of unit tests. Unit tests are class methods that verify whether a particular piece of code is working properly or not. Unit tests are written in Apex Code and annotated with the “testMethod” keyword.

Important thing to note down before to write TestClass:
– At least 75% of code coverage is required to move the apex code to production from sandboxes.
– Whatever we created the data in test class that won’t save in database. (delete all the data once transaction is done)
– Do not write any SOQLs in test class.
– Do not use “seeAllData=true”, Create own data in test class.
– Use As much as Assertions like “System.AssertEquals” or “System.AssertNotEquals”
– To reset the Governor limits for the particular transcation use system.startTest() and system.stopTest()

Writing a simple Unit Test Class:

Apex Class:
public class NewAccountCreation {
public Account account{get;set;}
public void save(){
Account acc = new Account();
// User enter values in vf page and we are capturing and creating account
acc.name = account.Name;
acc.adress = account.adress;
Insert acc;
}
}

// Unit Test class for above apex Class
@isTest
private class NewAccountCreationTest{
public static testMethod void NewAccountCreationTestMethod(){
NewAccountCreation accountCreation = new NewAccountCreation ();
Account acc = new Account();
acc.name = ‘NewAccount’;
acc.address = ‘bangalore’;
insert acc;
accountCreation.save();
}
}

What is Contact? | Salesforce Contact

What is Contact? | Salesforce Contact

What is contact in Salesforce? Contact in Salesforce represents the individual people associated with business account in your organization.

Salesforce CRM provides Contact Management as part of salesforce.com standard functionality, on top of that customers can customize their own functionality. This objects has attributes like FirstName, LastName, AccountId, AssistantName, AssistantPhone¸Birthdate, CanAllowPortalSelfReg, CleanStatus, ConnectionReceivedId, ConnectionSentId, Department, Description, Email, Fax, HomePhone, LeadSource, MailingAddress, MobilePhone, Name, OtherAddress, etc…

To create contact in Salesforce login to your Salesforce account and click on contact tab, click on new button and enter required details & save contact.

Contact Salesforce

What is Accounts in Salesforce|Salesforce Account

Salesforce Account

What is Salesforce Account? Account represents an individual customer account, organization or partner involved with business.

As part of standard functionality Salesforce.com provides Account objects in Salesforce which stores all account details related your business like Customers and Competitors.  This object has properties (fields) like AccountNumber, AccountSource, AnnualRevenue, Name, BillingAddress, BillingCity, BillingCountry, BillingCountryCode, BillingLatitude, BillingLongitude, BillingPostalCode, BillingState, BillingStateCode, BillingStreet, Description, Industry, IsCustomerPortal, IsPartner, IsPersonAccount, NumberOfEmployees, Phone, ShippingAddress, ShippingCity, ShippingCountry, ShippingCountryCode, Site etc…

How to create Simple test Salesforce Account? To create Account login to your Salesforce, Click on Account tab and click on new button & enter required fields and Save.

Salesforce Account

What is Person Account? Person accounts are used store information about individual consumers. By default Salesforce accounts are business accounts which stores companies/organization information. Personal account are different  compared to Business accounts in salesforce. Person accounts don’t have contacts. Person account acts contact. It stores first name, last name and other details.

How to enable Person Account? To enable person account Raise a support case with Salesforce.com.

What is the relationship between account & Contact? Actual relationship between account & contact is Master detail relationship. But from the UI it shows look up relationship look & feel. If you delete account, its associated  contacts will be deleted. It shows it is master detail relationship.