---
schema_version: "1"
id: c203efa65a6ccdc8c779890590b1ef99cfaded11d133c733390911b26799ca5a
title: GetSchema RPC Method
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/event-bus/pub-sub-api/references/getschema-rpc.md
canonical_url: https://developer.salesforce.com/docs/platform/pub-sub-api/references/methods/getschema-rpc.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: b41a6fe1e01c9147600ea2f657c38138371a134ef097b3bdab03889ddf35be3c
products:
  - Pub/Sub API
  - Event Bus Docs
---
# GetSchema RPC Method

The `GetSchema` method returns the schema of an event topic using the schema ID. Use the schema to encode the payload in the Avro format of the event to publish, or to decode the payload of a received event.

**important:** Don’t call `GetSchema` for every RPC method call. The schema typically doesn’t change often, so call `GetSchema` only one time and store the returned schema for subsequent calls. If the event schema changes, for example, when an administrator adds a field to the event definition, the schema ID changes. Compare the schema ID with the latest schema ID retrieved from PublishResponse or FetchResponse. If the schema ID changes, call `GetSchema` to retrieve the new schema. Calling `GetSchema` unnecessarily can slow down your app’s performance.

```
rpc GetSchema (SchemaRequest) returns (SchemaInfo);
```

To get the schema ID for the `SchemaRequest` parameter, do one of the following.

- Call `GetTopic`. The return value of this method is TopicInfo. TopicInfo contains `schema_id`, which represents the latest schema. We recommend that you publish events with the latest schema.
- For events received from the event bus, get the schema ID from the event message in the FetchResponse, `ProducerEvent.schema_id`. Use this schema for deserialization. For events published to the event bus, get the schema ID from the PublishResponse.

**note:** You can still publish events with an old schema saved from an earlier `GetTopic` call. You use an Avro code generator to generate classes based on Avro types and deploy your app. If the event schema changes later, you can still publish and subscribe to the events as long as the schema differences are resolvable by the Avro schema resolution rules.

For more information about the fields in SchemaRequest and SchemaInfo, see the [Pub/Sub API proto file](https://github.com/forcedotcom/pub-sub-api/blob/main/pubsub_api.proto).
