Skip to content

Commit e9155a4

Browse files
committed
Added LeadQueryRepository.cls with 2 sample methods
1 parent 5d03a12 commit e9155a4

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class LeadQueryRepository {
2+
3+
public static Lead getLeadById(Id leadId) {
4+
// Created a string for your where clause
5+
String whereClause = 'WHERE Id = :leadId';
6+
// Created a new instance of QueryGenerator, using a field set and your where clause
7+
String query = new QueryGenerator(SObjectType.Lead.FieldSets.MyFieldSet).buildQuery(whereClause);
8+
9+
// Database.query returns generic SObjects, so cast it to the desired SObject type & return it
10+
return (Lead)Database.query(query);
11+
}
12+
13+
public static List<Lead> getLeadsByStatus(String status) {
14+
// Created a string for your where clause
15+
String whereClause = 'WHERE Status = :status';
16+
// Created a new instance of QueryGenerator, using a field set and your where clause
17+
String query = new QueryGenerator(SObjectType.Lead.FieldSets.MyFieldSet).buildQuery(whereClause);
18+
19+
// Database.query returns generic SObjects, so cast it to the desired SObject type & return it
20+
return (List<Lead>)Database.query(query);
21+
}
22+
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>38.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

0 commit comments

Comments
 (0)