Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. public String geolocation { get; set; }
  2. public String text { get; set; }
  3. public String error { get; set; }
  4. public Id accid = ApexPages.CurrentPage().getparameters().get('id');
  5.  
  6. public void checkin()
  7. {
  8. // Check if geolocation found or not
  9. if(geolocation==null || geolocation.length()<8)
  10. {
  11. error = 'Unable to retreive location';
  12. return;
  13. }
  14.  
  15. if(text == null || text.trim().length()==0)
  16. {
  17. error = 'Nothing to post';
  18. return;
  19. }
  20.  
  21. try
  22. {
  23. // Post to chatter of current user
  24. FeedItem post = new FeedItem();
  25. post.ParentId = Userinfo.getUserId();
  26. post.Body = text;
  27. post.ParentId = accid;
  28. post.Type = 'LinkPost';
  29. post.LinkUrl = 'http://maps.google.com/maps?q=' + geolocation;
  30. insert post;
  31. error = 'Posted Successfully !';
  32.  
  33. //post to account activity history
  34. Task myTask = new Task();
  35. myTask.WhatId = accid;
  36. myTask.OwnerId= UserInfo.GetUserId();
  37. myTask.Status = 'Completed';
  38. myTask.Subject = 'On-Site Check In';
  39. myTask.Description = text +' - http://maps.google.com/maps?q='+geolocation;
  40. myTask.Priority = 'Normal';
  41. myTask.ActivityDate = date.today();
  42. insert myTask;
  43. }
  44. catch(Exception ex)
  45. {
  46. error = ex.getMessage();
  47. }
  48. //return null;
  49. }
  50.  
  51. static testMethod void myUnitTest()
  52. {
  53.  
  54. // insert test account
  55. Account testaccount = new Account(name = 'pt Abc', AccountNumber='123456');
  56. insert testaccount;
  57. AccountCheckInController2 controller = new AccountCheckInController2();
  58.  
  59. //Test.startTest();
  60. PageReference ref = Page.AccountCheckin2;
  61. ApexPages.currentPage().getParameters().put('id', testaccount.Id);
  62. ApexPages.currentPage().getParameters().put('geolocation','-6.228693,106.8248041');
  63. ApexPages.currentPage().getParameters().put('text','test checkin');
  64. Test.setCurrentPage(ref);
  65. //Test.stopTest();
  66.  
  67. controller.checkin();
  68.  
  69.  
  70. }
  71.  
  72. // Check if geolocation found or not
  73. if(geolocation==null || geolocation.length()<8)
  74. {
  75. error = 'Unable to retreive location';
  76. return;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement