Apex :
@RestResource(urlMapping = '/agentInfor/*')
global class AgentInformationCls {
@HttpGet
global static List < InboundAgentInfomation > getAgentInfomation() {
List < InboundAgentInfomation > agentInfo = new List < InboundAgentInfomation > ();
RestRequest req = RestContext.request;
String agentEmailAddress = req.params.get('emailId');
String primarySkill = req.params.get('primarySkill');
String secondarySkill = req.params.get('secondarySkill');
String firstName = req.params.get('firstName');
String lastName = req.params.get('lastName');
String locationName = req.params.get('locationName');
try {
//dynamic query formation
String wherequery = 'select id, Client__c, Confirm_Password1__c, Contact__c, Email_Address__c, Experience_in_Primary_Skill__c,'
+' Experience_in_Secondary_Skill__c, First_Name__c, Last_Name__c, Location__c, Password1__c, Primary_Skill__c, Secondary_Skill__c,'
+'Primar_Skill_Proficiency1__c, Secondary_Skill_Proficiency1__c, Career_Level__c from Base_Data__c where (';
if (String.isNotBlank(agentEmailAddress)) {
wherequery = wherequery + 'Email_Address__c = \'' + agentEmailAddress + '\'' + ' and ';
}
if (String.isNotBlank(primarySkill)) {
wherequery = wherequery + 'Primary_Skill__c= \'' + primarySkill + '\'' + ' and ';
}
if (String.isNotBlank(secondarySkill)) {
wherequery = wherequery + 'Secondary_Skill__c = \'' + secondarySkill + '\'' + ' and ';
}
if (String.isNotBlank(firstName)) {
wherequery = wherequery + 'First_Name__c = \'' + firstName + '\'' + ' and ';
}
if (String.isNotBlank(lastName)) {
wherequery = wherequery + 'Last_Name__c = \'' + lastName + '\'' + ' and ';
}
if (String.isNotBlank(locationName)) {
wherequery = wherequery + 'Location__c = \'' + locationName + '\'' + ' and ';
}
if (wherequery.substring(wherequery.length() - 4) == 'and ') {
wherequery = wherequery.substring(0, wherequery.length() - 4);
}
wherequery = wherequery + ') order by Primar_Skill_Proficiency1__c desc';
system.debug(wherequery);
//Adding dynamic query to list
List < Base_Data__c > acc = Database.query(wherequery);
if (!acc.isEmpty()) {
for (Base_Data__c b: acc) {
agentInfo.add(new InboundAgentInfomation(b, acc.size()));
}
return agentInfo;
} else {
agentInfo.add(new InboundAgentInfomation('No Results Found'));
return agentInfo;
}
} catch (exception e) {
agentInfo.add(new InboundAgentInfomation(e.getMessage()));
return agentInfo;
}
}
global class InboundAgentInfomation {
global Integer recordCount;
global Base_Data__c agentList;
global String errorMessage;
global InboundAgentInfomation(Base_Data__c agentList, Integer recordCount) {
this.agentList = agentList;
this.recordCount = recordCount;
}
global InboundAgentInfomation(String errorMessage) {
this.errorMessage = errorMessage;
this.agentList = agentList;
this.recordCount = 0;
}
}
}

@RestResource(urlMapping = '/agentInfor/*')
global class AgentInformationCls {
@HttpGet
global static List < InboundAgentInfomation > getAgentInfomation() {
List < InboundAgentInfomation > agentInfo = new List < InboundAgentInfomation > ();
RestRequest req = RestContext.request;
String agentEmailAddress = req.params.get('emailId');
String primarySkill = req.params.get('primarySkill');
String secondarySkill = req.params.get('secondarySkill');
String firstName = req.params.get('firstName');
String lastName = req.params.get('lastName');
String locationName = req.params.get('locationName');
try {
//dynamic query formation
String wherequery = 'select id, Client__c, Confirm_Password1__c, Contact__c, Email_Address__c, Experience_in_Primary_Skill__c,'
+' Experience_in_Secondary_Skill__c, First_Name__c, Last_Name__c, Location__c, Password1__c, Primary_Skill__c, Secondary_Skill__c,'
+'Primar_Skill_Proficiency1__c, Secondary_Skill_Proficiency1__c, Career_Level__c from Base_Data__c where (';
if (String.isNotBlank(agentEmailAddress)) {
wherequery = wherequery + 'Email_Address__c = \'' + agentEmailAddress + '\'' + ' and ';
}
if (String.isNotBlank(primarySkill)) {
wherequery = wherequery + 'Primary_Skill__c= \'' + primarySkill + '\'' + ' and ';
}
if (String.isNotBlank(secondarySkill)) {
wherequery = wherequery + 'Secondary_Skill__c = \'' + secondarySkill + '\'' + ' and ';
}
if (String.isNotBlank(firstName)) {
wherequery = wherequery + 'First_Name__c = \'' + firstName + '\'' + ' and ';
}
if (String.isNotBlank(lastName)) {
wherequery = wherequery + 'Last_Name__c = \'' + lastName + '\'' + ' and ';
}
if (String.isNotBlank(locationName)) {
wherequery = wherequery + 'Location__c = \'' + locationName + '\'' + ' and ';
}
if (wherequery.substring(wherequery.length() - 4) == 'and ') {
wherequery = wherequery.substring(0, wherequery.length() - 4);
}
wherequery = wherequery + ') order by Primar_Skill_Proficiency1__c desc';
system.debug(wherequery);
//Adding dynamic query to list
List < Base_Data__c > acc = Database.query(wherequery);
if (!acc.isEmpty()) {
for (Base_Data__c b: acc) {
agentInfo.add(new InboundAgentInfomation(b, acc.size()));
}
return agentInfo;
} else {
agentInfo.add(new InboundAgentInfomation('No Results Found'));
return agentInfo;
}
} catch (exception e) {
agentInfo.add(new InboundAgentInfomation(e.getMessage()));
return agentInfo;
}
}
global class InboundAgentInfomation {
global Integer recordCount;
global Base_Data__c agentList;
global String errorMessage;
global InboundAgentInfomation(Base_Data__c agentList, Integer recordCount) {
this.agentList = agentList;
this.recordCount = recordCount;
}
global InboundAgentInfomation(String errorMessage) {
this.errorMessage = errorMessage;
this.agentList = agentList;
this.recordCount = 0;
}
}
}

No comments:
Post a Comment