---
schema_version: "1"
id: d82916d171b0b864b870a8510f018ba26e2c17d95a2228bfdac80911ce608810
title: AffinityScoreDefinition
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/api_meta/fundraising_affinityscoredefinition_metadata_api.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/fundraising_affinityscoredefinition_metadata_api.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 68b4a22da7349b02fe9e96536f02fc0f9d49b80eadd3b3c67aae5abc63a10357
description: Represents the affinity information used in calculations to analyze and categorize contacts for marketing purposes.
---
# AffinityScoreDefinition

Represents the affinity information used in calculations to analyze and categorize contacts for marketing purposes.

![Important](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/images/icon_note_important.png)

#### Important

Where possible, we changed noninclusive terms to align with our company value of Equality. We maintained certain terms to avoid any effect on customer implementations.

## Parent Type

This type extends the [Metadata](https://developer.salesforce.com/docs/atlas.en-us.264.0.api_meta.meta/api_meta/metadata.htm "HTML (New Window)") metadata type and inherits its fullName field.

## File Suffix and Directory Location

AffinityScoreDefinition components have the suffix .affinityScoreDefinition and are stored in the affinityScoreDefinitions folder.

## Version

AffinityScoreDefinition components are available in API version 68.0 and later.

## Special Access Rules

This metadata type is available only if the Fundraising Access license is enabled for the org and the Fundraising admin permission is assigned to users.

## Fields

### affinityScoreDefinitionDesc

- **Field Type**: string
- **Description**: Description of the affinity score definition.

### affinityScoreDefinitionName

- **Field Type**: string
- **Description**: Name of the affinity score definition.

### affinityScoreType

- **Field Type**: AffinityScoreType (enumeration of type string)
- **Description**: Type of the affinity score that's defined. Valid values are CAP—Capacity, Ability, Propensity (CAP), or RFM—Recency, Frequency, Monetary (RFM).
- **Default value**: RFM

### masterLabel

- **Field Type**: string
- **Description**: Label for this affinity score definition value. This display value is the internal label that doesn't get translated.

### numberOfMonths

- **Field Type**: int
- **Description**: Number of months to analyze the records for calculating the affinity score.

### numberOfRanges

- **Field Type**: int
- **Description**: Required. Number of ranges to use in the calculation, ranging from 0 to 9. Provide the corresponding range list values in the scoreRangeList field.

### scoreRangeList

- **Field Type**: string
- **Description**: Required. Ranges that are referenced in the affinity score calculation. This field is used with scoreRangeList. For example, to calculate RFM with numberOfRanges value as 3, provide the values for the scoreRangeList field.

### sourceFieldApiNameList

- **Field Type**: string
- **Description**: Required. API names of the source fields that are referenced in the score calculation.

### sourceObjectApiNameList

- **Field Type**: string
- **Description**: API names of the source objects that are referenced in the score calculation.

### targetFieldApiNameList

- **Field Type**: string
- **Description**: Required. API names of the target fields where the calculated scores are added.

### targetObjectApiName

- **Field Type**: string
- **Description**: API name of the target object where the calculated scores are added.

Example scoreRangeList format:

{
    "R ranges":"0-30, 31-100, 100+",
    "F ranges":"0-10, 11-100, 100+",
    "M ranges":"0-1000, 1001-5000, 5000+"
}

## Declarative Metadata Sample Definition

This example shows a sample of an AffinityScoreDefinition component.

<?xml version="1.0" encoding="UTF-8"?>
<AffinityScoreDefinition
	xmlns="http://soap.sforce.com/2006/04/metadata">
	<affinityScoreDefinitionDesc\>RFM Affinity Score</affinityScoreDefinitionDesc\>
	<affinityScoreDefinitionName\>AffinityScoreDefinition\_RFM</affinityScoreDefinitionName\>
	<affinityScoreType\>RFM</affinityScoreType\>
	<masterLabel\>MasterLabel</masterLabel\>
	<numberOfMonths\>12</numberOfMonths\>
	<numberOfRanges\>3</numberOfRanges\>
	<scoreRangeList\>
        \[
          {
            "name": "R Ranges",
            "direction": "ascending",
            "ranges": \[30,90,180\]
          },
          {
            "name": "F Ranges",
            "direction": "descending",
            "ranges": \[10,15,100\]
          },
          {
            "name": "M Ranges",
            "direction": "descending",
            "ranges": \[500,1000,5000\]
          }
     \]
      </scoreRangeList\>
	<sourceFieldApiNameList\>
        \[
          {
            "name": "R Source",
            "values": 
                \[
                  {
                    "fieldName": "DonorGiftSummary.DaysSinceLastGift",
                    "fieldWeight": 1
                  }
                \]
          },
          {
            "name": "F Source",
            "values": 
                \[
                  {
                    "fieldName": "DonorGiftSummary.GiftCount",
                    "fieldWeight": 1
                  }
                \]
          },
          {
            "name": "M Source",
            "values": 
                \[
                  {
                    "fieldName": "DonorGiftSummary.TotalGiftsCount",
                    "fieldWeight": 1
                  }
                \]
          }
        \]
      </sourceFieldApiNameList\>
	<targetFieldApiNameList\>
        \[
          {
            "name": "R Target",
            "values": 
                \[
                  {
                    "fieldName": "DonorGiftSummary.RecencyScore",
                    "fieldWeight": 1
                  }
                \]
          },
          {
            "name": "F Target",
            "values": 
                \[
                  {
                    "fieldName": "DonorGiftSummary.FrequencyScore",
                    "fieldWeight": 1
                  }
                \]
          },
          {
            "name": "M Target",
            "values": 
                \[
                  {
                    "fieldName": "DonorGiftSummary.MonetaryScore",
                    "fieldWeight": 1
                  }
                \]
          }
        \]
      </targetFieldApiNameList\>
</AffinityScoreDefinition\>

This example shows a sample of the package.xml file that references the previous definition.

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types\>
        <members\>\*</members\>
        <name\>AffinityScoreDefinition</name\>
    </types\>
    <version\>68.0</version\>
</Package\>

## Wildcard Support in the Manifest File

This metadata type supports the wildcard character \* (asterisk) in the package.xml manifest file. For information about using the manifest file, see [Deploying and Retrieving Metadata with the Zip File](https://developer.salesforce.com/docs/atlas.en-us.264.0.api_meta.meta/api_meta/file_based_zip_file.htm "HTML (New Window)").