Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String geolocation { get; set; }
- public String text { get; set; }
- public String error { get; set; }
- public Id accid = ApexPages.CurrentPage().getparameters().get('id');
- public void checkin()
- {
- // Check if geolocation found or not
- if(geolocation==null || geolocation.length()<8)
- {
- error = 'Unable to retreive location';
- return;
- }
- if(text == null || text.trim().length()==0)
- {
- error = 'Nothing to post';
- return;
- }
- try
- {
- // Post to chatter of current user
- FeedItem post = new FeedItem();
- post.ParentId = Userinfo.getUserId();
- post.Body = text;
- post.ParentId = accid;
- post.Type = 'LinkPost';
- post.LinkUrl = 'http://maps.google.com/maps?q=' + geolocation;
- insert post;
- error = 'Posted Successfully !';
- //post to account activity history
- Task myTask = new Task();
- myTask.WhatId = accid;
- myTask.OwnerId= UserInfo.GetUserId();
- myTask.Status = 'Completed';
- myTask.Subject = 'On-Site Check In';
- myTask.Description = text +' - http://maps.google.com/maps?q='+geolocation;
- myTask.Priority = 'Normal';
- myTask.ActivityDate = date.today();
- insert myTask;
- }
- catch(Exception ex)
- {
- error = ex.getMessage();
- }
- //return null;
- }
- static testMethod void myUnitTest()
- {
- // insert test account
- Account testaccount = new Account(name = 'pt Abc', AccountNumber='123456');
- insert testaccount;
- AccountCheckInController2 controller = new AccountCheckInController2();
- //Test.startTest();
- PageReference ref = Page.AccountCheckin2;
- ApexPages.currentPage().getParameters().put('id', testaccount.Id);
- ApexPages.currentPage().getParameters().put('geolocation','-6.228693,106.8248041');
- ApexPages.currentPage().getParameters().put('text','test checkin');
- Test.setCurrentPage(ref);
- //Test.stopTest();
- controller.checkin();
- }
- // Check if geolocation found or not
- if(geolocation==null || geolocation.length()<8)
- {
- error = 'Unable to retreive location';
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement