Guest User

Untitled

a guest
Mar 6th, 2018
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. apex :-
  2.  
  3. @RestResource(urlMapping='/IntershopRelatedAccounts/*')
  4. global class IntershopInboundRestTofetchContacts {
  5. @HttpGet
  6. global static void fetchRelatedAccountswithContacts(){
  7. Id potentialrecordtype =e().get('Existing SAP Account').getRecordTypeId(); Schema.SObjectType.Account.getRecordTypeInfosByName().get('Potential Account').getRecordTypeId();
  8. Id existingSAPrecordtype = Schema.SObjectType.Account.getRecordTypeInfosByNam
  9. Boolean flag1;
  10. Boolean flag2;
  11. Boolean flag3;
  12. Boolean flag4;
  13. Map<string,string> countrymap = new Map<string,string>();
  14. Map<string,string> inactivecountrymap = new Map<string,string>();
  15.  
  16. List<contact> inactivecontacts = new List<Contact>();
  17. set<Id> accidsforActiveContacts = new Set<Id>();
  18. set<Id> accidsforInActiveContacts = new Set<Id>();
  19. // searching for active contacts
  20. for(Contact c: [ Select Id, Name, Email,AccountId,Current_Employee__c,Ecommerce_User__c,MailingCountry from Contact where Email=:emailstr AND Current_Employee__c=:true AND Ecommerce_User__c=:false ]){
  21. accidsforActiveContacts.add(c.AccountId);
  22. if(c.MailingCountry!=null) {
  23. countrymap.put(c.MailingCountry, c.MailingCountry);
  24. }
  25. }
  26. }
  27.  
  28. Test class code coverage:---
  29.  
  30. @isTest
  31. public class Test_IntershopInboundRest {
  32. public static testMethod void Test_1(){
  33.  
  34.  
  35. RestRequest req = new RestRequest();
  36. RestResponse res = new RestResponse();
  37.  
  38. // pass the req and resp objects to the method
  39. req.requestURI = 'https://danaherlbs--test.cs86.my.salesforce.com/services/apexrest/IntershopRelatedAccounts?Email=vineet@gmail.com';
  40. req.httpMethod = 'GET';
  41. req.addHeader('Content-Type', 'application/json');
  42. RestContext.request = req;
  43. RestContext.response = res;
  44. string emailstr = req.params.get('Email');
  45. List<string> sendto = new List<string>();
  46. Account a= new Account();
  47. a.name='account';
  48. a.SAP_Account_Number__c='569';
  49. a.Inactive__c=false;
  50. insert a;
  51. contact c= new contact();
  52. c.LastName='james';
  53. c.AccountId=a.Id;
  54. c.MailingCountry ='India';
  55. c.Current_Employee__c=true;
  56. c.Ecommerce_User__c=false;
  57. c.Email='james@gmail.com';
  58. insert c;
  59. List<Contact> conlst=[select id ,Email from contact where Email=:emailstr];
  60.  
  61. if(conlst.size()>1){
  62.  
  63. Email_Notify__c emailnotify = new Email_Notify__c();
  64. emailnotify.Name='InboundEmailId';
  65. emailnotify.EmailId__c='james@gmail.com';
  66. insert emailnotify;
  67. Email_Notify__c emailcustset=[select Id, EmailId__c from Email_Notify__c where Id=:emailnotify.Id];
  68. system.debug('11111'+emailcustset.EmailId__c);
  69.  
  70.  
  71. IntershopInboundRestTofetchContacts.fetchRelatedAccountswithContacts();
  72.  
  73.  
  74.  
  75.  
  76. }
  77.  
  78. hi all, the code is not getting covered ,please help.
Add Comment
Please, Sign In to add comment