• sujithkumar j 9
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
@Restresource(urlmapping='/Lead/*')

     global class Cls_LeadData
    {
  @HttpPost
    global static void updateLead(String codeid, String Zipid, String Email) {
    RestRequest req = RestContext.request;
    RestResponse res = RestContext.response;
   
        res.addHeader('Access-Control-Allow-Origin','*');
    res.addHeader('Content-Type', 'application/json');
    res.addHeader('Access-Control-Allow-Credentials','true');
    res.addHeader('Access-Control-Allow-Headers','x-requested-with, Authorization');
    res.addHeader('Accept-Type', 'application/json');
    res.addHeader('Access-Control-Allow-Headers','Content-Type, Accept');
    res.addHeader('Access-Control-Allow-Headers','POST');
    res.addHeader('Access-Control-Allow-Methods', 'POST');
    RestContext.response.addHeader('Content-Type', 'application/json');
        
       try {
           CodeID__c Code = null;        
           String LeadJson = '';
           try{
               CodeID__c LeadDetail= [SELECT Lead__r.Id, Name, Lead__r.PostalCode, Lead__r.Email  FROM CodeID__c where Name=:codeid And Lead__r.PostalCode=:Zipid And Lead__r.Id != null Limit 1];
               Lead ld = new Lead();
               ld.Id = LeadDetail.Lead__r.Id;
               ld.Email = Email;    
                //Update Lead if Exists   
                Update ld;
            Lead led = [Select Name,Street,City,State,Country,PostalCode,Email,UniqueID__c, Lender__c From Lead Where Id=:ld.Id Limit 1];
            Cls_LeadConvertAftertrigger.LeadConvertMethod(LeadDetail.Lead__r.Id);
            LeadJson = JSON.serializePretty(led);              
            RestContext.response.responseBody = Blob.valueOf(LeadJson);            
        } catch(Exception ex){
            RestContext.response.responseBody = Blob.valueOf('{ "valid" : false }'); 
        }
    }
    catch(Exception e) {
            RestContext.response.responseBody = Blob.valueOf('{ "valid" : false }'); 
        }
        }
    }

Here is my test class

@istest
public class Cls_LeadData__test { static testMethod void testupdateLead() {
//CodeID__c m= Lead l=new Lead();
l.firstname='testname';
l.lastname='test';
l.company='Test Company';
//l.CodeID__c='90876544';
l.email='sample@test.com';
l.phone='6884382997';
l.street='123 Test Ave';
l.city='Somewhere';
l.state='MA';
l.PostalCode='87945';
l.country='US';
String JSONMsg= JSON.serialize(l);
RestRequest req = new RestRequest();
req.addHeader('Content-Type', 'application/json'); // Add a JSON Header as it is validated
req.requestURI = '/services/apexrest/Lead/';
req.httpMethod = 'POST';
req.requestBody = Blob.valueof(JSONMsg); // Add JSON Message as a POST
RestResponse res = new RestResponse();
RestContext.request = req;
RestContext.response = res;
Cls_LeadData.updateLead('90876544','87945','sample@test.com');
} }
I am getting 65% code coverage..I am not able to get above 75% code coverage. Can any one help me how to get code coverage for the above class.

 
HI All,

            We are having pdf files on the Library Object . We are using HTML Native app for accessing the rest apis from the salesforce.We need to get the list of Libary ids from the salesforce.For that we developed the below Rest api.

@RestResource(urlMapping='/LibraryList/*')
global class LibraryListController 
{
    @HttpGet    
    //global static List<ContentWorkspaceDoc> retrieve()
    global static List<ContentWorkspace> retrieve()
    {
       RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        res.addHeader('Access-Control-Allow-Origin', '*');
        res.addHeader('Content-Type', 'application/json');
         res.addHeader('Accept', 'application/json');
        res.addHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE');
        String Id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); 
        //List <ContentWorkspace> Lib= [SELECT ParentId,ContentDocumentId,ContentWorkspaceId,Id FROM ContentWorkspaceDoc]; 
        List <ContentWorkspace> Lib= [SELECT Id,Name FROM ContentWorkspace];               
        return Lib;
     }
}

We are sending our apis through our site.Example url  https://ap2.salesforce.com/SampleSite/services/apexrest/LibraryList..
If we are trying to acces this from workbench we are getting the data. But if we run this url publicly we are not getting responce.The reamining all apis we are able to get data.

Can any one please suggest How to get data from the Library.Please help us with your suggestions
Hi guys,

 

When I used Force.com Migration tool to retrieve metadata from a developer org, I got this error : 

Invalid username, password, security token; or user locked out.

My password don't have any $ symbols.But i am getting the same

 

After checking the configuration, I'm sure that : 

- The username, password & security token are correct because I can use them to checkout a Force.com project in Eclipse.

- Server url is correct (https://login.salesforce.com)

 

Can anybody give me an advice ?

 

Thanks.
@Restresource(urlmapping='/Lead/*')

     global class Cls_LeadData
    {
  @HttpPost
    global static void updateLead(String codeid, String Zipid, String Email) {
    RestRequest req = RestContext.request;
    RestResponse res = RestContext.response;
   
        res.addHeader('Access-Control-Allow-Origin','*');
    res.addHeader('Content-Type', 'application/json');
    res.addHeader('Access-Control-Allow-Credentials','true');
    res.addHeader('Access-Control-Allow-Headers','x-requested-with, Authorization');
    res.addHeader('Accept-Type', 'application/json');
    res.addHeader('Access-Control-Allow-Headers','Content-Type, Accept');
    res.addHeader('Access-Control-Allow-Headers','POST');
    res.addHeader('Access-Control-Allow-Methods', 'POST');
    RestContext.response.addHeader('Content-Type', 'application/json');
        
       try {
           CodeID__c Code = null;        
           String LeadJson = '';
           try{
               CodeID__c LeadDetail= [SELECT Lead__r.Id, Name, Lead__r.PostalCode, Lead__r.Email  FROM CodeID__c where Name=:codeid And Lead__r.PostalCode=:Zipid And Lead__r.Id != null Limit 1];
               Lead ld = new Lead();
               ld.Id = LeadDetail.Lead__r.Id;
               ld.Email = Email;    
                //Update Lead if Exists   
                Update ld;
            Lead led = [Select Name,Street,City,State,Country,PostalCode,Email,UniqueID__c, Lender__c From Lead Where Id=:ld.Id Limit 1];
            Cls_LeadConvertAftertrigger.LeadConvertMethod(LeadDetail.Lead__r.Id);
            LeadJson = JSON.serializePretty(led);              
            RestContext.response.responseBody = Blob.valueOf(LeadJson);            
        } catch(Exception ex){
            RestContext.response.responseBody = Blob.valueOf('{ "valid" : false }'); 
        }
    }
    catch(Exception e) {
            RestContext.response.responseBody = Blob.valueOf('{ "valid" : false }'); 
        }
        }
    }

Here is my test class

@istest
public class Cls_LeadData__test { static testMethod void testupdateLead() {
//CodeID__c m= Lead l=new Lead();
l.firstname='testname';
l.lastname='test';
l.company='Test Company';
//l.CodeID__c='90876544';
l.email='sample@test.com';
l.phone='6884382997';
l.street='123 Test Ave';
l.city='Somewhere';
l.state='MA';
l.PostalCode='87945';
l.country='US';
String JSONMsg= JSON.serialize(l);
RestRequest req = new RestRequest();
req.addHeader('Content-Type', 'application/json'); // Add a JSON Header as it is validated
req.requestURI = '/services/apexrest/Lead/';
req.httpMethod = 'POST';
req.requestBody = Blob.valueof(JSONMsg); // Add JSON Message as a POST
RestResponse res = new RestResponse();
RestContext.request = req;
RestContext.response = res;
Cls_LeadData.updateLead('90876544','87945','sample@test.com');
} }
I am getting 65% code coverage..I am not able to get above 75% code coverage. Can any one help me how to get code coverage for the above class.

 

Hi guys,

 

When I used Force.com Migration tool to retrieve metadata from a developer org, I got this error : 

Invalid username, password, security token; or user locked out.

 

After checking the configuration, I'm sure that : 

- The username, password & security token are correct because I can use them to checkout a Force.com project in Eclipse.

- Server url is correct (https://login.salesforce.com)

 

Can anybody give me an advice ?

 

Thanks.

  • April 16, 2012
  • Like
  • 0