• sawaji varun
  • NEWBIE
  • 5 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 6
    Replies
I am able to create the task, If I click the custom button that task should be added to activities in account. How to do it. Please any one help me on this.The Code is given below

VF Page:

<apex:page standardController="Task" extensions="CBD_SendSMS" sidebar="false" >
<apex:form >
  <apex:pageBlock >
 
<apex:pageBlockSection columns="2">
 <apex:inputfield value="{!tsk.Mobile_Number__c}"/>
 <apex:inputTextarea value="{!tsk.SMS_Description__c}"/>
 <!--<apex:inputField value="{!tsk.Lead_Lookup__c}"/>
  <apex:inputField value="{!tsk.Account_Lookup__c}"/>
   <apex:inputField value="{!tsk.Opportunity_Lookup__c}"/>-->
 </apex:pageBlockSection>
      <apex:commandButton value="Send SMS" action="{!sendSMS}" style="margin-left:600px;width=50px;height=30px" reRender="">
          <apex:param id="someId" name="accountID" value="{$account.id}"/>
      </apex:commandButton>
 <apex:outputText value="{!Account.Id}"></apex:outputText>
 </apex:pageBlock>
</apex:form>
</apex:page>
____________________________
public with sharing class CBD_SendSMS {
 
 public Task tsk{
    get {
      if (tsk == null)
        tsk = new Task();
      return tsk;
    }
    set;
    }
    
  // public Account acc{ get;set;}

public PageReference sendSMS() {
          
        
        
        
       
        
        
         // Integer fPhone=tsk.Mobile_Number__c;
        //  if (fphone.length() != 10) {
         // tsk.addError('Error1');
       //   }
         Id id1= System.currentPageReference().getParameters().get('accountID');
       //  System.debug('ID Dispalys' +Id);
     System.debug('ID Dispalys' +id1);
         
        tsk.WhatId = id1;
    //   tsk.RecordtypeId = '012p00000004O5k';
       //tsk.WhoId=userInfo.getUserId();
         insert tsk;
        pageReference pageref= new pageReference('/' + tsk.Id);
        Task tsk = new Task();
        return pageref;
    }
    
    
 
  public CBD_SendSMS(ApexPages.StandardController controller)
 
  {
 
 
  this.tsk = (Account)Controller.getRecord();

}
}
 
I have ceated to fields Mobile Number and SMS Description using VF Page. I'm able to create the task, When I click the button submit, these to field details added to activities in account. How to do it.Please anybody help me on this.
 
Simple Example using SOAP step by step. Anybody suggests on this
I have created the Lookup field for activity on Lead. If I click the submit button that should be added to activity in lead. How to do it?
How to develop program for sending sms using apex and visualforce.
How to enable or disable the textfield when selecting item from picklist on the standard page like leads, accounts etc.
I'm able to track current location latitude and Longitude. I want to display the address on the basis of latitude and Longitude. How to achieve it. The code is given below. I have created the one geolocation field and address as text field.

LocatorPage.vfp

<apex:page StandardController="Task" showHeader="true" sidebar="false" extensions="visitController">

<script>

var pos = {};
function success(position) {

  pos = position.coords;
  console.log(pos);
}

function error(msg) {
console.log(msg);
}

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(success, error);
} else {
  error('not supported');
}

function setPos() {
    var inputs = document.getElementsByTagName('input');
    for(var x = 0; x < inputs.length; x++) {
        if(inputs[x].id.indexOf('contactlat') >= 0) { inputs[x].value = pos.latitude; }
        if(inputs[x].id.indexOf('contactlong') >= 0) { inputs[x].value = pos.longitude; }
        if(inputs[x].id.indexOf('contactaddress') >= 0) { inputs[x].value = address; }
    }
}


visitController.apxp

public class visitController { 

    public Task tsk{
    get {
      if (tsk == null)
        tsk = new Task();
      return tsk;
    }
    set;
    }
    public Opportunity opp {get;set;}
    
    public visitController(ApexPages.StandardController controller) {
        this.tsk = (Task)Controller.getRecord();
        tsk.Id = System.currentPageReference().getParameters().get('Id');
    }

    public PageReference save() {
        //tsk.WhatId = opp.Id;
        insert tsk;
        pageReference pageref= new pageReference('/' + tsk.Id);
        Task tsk = new Task();
        return pageref;
    }
}
Hi, I have created a custom button 'Checkin' on opportunity and below is the javascript for this. on cllick of the button, its creating a task under opportunity by saving checkin logtitude latitude.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 

var tsk = new sforce.SObject('Task'); 


tsk.WhatId = '{!Opportunity.Id}'; 
tsk.subject = 'Subject1'; 

if(navigator.geolocation){ 
//browser support geolocation 
navigator.geolocation.getCurrentPosition(callbackSuccess, callbackError,{enableHighAccuracy:true,timeout:3000}); 

}else{ 
alert('Navigation is not supported'); 


function callbackSuccess(position) { 

//get latitude and longitude 
var lat = position.coords.latitude; 
var lon = position.coords.longitude; 

tsk.Checkin_Geolocation__Latitude__s=lat; 
tsk.Checkin_Geolocation__Longitude__s=lon; 
sforce.connection.create([tsk]); 

window.location.reload(); 


function callbackError(error) { 
switch(error.code) { 
case error.UNKNOWN_ERROR: 
alert("UNKNOWN_ERROR."); 
break; 
case error.PERMISSION_DENIED: 
alert("PERMISSION_DENIED."); 
break; 
case error.POSITION_UNAVAILABLE: 
alert("POSITION_UNAVAILABLE."); 
break; 
case error.TIMEOUT: 
alert("TIMEOUT."); 
break; 

}


I am unable to see this button in salesforce1 app in mobile. Any solution for this.? Alternatively, how can we write this in visualforce page.
I'm able to track the address and display it, Now I want to save it into text.The code is given below

<apex:page > <html> <head> <meta charset="UTF-8" /> <title>Geolocation and Google Maps API</title> <script src="http://maps.google.com/maps/api/js?sensor=true"></script> <script> function writeAddressName(latLng) { var geocoder = new google.maps.Geocoder(); geocoder.geocode({ "location": latLng }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) document.getElementById("address").innerHTML = results[0].formatted_address; else document.getElementById("error").innerHTML += "Unable to retrieve your address" + "<br />"; }); } function geolocationSuccess(position) { var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); // Write the formatted address writeAddressName(userLatLng); var myOptions = { zoom : 16, center : userLatLng, mapTypeId : google.maps.MapTypeId.ROADMAP }; // Draw the map var mapObject = new google.maps.Map(document.getElementById("map"), myOptions); // Place the marker new google.maps.Marker({ map: mapObject, position: userLatLng }); // Draw a circle around the user position to have an idea of the current localization accuracy var circle = new google.maps.Circle({ center: userLatLng, radius: position.coords.accuracy, map: mapObject, fillColor: '#0000FF', fillOpacity: 0.5, strokeColor: '#0000FF', strokeOpacity: 1.0 }); mapObject.fitBounds(circle.getBounds()); } function geolocationError(positionError) { document.getElementById("error").innerHTML += "Error: " + positionError.message + "<br />"; } function geolocateUser() { // If the browser supports the Geolocation API if (navigator.geolocation) { var positionOptions = { enableHighAccuracy: true, timeout: 10 * 1000 // 10 seconds }; navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, positionOptions); } else document.getElementById("error").innerHTML += "Your browser doesn't support the Geolocation API"; } window.onload = geolocateUser; </script> <style type="text/css"> #map { width: 500px; height: 500px; } </style> </head> <body> <h1>Basic example</h1> <div id="map"></div> <p><b>Address</b>: <span id="address"></span></p> <p id="error"></p> </body> </html> </apex:page>
<apex:page >
<script src="http://www.google.com/jsapi?key=ABQIAAAAlJFc1lrstqhgTl3ZYo38bBQcfCcww1WgMTxEFsdaTsnOXOVOUhTplLhHcmgnaY0u87hQyd-n-kiOqQ"></script>
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<html>
<body>
<p id="demo">Click the button to get your position.</p>
 
<button onclick="getLocation()">Check-In</button>
 
<div id="mapholder"></div>
 
<script>
var x = document.getElementById("demo");
 
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition, showError);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
 
function showPosition(position) {
    alert('some');
    var latlon = position.coords.latitude + "," + position.coords.longitude;
        var img_url = "http://maps.googleapis.com/maps/api/staticmap?center="
    +latlon+"&zoom=14&size=400x300&sensor=false";
    document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>";
}
 
function showError(error) {
    switch(error.code) {
        case error.PERMISSION_DENIED:
            x.innerHTML = "User denied the request for Geolocation."
            break;
        case error.POSITION_UNAVAILABLE:
            x.innerHTML = "Location information is unavailable."
            break;
        case error.TIMEOUT:
            x.innerHTML = "The request to get user location timed out."
            break;
        case error.UNKNOWN_ERROR:
            x.innerHTML = "An unknown error occurred."
            break;
    }
}
</script>
 
 
<p id="demo1">Click the button to get your position.</p>
 
<button onclick="getLocation1()">Check-Out</button>
 
<div id="mapholder1"></div>
 
<script>
 
 
function getLocation1() {
var x1 = document.getElementById("demo1");
 
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition1, showError1);
    } else {
        x1.innerHTML = "Geolocation is not supported by this browser.";
       
    }
}
 
function showPosition1(position) {
alert('here');
    var latlon1 = position.coords.latitude + "," + position.coords.longitude;
   
    var img_url1 = "http://maps.googleapis.com/maps/api/staticmap?center="
    +latlon1+"&zoom=14&size=400x300&sensor=false";
    document.getElementById("mapholder1").innerHTML = "<img src='"+img_url1+"'>";
}
 
function showError1(error) {
    switch(error.code) {
        case error.PERMISSION_DENIED:
            x1.innerHTML = "User denied the request for Geolocation."
            break;
        case error.POSITION_UNAVAILABLE:
            x1.innerHTML = "Location information is unavailable."
            break;
        case error.TIMEOUT:
            x1.innerHTML = "The request to get user location timed out."
            break;
        case error.UNKNOWN_ERROR:
            x1.innerHTML = "An unknown error occurred."
            break;
    }
}
</script>
 
</body>
</html>
 
</apex:page>


Hi, Now it is working like, On click of checkin and checkout it is displaying the current location in the map. Also latitude and longitude are stored in latlong variable. However i also want to display the current location's physical address. Please help me out.

Thanks
 
How to Create and Manage quote
How to create custom login page and How to write the Test class for it. The page conatins the fields username and password. If success go to next page else redirects to same login page
What is the best way to do this either code or configuration.
I have created a report in lightning, when I'm searching in dashborad from drop down to create chart, It displays the Unsupported Type.
I have created report in lightning and now I want generate dashboard, when I selecting the earlier report from drop down, shows Unsupported Type error. please guide on this
AccountsController.apxc
public class AccountsController {
    @AuraEnabled public static Account          getAccount(){
        return (Account) Database.query( ' SELECT Name,Type,NumberOfEmployees,TickerSymbol,Phone FROM Account  ' )[0];
    }
    @AuraEnabled public static Account          saveAccount(Account account){
        upsert account;
        return account;
    } 
}

AccountsListController.js
({
    init : function(component, event, helper) {
        console.log('init');
        var action2 = component.get("c.getAccount");        
        action2.setCallback(this, function(response) {
            console.log(response.getReturnValue());
            component.set("v.account", response.getReturnValue());
        });
        $A.enqueueAction(action2);
    }, 
    save : function(component, event, helper) {
        console.log('save:1');
        var action = component.get("c.saveAccount");
        var account = component.get("v.account");
        action.setParams({"account": account});
        action.setCallback(this, function() {  console.log('SAVED.');  } );
        $A.enqueueAction(action);
        console.log('save:end');
    },
})

({
   //Fetch the accounts from the Apex controller
  getAccountList: function(component) {
    var action = component.get("c.getAccounts");

    //Set up the callback
    var self = this;
    action.setCallback(this, function(actionResult) {
        component.set("v.accounts", actionResult.getReturnValue());            
    });
    $A.enqueueAction(action);
  }   
})

AccountList.cmp
<aura:component controller="AccountsController" implements="forceCommunity:availableForAllPageTypes">
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <aura:attribute name="account"  type="Account" />
    <h1>Test</h1>
    <form>
         
        <ui:inputText aura:id="client"
            label="{!$ObjectType.Account.fields.Name.Label}"
            class="form-control"
            value="{!v.account.Name}"
            placeholder="Name"
        />
        <ui:inputText aura:id="client"
            label="{!$ObjectType.Account.fields.Type.Label}"
            class="form-control"
            value="{!v.account.Type}"
            placeholder="Type"
        />
        <ui:inputText aura:id="client"
            label="{!$ObjectType.Account.fields.NumberOfEmployees.Label}"
            class="form-control"
            value="{!v.account.NumberOfEmployees}"
            placeholder="NumberOfEmployees"
        />
        <ui:inputText aura:id="client"
            label="{!$ObjectType.Account.fields.TickerSymbol.Label}"
            class="form-control"
            value="{!v.account.TickerSymbol}"
            placeholder="TickerSymbol"
        />
        <ui:inputText aura:id="client"
            label="{!$ObjectType.Account.fields.Phone.Label}"
            class="form-control"
            value="{!v.account.Phone}"
            placeholder="Phone"
        />
        <br />
        <ui:button class="form-control" aura:id="button" label="Save" press="{!c.save}"/>
        <br />
    <br />
       
    </form>
</aura:component>
 
Hi, I have created a custom button 'Checkin' on opportunity and below is the javascript for this. on cllick of the button, its creating a task under opportunity by saving checkin logtitude latitude.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 

var tsk = new sforce.SObject('Task'); 


tsk.WhatId = '{!Opportunity.Id}'; 
tsk.subject = 'Subject1'; 

if(navigator.geolocation){ 
//browser support geolocation 
navigator.geolocation.getCurrentPosition(callbackSuccess, callbackError,{enableHighAccuracy:true,timeout:3000}); 

}else{ 
alert('Navigation is not supported'); 


function callbackSuccess(position) { 

//get latitude and longitude 
var lat = position.coords.latitude; 
var lon = position.coords.longitude; 

tsk.Checkin_Geolocation__Latitude__s=lat; 
tsk.Checkin_Geolocation__Longitude__s=lon; 
sforce.connection.create([tsk]); 

window.location.reload(); 


function callbackError(error) { 
switch(error.code) { 
case error.UNKNOWN_ERROR: 
alert("UNKNOWN_ERROR."); 
break; 
case error.PERMISSION_DENIED: 
alert("PERMISSION_DENIED."); 
break; 
case error.POSITION_UNAVAILABLE: 
alert("POSITION_UNAVAILABLE."); 
break; 
case error.TIMEOUT: 
alert("TIMEOUT."); 
break; 

}


I am unable to see this button in salesforce1 app in mobile. Any solution for this.? Alternatively, how can we write this in visualforce page.
I have ceated to fields Mobile Number and SMS Description using VF Page. I'm able to create the task, When I click the button submit, these to field details added to activities in account. How to do it.Please anybody help me on this.
 
How to develop program for sending sms using apex and visualforce.
How to Create and Manage quote
How to create custom login page and How to write the Test class for it. The page conatins the fields username and password. If success go to next page else redirects to same login page
AccountsController.apxc
public class AccountsController {
    @AuraEnabled public static Account          getAccount(){
        return (Account) Database.query( ' SELECT Name,Type,NumberOfEmployees,TickerSymbol,Phone FROM Account  ' )[0];
    }
    @AuraEnabled public static Account          saveAccount(Account account){
        upsert account;
        return account;
    } 
}

AccountsListController.js
({
    init : function(component, event, helper) {
        console.log('init');
        var action2 = component.get("c.getAccount");        
        action2.setCallback(this, function(response) {
            console.log(response.getReturnValue());
            component.set("v.account", response.getReturnValue());
        });
        $A.enqueueAction(action2);
    }, 
    save : function(component, event, helper) {
        console.log('save:1');
        var action = component.get("c.saveAccount");
        var account = component.get("v.account");
        action.setParams({"account": account});
        action.setCallback(this, function() {  console.log('SAVED.');  } );
        $A.enqueueAction(action);
        console.log('save:end');
    },
})

({
   //Fetch the accounts from the Apex controller
  getAccountList: function(component) {
    var action = component.get("c.getAccounts");

    //Set up the callback
    var self = this;
    action.setCallback(this, function(actionResult) {
        component.set("v.accounts", actionResult.getReturnValue());            
    });
    $A.enqueueAction(action);
  }   
})

AccountList.cmp
<aura:component controller="AccountsController" implements="forceCommunity:availableForAllPageTypes">
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <aura:attribute name="account"  type="Account" />
    <h1>Test</h1>
    <form>
         
        <ui:inputText aura:id="client"
            label="{!$ObjectType.Account.fields.Name.Label}"
            class="form-control"
            value="{!v.account.Name}"
            placeholder="Name"
        />
        <ui:inputText aura:id="client"
            label="{!$ObjectType.Account.fields.Type.Label}"
            class="form-control"
            value="{!v.account.Type}"
            placeholder="Type"
        />
        <ui:inputText aura:id="client"
            label="{!$ObjectType.Account.fields.NumberOfEmployees.Label}"
            class="form-control"
            value="{!v.account.NumberOfEmployees}"
            placeholder="NumberOfEmployees"
        />
        <ui:inputText aura:id="client"
            label="{!$ObjectType.Account.fields.TickerSymbol.Label}"
            class="form-control"
            value="{!v.account.TickerSymbol}"
            placeholder="TickerSymbol"
        />
        <ui:inputText aura:id="client"
            label="{!$ObjectType.Account.fields.Phone.Label}"
            class="form-control"
            value="{!v.account.Phone}"
            placeholder="Phone"
        />
        <br />
        <ui:button class="form-control" aura:id="button" label="Save" press="{!c.save}"/>
        <br />
    <br />
       
    </form>
</aura:component>