function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AmandaSilberAmandaSilber 

URGENT!! I'm deploying and my original test class isn't working!

@RestResource(urlMapping='/ZLead/*')
global class ZRestAPI {

   @HttpPost
    global static String  createLead(Sender sender,Details details,String type,String id,String created, Recipient recipient, String price, Quote quote, Arm arm, Z z, Fees fees) {
    
    RecordType rt = [select ID, name from RecordType where name='Z'];    
    Lead  l =new Lead(LastName = sender.lastName,
                    FirstName = sender.FirstName,
                    Lead_Type1__c = Type,
                    Email = sender.emailAddress,
                    Phone = sender.phoneNumber,
                    Ref_Id__c = id,
                    RecordTypeId = rt.id,
                    Admin_Comments__c = details.message,
                    What_is_your_annual_income__c = details.annualincome,
                    Property_Zip_Code__c = details.zipCode,
                    Approximate_Value__c = details.propertyValue,
                    Loan_Amount__c  = details.loanAmount,
                    Loan_Purpose__c  = details.loanPurpose,
                    State  = details.stateAbbreviation,
                    Property_State__c = details.stateAbbreviation,
                     Down_Payment__c = details.downPayment,       
                    Property_Purpose__c = details.propertyUse                    
                    );
    insert l;    
    
       if(details.propertyType == 'SingleFamilyHome'){
           l.property_type__c = 'Single Family';}
        if(details.propertyType == 'TownHouse'){
           l.property_type__c = 'Town Home';}
            if(details.propertyType == 'CondoFourOrFewerStories' || details.propertyType == 'CondoFiveOrMoreStories'){
           l.property_type__c = 'Condominium';}
            if(details.propertyType == 'Cooperative'){
           l.property_type__c = 'Co-Op';}
            if(details.propertyType == 'MobileOrManufactured'){
           l.property_type__c = 'Manufactured/Mobile Home';}
            if(details.propertyType == 'Modular'){
           l.property_type__c = 'Modular';}
            if(details.propertyType == 'Leasehold'){
           l.property_type__c = 'Leasehold';}    

           if(details.creditScoreRange == 'R_720_739'){
            l.Credit_Score__c = 'Excellent (720+)';}
        if(details.creditScoreRange == 'R_680_699'){
            l.Credit_Score__c = 'Good (680-719)';}
        if(details.creditScoreRange == 'R_640-679'){
            l.Credit_Score__c = 'Fair (640-679)';}
         if(details.creditScoreRange == 'R_620_639'){
            l.Credit_Score__c = 'Poor (639 or less)';}  
         
         if(details.closingTimelineDays == 90){
             l.How_Soon_Are_You_Looking_to_Purchase__c = '0 to 3 months';}   
        if(details.closingTimelineDays == 180){
             l.How_Soon_Are_You_Looking_to_Purchase__c = '3 to 6 months';}   
         if(details.closingTimelineDays == 365){
             l.How_Soon_Are_You_Looking_to_Purchase__c = '6 to 12 months';}   
         if(details.closingTimelineDays == 366){
             l.How_Soon_Are_You_Looking_to_Purchase__c = '12+ months';}   
         if(details.closingTimelineDays == 1){
             l.How_Soon_Are_You_Looking_to_Purchase__c = 'Not sure, Im Just Getting Started';}                    
    
        if(details.hasAgent == true){
        l.Working_w_Realtor_or_Specialist__c = true;}
        
        if(details.hasBankruptcy == true || details.hasForeclosure == true){
            l.past_bankruptcy_foreclosure_short_sale__c = 'Yes';}
            else
            if(details.hasBankruptcy != true && details.hasForeclosure != true){
                l.past_bankruptcy_foreclosure_short_sale__c = 'No';}
         
         if(details.firstTimeBuyer == true){
             l.First_Time_Home_Buyer__c = 'Yes';}
             else
             if(details.firstTimeBuyer == false){
                 l.First_Time_Home_Buyer__c = 'No';}
         
         if(details.vaEligible == true){
             l.Have_you_served_in_us_military__c = 'Yes';}    
             else
             if(details.vaEligible == false){
                 l.Have_you_served_in_us_military__c = 'No';}
                 
          if(details.hasCoborrower == true){
             l.Will_there_be_a_co_borrower__c = 'Yes';}    
             else
             if(details.hasCoborrower == false){
                 l.Will_there_be_a_co_borrower__c = 'No';}        

update l;
    
    return 'Z Lead Created '+l.Id;


    }// method

   
    global class Sender {
    
        global String lastName;
        global String firstName;
        global String phoneNumber;
        global String emailAddress;
    }
    
    global  class Recipient{
    global  string firstname;
    global string lastname;
    global  string lenderId;
    global string nmlsLicense;
    global  string phoneNumber;
    global  string emailAddress;
    }
    
    global class Details{
    global List<string> desiredPrograms;
    global String message;
    global  Decimal annualincome;
    global  String monthlyDebts;
    global  String creditScoreRange;
    global  boolean hasAgent;
    global  String zipCode;
    global  Decimal propertyValue;
    global  Boolean hasBankruptcy;
    global  Decimal loanAmount;
    global String loanPurpose; //purchase
    global  Decimal loanToValuePercent;
    global  String propertyType; //single family home
    global  String stateAbbreviation;
    global  Boolean firstTimeBuyer; 
    global  Decimal downPayment;
    global  Boolean vaEligible;  
    global  Boolean hasForeclosure;
    global  String debtToIncomePercent; 
    global  Boolean acceptPrepaymentPenalty; //
    global  Decimal totalAssets;
    global  string quoteId;
    global  string propertyUse; //primary
    global  boolean newConstruction;
    global  boolean selfEmployed;
    global  string preapprovalLetterId;
   global string requestId;
   global Boolean hasCoborrower;
   global string creditReportId;
   global Decimal creditReportScore;
   global String loanRequest;
   global String agentBusinessName;
   global String agentEmailAddress;
   global String agentFirstName;
   global String agentId;
   global String agentLastName;
   global string agentPhoneNumber;
   global Decimal cashOut;
   global Decimal closingTimelineDays;
   global string coborrowerFirstName;
   global string coborrowerLastName;
   global string currentBacker;
   global decimal currentBalance;
   global boolean fhaStreamlineEligible;
   global boolean harpEligible;
   global boolean hasSecondMortgage;
   global string propertyAddress;
   global boolean wantsCashOut;
   global boolean vaFirstTimeUser;
   global boolean vaHasDisability;
   global string veteranType;
   global string yearPurchased;
}

    global  class Contact{
    global  String type;
    global  String id;
    global  String created;
    global String price;
}        

   global class quote{
   global String lenderCredit;
   global String termMonths;
   global String dueInMonths;
   global String rate;
   global Decimal lockDays;
   global Arm arm;
   global List<fees> fees;
   global Quote quote;
   global Zillow zillow;
   global Decimal apr;
   global decimal interestOnlyMonths;
   global boolean hasPrepaymentPenalty;
   global boolean jumbo;
   global boolean harp;
   global boolean lenderPaidMortgageInsurance;
   global decimal annualMortgageInsurancePremiumPercent;
   global Fha fha;
   global Va va;
   global boolean currentBackerMustBeFannieMae;
   global boolean currentBackerMustBeFreddieMac;
   global decimal lenderCreditPercent;
   global decimal maxAllowedLTV;
}

  global class fees{
  global Decimal amount;
  global String name;
  global Decimal hudLine;
  global decimal percent;
}

  global class arm{
  global String index;
  global String initialCap;
  global String lifetimeCap;
  global Decimal fixedRateMonths;
  global Decimal adjustmentPeriodMonths;
  global String margin;     
  global String periodicCap;
}

  global class zillow{
  global Decimal feesRolledIntoLoanAmount;
  global Decimal monthlyMortgageInsurance;
  global Decimal loanAmount;
  global String created;
  global Decimal apr;
  global Decimal monthlyprincipalAndInterest;
  global Decimal upfrontCost;  
  global Decimal points;
}  

  global class fha{
  global decimal upfrontPremiumPercent;
  global decimal annualPremiumPercent;
  global boolean streamline;
}

  global class va{
  global decimal fundingFeePercent;
}    

}// class
Best Answer chosen by AmandaSilber
Himanshu ParasharHimanshu Parashar
Hi Amanda,

In your scenerio I see following options to solve this issue. Pass the rest of the objects as I did for Sender Class. it will surely,

 
ZRestAPI.Sender send= new ZRestAPI.Sender();
send.lastName='User';
send.firstName='Demo';
send.phoneNumber='';
send.emailAddress='test@test.com';



String str = ZRestAPI.createLead(send,details,type,Stringid,created,recipient,price,quote,arm,z,fees);
system.debug(str);


Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
 

All Answers

Himanshu ParasharHimanshu Parashar
Can you post your test class code as well ?
AmandaSilberAmandaSilber
@isTest (SeeAllData = true)
private class testZAPI{
    static testMethod void ZRestAPI() {
    
        String json=        '{"sender": {"lastName": "Testing", "phoneNumber": "(206) 402-4568", "emailAddress": "superadmin@tes.com", "firstName": "Joe"}, '+
        '"created": "2014-12-30T10:31:00-08:00","recipient": {"firstName": "testing", "lenderId": "ZUzr6lkkilfhu1_aj9j7", "nmlsLicense": "399802", "phoneNumber": "(888) 871-7291", "emailAddress": "40030557@tes.zillow.local"}, "price": 0,"details": {"message": "Please contact me."}, "type": "simple", "id": "LC-CWDXZJL"}'+
        '';

HttpRequest req = new HttpRequest();
        req.setEndpoint('https://citirel--sfdc.cs3.my.salesforce.com/services/apexrest/ZLead');
        req.setMethod('POST');
        req.setBody(json);
        Http h = new Http();
        HttpResponse res = h.send(req);
        
        System.assert(json != null);
    }
    }

This is the latest version I've tried. I've also tried to use the HTTPMockCallout as well with still 0% coverage.
Himanshu ParasharHimanshu Parashar
Hi Amanda,

I think you should use RestRequest class to send request. you can try following code
 
@isTest (SeeAllData = true)
private class testZAPI {

  static testMethod void testDoPOST() {

 String json='{"sender": {"lastName": "Testing", "phoneNumber": "(206) 402-4568", "emailAddress": "superadmin@tes.com", "firstName": "Joe"}, '+

        '"created": "2014-12-30T10:31:00-08:00","recipient": {"firstName": "testing", "lenderId": "ZUzr6lkkilfhu1_aj9j7", "nmlsLicense": "399802", "phoneNumber": "(888) 871-7291", "emailAddress": "40030557@tes.zillow.local"}, "price": 0,"details": {"message": "Please contact me."}, "type": "simple", "id": "LC-CWDXZJL"}'+ '';

    RestRequest req = new RestRequest(); 
    RestResponse res = new RestResponse();

    // pass the req and resp objects to the method     
    req.requestURI = 'https://citirel--sfdc.cs3.my.salesforce.com/services/apexrest/ZLead';  
    req.httpMethod = 'POST';
    req.requestBody = Blob.valueof(json);

    resp = ZRestAPI.createLead(req);
    system.debug(resp);
    

  }

}


Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
 
AmandaSilberAmandaSilber
Thank you Himanshu!

I have actually tried that way before, but I end up with this error:

 Compile Error: Method does not exist or incorrect signature: ZRestAPI.createLead(RestRequest) at line 16 column 12

Do you know what would cause that??
Himanshu ParasharHimanshu Parashar
Can you first make sure to run this code from console ? I am asusming that your class added in guest profile ?
AmandaSilberAmandaSilber
Himanshu, thank you so much for helping and your quick responses, I reallly appreciate it!

Yes, the class has been added. I ran from console with same error. 
Himanshu ParasharHimanshu Parashar
Hi Amanda,

In your scenerio I see following options to solve this issue. Pass the rest of the objects as I did for Sender Class. it will surely,

 
ZRestAPI.Sender send= new ZRestAPI.Sender();
send.lastName='User';
send.firstName='Demo';
send.phoneNumber='';
send.emailAddress='test@test.com';



String str = ZRestAPI.createLead(send,details,type,Stringid,created,recipient,price,quote,arm,z,fees);
system.debug(str);


Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
 
This was selected as the best answer