Steps to Create Custom filter in AngularJS .

Tags

In last post we have discussed about predefined “Filters” available in AngularJS. In this post will discuss how to create a custom filter in AngularJS.

Steps :

  1. Initialize ng-app
    var stepByStepApp = angular.module(“stepByStepApp”, []);

    1. Create custom filter
      stepByStepApp.filter(“evenorodd”, function () {
      return function (input) {
      var result = “”;
      input = input || “”;
      if (input != “” && !isNaN(input)) {
      if (input % 2 == 0)
      result = “even”;
      else
      result = “odd”;
      }
      else
      result=”Invalid Number”
      return result;
      }
      });
  2. Use custom filter in HTML page

    <div ng-app=”stepByStepApp”>
    <input type=”text” ng-model=”text” placeholder=”Enter text” />
    <p>entered text is : {{ text | evenorodd }}</p>
    </div>

Note : In this post we have discussed how to create custom filter in AngularJs.
Try Yourself

How to create custom helper class using Extension Method ?

Tags

In this post we are going to learn how to create a Custom helper class using extension method.

Example 1 :
Helper class : HtmlHelpers.cs

using system.web.mvc;

namespace MvcApplication1.Helper

{
public static class HtmlHelpers
{
public static string Truncate(this HtmlHelper helper, string input, int length)

{
if (input.Length <= length)
return input;
else
return input.Substring(0, length) + “…..”;
}
}
}

Controller class : HtmlHelperController.cs

public class HtmlHelperController : Controller

{
public ActionResult Index()
{
ViewBag.Message = “Razor declarative @helper example”;
return View();
}
}

How to consume Custom HtmlHelper class?

File Name : Index.cshtml

@using MvcApplication1.Helper // This is Custom helper class namespace

<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<div>
Original Text : @ViewBag.Message <br />
Text after Truncate :
@Html.Truncate(ViewBag.Message as string,15)
</div>
</body>
</html>

Output :

Original Text : Razor declarative @helper example

Text after Truncate : Razor declarati……

 

How to extend an user defined class using Extension Method?

Tags

In this post we are going to discuss how to write an extension method for an existing class. Below code will help you to write an extension method for an existing class.

Main class :

public class MainClass
{
public int x = 100;
public void Method1()
{
Console.WriteLine(“Method1”);
}
public void Method2()
{
Console.WriteLine(“Method2”);
}
}

Extension method for main class :

public static class ExtendMainClass
{
public static void Method3(this MainClass obj)
{
Console.WriteLine(“method3”);
}
public static void Method4(this MainClass obj,int x){

Console.WriteLine(“method4 : “+x);
}

}

How to call Extension Method :
MainClass obj = new MainClass();
obj.Method3();
obj.Method4(10);

How to view Salesforce exported Data correctly in different excel versions.

I tried to export data using Salesforce Data Management tools. I am  sharing the steps how to view exported file in different version of excel which I received from SalesForce.

The exported data files were created using Unicode (UTF-8) character encoding. To view the characters correctly, open the files in a text editor, or follow the instructions below for opening the files in Microsoft® Excel.

Microsoft® Excel (pre-2003 versions)
1. Open the file in Microsoft® Excel and select File -> Save As, and save the file as type Web Page.
2. Select Tools -> Options -> General tab and click the Web Options button.
3. Select the Encoding tab, and then choose the “Unicode (UTF-8)” option.
4. Click OK to close the dialog boxes.
5. Select File -> Save to save the file with selected encoding.
These steps will need to be repeated for each file.

Microsoft® Excel 2003
1. Open Microsoft® Excel and click File -> New.
2. Click Data -> Import External Data -> Import Data.
3. Select the csv file to open and Microsoft® Excel will launch the text import wizard.
4. Select “Delimited” and choose the “Unicode (UTF-8)” option for File origin.
5. Click Next.
6. Select “Comma” in the Delimiters section and click Finish. You may be prompted to select a range of cells.
These steps will need to be repeated for each file.

Reference :  SalesForce

How to logging in Apex Data Loader

Below are the steps to logging in Apex Dataloder.

  1. Enter Username.
  2. Enter password as  security token with password.
    Ex. If the Password is abc and Security token is xxxxxxxxxxxxxxx then Apex dataloader password is abcxxxxxxxxxxxxxxx.
    How to set security token click here
  3. Go to Settings in data loader > Check Server Host (clear for default) : should be “https://login.salesforce.com” if you have developer edition and “https://test.salesforce.com” if it is a sandbox.

Please provide your valuable comments if this helpful.

How to import Custom Objects records in Salesforce

In salesforce there are different ways to import custom object records. In this post will discuss how to import custom object records using Salesforce “Data Management” option.

I have created below custom object in salesforce for demo.

Location Custom Object

Steps :

  1. Log in to salesforce account using salesforce credential.
  2. Create above location object.
  3. Click on “Salesforce Setup link” as mentioned below link.
  4. Img1Start the Import “Location” Custom Objects by clicking Data Management -> Import Custom Objects -> Start the Import Wizard! as mentioned below image.
  5. Img2
  6. Import wizard opens with list of all custom Objects.
    [Step 1] : Select “Location” and click “Next”.
    Step1[Step 2] : Select Prevents Duplicates option based on requirement. In this example I have selected “Yes – prevent duplicate records from being created. Note: You must select this option if you want to update existing records”. Location Name is my matching filed and Update the record if already exists as mentioned below image and click “Next” button.Img3[Step 3] :  Specify the relationship and click next as per below Image.[Step 4] : In this section we need to upload the required(which has Location records) file with .csv extension. Below are the two location details and format which I have kept in my Location.csv file.
    Name,Street_Address__c,City__c,State_Provience__c,Postal_Code__c,Country__c,Phone__c,Location_Map_URL__c
    Delhi,#9091,Delhi,DEL,445613,India,1234567891,https://success.salesforce2.com/ideaView?id=08730000000gPv5AAE
    Chennai,#9092,Chennai,CHE,445612,India,1234567891,https://success.salesforce.com/ideaView?id=08730000000gPv5AAE
    i)  Select .csv file
    ii) Specify character encoding and click next as mentioned below image.img 6[Step 5] : Filed Mapping-  In this steps map the .csv fields with the salesforce field.Img 7[Step 6] : Click “Import Now!”  img 8[Step 7] : Click Finish and check your email associated with SalesForce.
  7. Check “Location” tab after receiving confirmation.
    Before : BeforeAfter :After

In this post we have discussed on how to import custom object using “Data Management” option of Salesforce application.

Reference : Import My Organization’s Custom Objects

 

Sql Server Tips #1

1. Searching procedure names using specific XXX tables
SELECT DISTINCT so.name
FROM syscomments sc
INNER JOIN sysobjects so ON sc.id=so.id
WHERE sc.TEXT LIKE ‘%XXX%’

Example : Suppose you are searching stored procedures which are using ‘Employee’ table .

SELECT DISTINCT so.name
FROM syscomments sc
INNER JOIN sysobjects so ON sc.id=so.id
WHERE sc.TEXT LIKE ‘%Employee%’

2. Find list of procedures which are modified in Last 30 days
SELECT name,create_date,modify_date
FROM sys.objects
WHERE type = ‘P’
AND DATEDIFF(D,modify_date, GETDATE()) < 30

3. Find list of Procedures which are created in Last 30 days
SELECT name,create_date,modify_date
FROM sys.objects
WHERE type = ‘P’
AND DATEDIFF(D,create_date, GETDATE()) < 30

4. Find list of tables which are modified in Last 30 days
SELECT name,create_date,modify_date,type
FROM sys.tables where
DATEDIFF(D,modify_date, GETDATE()) <  30

5. Find list of tables which are created in Last 30 days
SELECT name,create_date,modify_date,type
FROM sys.tables where
DATEDIFF(D,create_date, GETDATE()) <  30

Many times I have used above queries to track my schema changes during moving code from one environment to other. Hope above tips will helps you all.  Keep share your thoughts and leanings.  🙂

How to retrive nth row value of a table

Problem : I have a employee table then how to find out nth employee detail with out using the actual id. Below are the solutions for the given problem.

The below solution I have wrote the query for , getting the record of third employee.

CREATE TABLE [dbo].[Employee](
[Id] [int] NOT NULL PRIMARY KEY,
[Name] [varchar](50) NULL,
[Age] [int] NOT NULL,
[Photo] [image] NULL,
[Salary] [numeric](10, 2) NULL,
)

INSERT INTO Employee values (101,’James Clerk’,29,NULL,1000.00);
INSERT INTO Employee values (102,’Steve Proell’,40,NULL,60000.00);
INSERT INTO Employee values (103,’Matt Mcnair’,35,NULL,5000.00);
INSERT INTO Employee values (104,’Amit Kr’,29,NULL,1000.00);
INSERT INTO Employee values (105,’Jeff Yeary’,32,NULL,1000.00);

# Solution 1
select * from employee where id in (
select MAX(Id) from Employee
where Id in (select top(3) ID from Employee ))

# Solution 2

select top 1 *
from employee
where Id in (select top 3 Id from employee order by Id asc)
order by Id desc

# Solution 3

SELECT * FROM
(SELECT ROW_NUMBER() OVER (ORDER BY ID) AS RowNum, * FROM Employee) sub
WHERE RowNum = 3

# Solution 4
SELECT * FROM
(SELECT DENSE_RANK() OVER (ORDER BY ID) AS RowNum, * FROM Employee) sub
WHERE RowNum = 3

#solution 5 : [Paging in SqlServer 2012]

SELECT intUserID_pk, chvFirstName, chvLastName
FROM User
ORDER BY intUserID_pk
OFFSET 5 ROWS
FETCH NEXT 5 ROW ONLY;

This post tried to explain different solution to  retrieve nth row value of a table. Please provide your valuable comments and suggestions which will helps to improve our learning.

Pagination in “Sql queries” / “Stored Procedure”

Mostly we are looking for specific range of record from database instead of fetching all the records from the database to increase scalability of our web-application .

Below examples will describes how we can archive pagination using “Sql queries” / “Stored Procedure”

Example :

CREATE TABLE [dbo].[Employee](
[Id] [int] NOT NULL PRIMARY KEY,
[Name] [varchar](50) NULL,
[Age] [int] NOT NULL,
[Photo] [image] NULL,
[Salary] [numeric](10, 2) NULL,
)

INSERT INTO Employee values (101,’James Clerk’,29,NULL,1000.00);
INSERT INTO Employee values (102,’Steve Proell’,40,NULL,60000.00);
INSERT INTO Employee values (103,’Matt Mcnair’,35,NULL,5000.00);
INSERT INTO Employee values (104,’Amit Kr’,29,NULL,200.00);
INSERT INTO Employee values (105,’Jeff Yeary’,32,NULL,45000.00);
INSERT INTO Employee values (106,’Lisa Miller’,34,NULL,55000.00);
INSERT INTO Employee values (107,’Eric Pressly’,45,NULL,80000.00);
INSERT INTO Employee values (108,’Brianna Greene’,32,NULL,40000.00);

#Method 1 : ROW_NUMBER() 

//Procedure

CREATE PROC GetRecord
(
@startInd int,
@endInd int
)
AS
BEGIN
SELECT * FROM
(
SELECT *, ROW_NUMBER() OVER (ORDER BY SALARY DESC) EMPIND
FROM EMPLOYEE
)employeedata
WHERE EMPIND > @startInd AND EMPIND <= @endInd;
END

@if we want to display record between 2nd to 5th highest salary then execute the procedure as mentioned below.

exec dbo.getRecord 1, 5

#Method 2 : Rank()

SELECT * FROM
(
SELECT *,
RANK() OVER (ORDER BY SALARY DESC) EMPIND
FROM EMPLOYEE
)employeedata
WHERE EMPIND > @startInd AND EMPIND <= @endInd;

#Method 3 : DENSE_RANK()

SELECT * FROM
(
SELECT *,
DENSE_RANK() OVER (ORDER BY SALARY DESC) EMPIND
FROM EMPLOYEE
)employeedata
WHERE EMPIND > @startInd AND EMPIND <= @endInd;

In this post we discussed different methods to archive pagination in “Sql queries” or “Stored Procedure”. Please share your thoughts and others methods to archive pagination.

Create your own website, free on WordPress.com.Create your own website.
Start free