Guest User

Untitled

a guest
Mar 6th, 2018
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. @RestResource(urlMapping='/IntershopRelatedAccounts/*')
  2. //beginning of 1
  3. global class IntershopInboundRestTofetchContacts {
  4. @HttpGet
  5. global static void fetchRelatedAccountswithContacts(){
  6. String emailstr = RestContext.request.params.get('Email');
  7.  
  8.  
  9. // Search contacts
  10. List<Contact> cont = [ Select Id, Name, Email,AccountId,Current_Employee__c,Ecommerce_User__c,MailingCountry from Contact where Email=:emailstr ];
  11.  
  12. // When contact does not exists
  13. if(cont.size()==0){
  14. List<String> sendTo = new List<String>();
  15. Email_Notify__c emailaddress = Email_Notify__c.getValues('InboundEmailId');
  16. Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
  17. sendTo.add(emailaddress.EmailId__c);
  18. email.setSubject('Regarding creation of Accounts and Contacts ');
  19. email.setToAddresses(sendTo);
  20. email.setPlainTextBody('kindly create accounts and contacts');
  21. Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
  22.  
  23. }
  24.  
  25. @isTest
  26. public class Test_IntershopInboundRest {
  27. public static testMethod void Test_1(){
  28.  
  29.  
  30. RestRequest req = new RestRequest();
  31. RestResponse res = new RestResponse();
  32.  
  33. // pass the req and resp objects to the method
  34. req.requestURI = 'https://danaherlbs--test.cs86.my.salesforce.com/services/apexrest/IntershopRelatedAccounts?Email=vineet@gmail.com';
  35. req.httpMethod = 'GET';
  36. req.addHeader('Content-Type', 'application/json');
  37. RestContext.request = req;
  38. RestContext.response = res;
  39. string emailstr = req.params.get('Email');
  40. List<string> sendto = new List<string>();
  41. Account a= new Account();
  42. a.name='account';
  43. a.SAP_Account_Number__c='569';
  44. a.Inactive__c=false;
  45. insert a;
  46. contact c= new contact();
  47. c.LastName='vineet';
  48. c.AccountId=a.Id;
  49. c.MailingCountry ='India';
  50. c.Current_Employee__c=true;
  51. c.Ecommerce_User__c=false;
  52. c.Email='james@gmail.com';
  53. insert c;
  54. List<Contact> conlst=[select id ,Email from contact where Email=:emailstr];
  55.  
  56. if(conlst.size()==0){
  57. Email_Notify__c emailnotify = new Email_Notify__c();
  58. emailnotify.Name='james';
  59. emailnotify.EmailId__c='james@gmail.com';
  60. insert emailnotify;
  61. Email_Notify__c emailcustset=[select Id, EmailId__c from Email_Notify__c where Id=:emailnotify.Id];
  62. system.debug('11111'+emailcustset.EmailId__c);
  63.  
  64. Test.startTest();
  65.  
  66.  
  67. IntershopInboundRestTofetchContacts.fetchRelatedAccountswithContacts();
  68.  
  69.  
  70. Test.stopTest();
  71. }
  72.  
  73. }
  74. }
  75.  
  76. The code is failing at this line
  77. 'sendTo.add(emailaddress.EmailId__c);'
  78. Error:- Attempt to de-reference the null object.
Add Comment
Please, Sign In to add comment