You need to sign in to do that
Don't have an account?
SFDC12
Integration testclass
Hi everyone, can someonehelp how to write testclass for the below class
@RestResource(urlmapping='/v1/Accountmanager/')
global class Integration_Example {
@HttpGet
//which is used to get the records or query the records
global static Account doget(){
//intilaise the object
Account a=new Account();
//get the req parameters in map
map<string,string> paramsmap=Restcontext.request.params;
//get the id
string accid=paramsmap.get('Id');
//query the records
a=[select id ,name from Account where id=:accid];
return a;
}
@HttpDelete
global static Account doDelete(){
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String AccNumber = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE AccountNumber = :AccNumber ];
delete result;
return result;
}
@Httppost
//post method is used to create the record
global static Account docreate(string name){
Account a = new Account(name=name);
insert a;
return a;
}
@Httpput
global static Account doupdate(string name){
map<string,string> paramsmap=Restcontext.request.params;
//get the id
string accid=paramsmap.get('Id');
Account a = new Account(name=name, id=accid);
update a;
return a;
}
}
Thanks in Advance
@RestResource(urlmapping='/v1/Accountmanager/')
global class Integration_Example {
@HttpGet
//which is used to get the records or query the records
global static Account doget(){
//intilaise the object
Account a=new Account();
//get the req parameters in map
map<string,string> paramsmap=Restcontext.request.params;
//get the id
string accid=paramsmap.get('Id');
//query the records
a=[select id ,name from Account where id=:accid];
return a;
}
@HttpDelete
global static Account doDelete(){
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String AccNumber = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE AccountNumber = :AccNumber ];
delete result;
return result;
}
@Httppost
//post method is used to create the record
global static Account docreate(string name){
Account a = new Account(name=name);
insert a;
return a;
}
@Httpput
global static Account doupdate(string name){
map<string,string> paramsmap=Restcontext.request.params;
//get the id
string accid=paramsmap.get('Id');
Account a = new Account(name=name, id=accid);
update a;
return a;
}
}
Thanks in Advance
Please try the below code:
Thanks,
Maharajan.C
All Answers
Please try the below code:
Thanks,
Maharajan.C
Hi Anusha, Can you please mark the best answer !!!