Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RestResource(urlMapping='/IntershopRelatedAccounts/*')
- //beginning of 1
- global class IntershopInboundRestTofetchContacts {
- @HttpGet
- global static void fetchRelatedAccountswithContacts(){
- String emailstr = RestContext.request.params.get('Email');
- // Search contacts
- List<Contact> cont = [ Select Id, Name, Email,AccountId,Current_Employee__c,Ecommerce_User__c,MailingCountry from Contact where Email=:emailstr ];
- // When contact does not exists
- if(cont.size()==0){
- List<String> sendTo = new List<String>();
- Email_Notify__c emailaddress = Email_Notify__c.getValues('InboundEmailId');
- Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
- sendTo.add(emailaddress.EmailId__c);
- email.setSubject('Regarding creation of Accounts and Contacts ');
- email.setToAddresses(sendTo);
- email.setPlainTextBody('kindly create accounts and contacts');
- Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
- }
- @isTest
- public class Test_IntershopInboundRest {
- public static testMethod void Test_1(){
- RestRequest req = new RestRequest();
- RestResponse res = new RestResponse();
- // pass the req and resp objects to the method
- req.requestURI = 'https://danaherlbs--test.cs86.my.salesforce.com/services/apexrest/IntershopRelatedAccounts?Email=vineet@gmail.com';
- req.httpMethod = 'GET';
- req.addHeader('Content-Type', 'application/json');
- RestContext.request = req;
- RestContext.response = res;
- string emailstr = req.params.get('Email');
- List<string> sendto = new List<string>();
- Account a= new Account();
- a.name='account';
- a.SAP_Account_Number__c='569';
- a.Inactive__c=false;
- insert a;
- contact c= new contact();
- c.LastName='vineet';
- c.AccountId=a.Id;
- c.MailingCountry ='India';
- c.Current_Employee__c=true;
- c.Ecommerce_User__c=false;
- c.Email='james@gmail.com';
- insert c;
- List<Contact> conlst=[select id ,Email from contact where Email=:emailstr];
- if(conlst.size()==0){
- Email_Notify__c emailnotify = new Email_Notify__c();
- emailnotify.Name='james';
- emailnotify.EmailId__c='james@gmail.com';
- insert emailnotify;
- Email_Notify__c emailcustset=[select Id, EmailId__c from Email_Notify__c where Id=:emailnotify.Id];
- system.debug('11111'+emailcustset.EmailId__c);
- Test.startTest();
- IntershopInboundRestTofetchContacts.fetchRelatedAccountswithContacts();
- Test.stopTest();
- }
- }
- }
- The code is failing at this line
- 'sendTo.add(emailaddress.EmailId__c);'
- Error:- Attempt to de-reference the null object.
Add Comment
Please, Sign In to add comment