• Beth Gonzalez 3
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
I am in the process of creating a custom javascript that appears on a opportunity list view. However when I test the button, I recieve the following error: Error in Opportunity Creation = Type Error:sforce.connection.insert is not a function?

The code I am using, I found in the forum and I modified. I am not sure how to resolve the error. I am not a developer. I appeciate the help. 
 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")};
var url = parent.location.href;
var records = {!GETRECORDIDS($ObjectType.Opportunity)};
var CreateNewRecords = []; 
try
{

if (records[0] == null)
{
	alert("Please select at least one record to update.");
} 
else
 {
	for (var a=0; a<records.length; a++) 
	{
		var create_new_opportunity = new sforce.SObject("opportunity");
		create_new_opportunity.RecordTypeId = "012a0000001ZUXg"; 
		create_new_opportunity.AccountId = "{!Opportunity.Account}"; 
		create_new_opportunity.Closedate =new Date("{TODAYY()}");
		create_new_opportunity.OwnerId = "{!Opportunity.OwnerId}";   
		create_new_opportunity.StageName= "Info Gathering/Investigation";
                create_new_opportunity.Strategy_Type__c= "Full Launch Target";
		CreateNewRecords.push(create_new_opportunity);
	}
var result = sforce.connection.insert(CreateNewRecords);
if (result[0].success=='false')
{
	alert(result[0].errors.message);
}
elese
{
	location.reload(true);
}

}
}
catch(error)
{
alert("Error In Opportunity creation  = "+error);
}

 
I am trying to determine if it is possible to create interactive map of opportunities using google maps? If yes, how would I go about building it?

I found some code in the developer forum (see below) is this somethiing I can use to create what I need?
 
<apex:page standardController="Opportunity">
<apex:pageBlock >
<head>
 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
<script type="text/javascript"> 
 
$(document).ready(function() {
  
  var myOptions = {
    zoom: 20,
    mapTypeId: google.maps.MapTypeId.HYBRID,
    mapTypeControl: true
  }
  
  var map;
  var marker;
  
  var geocoder = new google.maps.Geocoder();
  var address = "{!Opportunity.Account.ShippingStreet}, " + "{!Opportunity.Account.ShippingCity}, " + "{!Opportunity.Account.ShippingCountry}";
  
  var infowindow = new google.maps.InfoWindow({
    content: "<b>{!Opportunity.Account.Name}</b><br>{!Opportunity.Account.ShippingStreet}<br>{!Opportunity.Account.ShippingCity}, {!Opportunity.Account.ShippingPostalCode}<br>{!Opportunity.Account.ShippingCountry}</b>"
  });
 
  geocoder.geocode( { address: address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK && results.length) {
      if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
      
        //create map
        map = new google.maps.Map(document.getElementById("map"), myOptions);
      
        //center map
        map.setCenter(results[0].geometry.location);
        
        //create marker
        marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map,
            title: "{!Opportunity.Account.Name}"
        });
        
        //add listeners
        google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map,marker);
        });
        google.maps.event.addListener(infowindow, 'closeclick', function() {
          map.setCenter(marker.getPosition()); 
        });
        
      }
      
    } else {
      $('#map').css({'height' : '15px'});
      $('#map').html("Oops! {!Opportunity.Account.Name}'s address could not be found, please make sure the address is correct.");
      resizeIframe();
    }
  });
  
  function resizeIframe() {
    var me = window.name;
    if (me) {
      var iframes = parent.document.getElementsByName(me);
      if (iframes && iframes.length == 1) {
        height = document.body.offsetHeight;
        iframes[0].style.height = height + "px";
      }
    }
  }
  
});
</script>
 
<style>
#map {
  font-family: Arial;
  font-size:12px;
  line-height:normal !important;
  height:500px;
  background:transparent;
  }
</style>
 
</head>
 
<body>
<div id="map"></div> 
</body> 
</apex:pageBlock>
</apex:page>