• Luca Benedettini 7
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 5
    Replies
Hi,
I create a custom visualforce page where user inserts one value (i.e. Indirizzo__c). Now I want to add a custom button that create an Event (Salesforce standard Object) and fills one field, inside the Event, with the value inserted by the user.
Now I'm using this code:
<apex:commandButton value="new Event" onclick="window.location='/00U/e?Indirizzo__c={!$CurrentPage.parameters.Event.Indirizzo__c}&nooverride=1'; return false;"/>
but it doesn't work, because Indirizzo__c is null instead have the value inserted by the user.
How can i do that?
Hi, I write a visualforce page that have to render all the locations of a bunch of events on a google Map.
Now I'm able to locate one marker on a google page but when I have to put more than one markers my code doesn't work. 
In the first part of the page I take an hardcoded address, I did it becouse I want to center the map on that location in the second part I build a list of address called "listOfAddresses" of the events that i want to render and I pass it to vf page using the controller extension.
If someone could help and tell me where I wrong, it'd be very helpfull.
Here my vf page:
<apex:page standardController="Event" extensions="Active" showHeader="true" sidebar="true">
<apex:form >
<apex:pageBlock title="Evento" id="evento" >
<apex:pageBlockSection title="Inserisci i Dati Dell'evento" collapsible="false" columns="2">
                 <apex:inputField required="true" value="{!Event.Indirizzo__c}"/>
                 <apex:inputField required="true" value="{!Event.Citt__c}"/ >
                 <apex:inputField required="true" value="{!Event.Cap__c}"/ >
                 <apex:inputField required="true" value="{!Event.Regione__c}"/ >
                 <apex:inputField required="true" value="{!Event.StartDateTime}"/ >
                 <apex:inputField value="{!Event.Subject}"/ >
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:commandButton action="{!cerca}" value="Cerca" rerender="mapGoogle"/>
</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
<apex:pageBlock title="Google map" id="mapGoogle" >

<apex:pageBlockSection title="Eventi collegati" id="eventi" collapsible="false" columns="1" >
<apex:pageblockTable value="{!eventconnected}" var="ev">
                <apex:column value="{!ev.Owner.Name}"/>
                <apex:column value="{!ev.Indirizzo__c}"/>
                <apex:column value="{!ev.Citt__c}"/>
                <apex:column value="{!ev.Cap__c}"/>
                <apex:column value="{!ev.Regione__c}"/>
                <apex:column value="{!ev.StartDateTime}"/>
                <apex:column value="{!ev.EndDateTime }"/>
                <apex:column value="{!ev.Subject}"/>                    
</apex:pageblockTable>
</apex:pageBlockSection>

<apex:pageBlockSection title="Mappa Eventi">
  
<head>
<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>
<script type="text/javascript">
$(document).ready(function() {
 
  var myOptions = {
    zoom: 18,
    mapTypeId: google.maps.MapTypeId.HYBRID,
    mapTypeControl: true
  }
  //create map
  var map= new google.maps.Map(document.getElementById("map"), myOptions);;
  var marker;
  var markerBounds = new google.maps.LatLngBounds();
  var geocoder = new google.maps.Geocoder();
  var address = "{!Event.Indirizzo__c}, " + "{!Event.Citt__c}, " + "{!Event.Cap__c}";
  var addressArray ="{!listOfAddresses}" ;
  
 
   var infowindow = new google.maps.InfoWindow({
    content: "<b>Event Locator</b>"
  });

  geocoder.geocode( { address: address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK && results.length) {
      if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {    
        //center map
        map.setCenter(results[0].geometry.location);
       
        //create marker
        marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map,
            title: "{!Event.Subject}"
        });
       
       
        //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("inserisci un indirizzo sulla mappa e verrà visualizzato");
      resizeIframe();
    }
  });
 
    for (var i = 0; i < addressArray.length; i++) {
        geocoder.geocode( { 'address': addressArray[i]}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location
                });
                markerBounds.extend(results[0].geometry.location);
                map.fitBounds(markerBounds);
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });
    }
 
  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>
</apex:pageBlockSection>

<body>
 <div id="map"></div> 
</body>
</apex:pageBlock>
</apex:page>

and this is the controller extension:
public with sharing class Active {
    private final Event evento;
    public List<Event> eventconnected { get; set; }
    public Active(ApexPages.StandardController stdcontroller) {
    this.evento = (Event)stdController.getRecord();
    }
    public List<String> listOfAddresses {get; set;}
    
    
    public void cerca(){
    Date dataevento= evento.StartDateTime.date();
    System.debug(evento.StartDateTime + 'la data è');
    System.debug(dataevento + 'la data è');
    eventconnected=[select Owner.Name,Indirizzo__c, Citt__c,Cap__c,Regione__c,StartDateTime, EndDateTime,Subject 
                   from Event where Indirizzo__c != null And StartDateTime<=:dataevento+1 ];
    System.debug('la lista è'+ eventconnected.size());
    List<String> listOfAddresses = new List<String>();
    for(Event e: eventconnected){
       String indirizzo=e.Indirizzo__c;
       String citt=e.Citt__c;
       String Cap=e.Cap__c;
       string appoggio= indirizzo + ',' + citt + ',' + Cap;
       listOfAddresses.add(appoggio);  
    }
    System.debug('gli indirizzi sono'+ listOfAddresses.size());
     System.debug('gli indirizzi sono'+ listOfAddresses);
    }
}
Hi, I need to view some tasks (i.e. visit a client, a dinner with a partner) of my org like marker on  google maps. There something simil already done, or Can you give me some tips to start programm this feature. Thank you for help me  
I use a process builder after a creation on one case, it has to call an apex class taht update one look up on that record. That is my apex class:
public class SetField{
@InvocableMethod
public static void Set(List<Id> casoid){
Case Caso=[select Id from Case where id=:casoid];
Caso.Working_Status__c='JUST CREATED';
Caso.Environment_Type__c='Production';
ID contratto= [select ID,(select ID from Contracts) from Account where Id=:Caso.AccountID].Contracts.get(0).ID;
caso.Contract_Number__c=contratto;          
}
}
and in the process builder in Set Apex Variables I set:
casoid - ID-CaseId
But constantly I encounter the error : 
Error Occurred: An Apex error occurred: System.QueryException: List has no rows for assignment to SObject.
I need your help to fix this please.


 
Hi , i'm writing a VF page with standardcontroller "Case" but when i use tag <apex:relatedList list="Solutions" /> (or any other object i.e. Atthacments, Emails)  on page Cases, throw an error :
Solutions' is not a valid child relationship name for entity Case.
I don't unaderstand why, I want simply rebuild the releted list on the standard Case page record. Someone could help me please?
 
Hi eveyone. I'm writing a VF page with a controller exstention and i have 2 problems. In my page when you fill the field Merge To Case and click Merge all the attachments of one case need to be reparented.
First Problem Am I passing Merge_To_Case in the right way between VF and CaseControllerExstention.
Second When i click on merge button , it's seems to do nothing and I don't understand why.
I hope you can help me.Here my code:
VF page:
<apex:page standardController="Case" extensions="CaseMergeExtension" showHeader="true" sidebar="false">
<apex:form >

<apex:actionfunction name="MergeCase" action="MergeCase" >
<apex:param name="Casetomerge" value="" assignTo="{!Case.Merge_To_Case__c}" />
</apex:actionFunction>

<apex:sectionHeader description="Case Merging Page" title="Case">
</apex:sectionHeader>
  <apex:pageBlock title="Case To BE Merged {!Case.CaseNumber}">
      <apex:pageBlockButtons location="top">
       <apex:commandButton value="Merge" onClick="MergeCase('{!Case.Merge_To_Case__c}')" />    
      </apex:pageBlockButtons>
       <apex:pageBlockSection >
      <apex:pageBlockSectionItem >
               <apex:outputLabel for="FondereCasi">Merge To Case</apex:outputLabel>
               <apex:inputField id="FondereCasi" value="{!Case.Merge_To_Case__c}"/>
      </apex:pageBlockSectionItem> 
      </apex:pageBlockSection> 
      <br/><br/><h1>ATTENTION !</h1>
      <p><b>When you click Merge button the case {!Case.CaseNumber} will be merge with {!Case.Merge_To_Case__c}</b></p> 
  </apex:pageBlock>
</apex:form>
  <!-- End Default Content REMOVE THIS -->
</apex:page>

and here the Apex Exstension Controller:
public class CaseMergeExtension {
    // ApexPages.StandardSetController must be instantiated
    // for standard list controllers
    public Case caso{get;set;}
    public CaseMergeExtension(ApexPages.StandardController stdcontroller) {
          this.caso = (Case)stdController.getRecord();
    }
    
    //pass Merge_To_Case__c from VF page in Casetomerge variable
    public String Casetomerge{get;set;}
    
    //function used to merge Case and case referenced by Merge_To_Case__c field 
    
    public void MergeCase(){
         //take the ID of Case referende By Merge_To_Case__c field and put it in CaseIDF variable
          Map<Id, Case> CaseMap = new Map<Id, Case>([
                           SELECT Id
                           FROM case
                           where CaseNumber=: 'Casetomerge']);
         List<Id> CaseId= new List<Id>(CaseMap.keySet());
         Id CaseIDF=CaseId.get(0);
        
        //Create a List of all Attachment from caso Object, that need to be reparented
         Map<id,List<Attachment>> AttachMap=new Map<Id,List<Attachment>>();
            for(Case cs:[select id, (select id from attachments) from case where ID=:caso.Id]){
                    AttachMap.put(cs.id,cs.attachments);
            }
        List<Attachment> attach= AttachMap.get(caso.Id);
        
        //reparent all the Attachemnts fro caso to the Case referenced by Merge_To_Case__c field
        for(Attachment a:attach ){
           a.parentid=CaseIDF;
        }
        update caso;
      }
}
 
Hi guys.I need in an apex class a Map of Cases ID with their Attachemnts and a List with that Attachment. Now i write this:
Map<Id, List<Attachment>> AttachMap = new Map<Id,List<Attachment>>([
                           select id,(select id from attachments) from case]);
But i receive the error:
 Invalid initial type List<Case> for Map<Id,List<Attachment>>.
How can i get the Map and after the list of Attachment based on case Id. Please help me 
Hi, I'm here to ask for help, I set up a workflow in my developer sandbox that send an email on one Date, I'm sure the Rules and Evaluation Criteria are rights but the email isn't sent. How Can I solve This Problem? I'm the Administrator of the sandbox
Hi,
I wrote an apex class for one Salesforce email service. I need that when an email arrive, case is created and email's attachemnts attach to the case created. When I test it, doesn't trhow errors or expetions, but also doesn't create case and attachment. Someone could please check my code and give me some tips please?

Here is my code
global class casewithattachments implements Messaging.InboundEmailHandler {
    
global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){ 
// Create an inboundEmailResult object for returning the result of the Force.com Email Service 
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult(); 
//List of email's Attachments
List <Attachment> attch = new List<Attachment>(); 
// Initialize the Contact ID, so if no Contact is found, a case is still created
Id vconID;     
//Case objects to be created 
Case newCase = new Case();   
// Try to lookup any contacts based on the email from address 
// If there is more than 1 contact with the same email address 
// an exception will be thrown and the catch statement will be called 
try { 
    Contact vCon = [Select Id, Name, Email From Contact Where Email = :email.fromAddress Limit 1]; 
// Add a new Case to the contact record we just found above - if not Contact found, value remains null 
    vconID = vCon.ID; 
// Insert the new Case and it will be created and appended to the contact record 
//newCase.Description = myPlainText;  
    newCase.Description = email.htmlBody; 
    newCase.Priority = 'Medium';
    newCase.Status = 'New';
    newCase.Subject = email.subject;
    newCase.Origin = 'Email'; 
    newCase.ContactId = vconID;
    insert newCase;
    System.debug('New Case Object: ' + newCase );     

// If there is an exception with the query looking up and the exception will be written to the Apex Debug logs 
catch (System.QueryException e) { 
    System.debug('Query Issue: ' + e);


    try{     
        for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
        attch.add(new Attachment(Name = tAttachment.fileName,Body = Blob.valueOf(tAttachment.body),ParentId = newCase.Id));} 

    
        for (Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
          attch.add(new Attachment(Name = bAttachment.fileName,Body = bAttachment.body,ParentId = newCase.Id));  } 
        System.debug('Attachemnt attached' );
    }
    catch (System.NullPointerException e) { 
            System.debug('Attachment Issue: ' + e);
}    
    
insert attch;
// Set the result to true, no need to send an email back to the user with an error message 
result.success = true; // Return the result for the Force.com Email Service 
return result; } 
}
i created a custom object and a visualforce tab to that object , but i can't show the title with the stab style like the standard pages as u can see. User-added image
this is my code:
<apex:page showHeader="true">
<apex:pageblock title="Departments">
<apex:ListViews type="Department__c" />
</apex:pageblock> </apex:page>.
How ca I show the title "Department" with a symbol in the page? Thanks for help
Hi, I understand that if I have to allow external software, i.e. SAP, to create,update External object in my org, I need to enable LIgthning Connect and define an OData adapter, but my question is : Where can I enable the Ligthning/Salsforce Connect within my org?

Thank you for your help.
Hi guys.I need in an apex class a Map of Cases ID with their Attachemnts and a List with that Attachment. Now i write this:
Map<Id, List<Attachment>> AttachMap = new Map<Id,List<Attachment>>([
                           select id,(select id from attachments) from case]);
But i receive the error:
 Invalid initial type List<Case> for Map<Id,List<Attachment>>.
How can i get the Map and after the list of Attachment based on case Id. Please help me 
Hi,
I wrote an apex class for one Salesforce email service. I need that when an email arrive, case is created and email's attachemnts attach to the case created. When I test it, doesn't trhow errors or expetions, but also doesn't create case and attachment. Someone could please check my code and give me some tips please?

Here is my code
global class casewithattachments implements Messaging.InboundEmailHandler {
    
global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){ 
// Create an inboundEmailResult object for returning the result of the Force.com Email Service 
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult(); 
//List of email's Attachments
List <Attachment> attch = new List<Attachment>(); 
// Initialize the Contact ID, so if no Contact is found, a case is still created
Id vconID;     
//Case objects to be created 
Case newCase = new Case();   
// Try to lookup any contacts based on the email from address 
// If there is more than 1 contact with the same email address 
// an exception will be thrown and the catch statement will be called 
try { 
    Contact vCon = [Select Id, Name, Email From Contact Where Email = :email.fromAddress Limit 1]; 
// Add a new Case to the contact record we just found above - if not Contact found, value remains null 
    vconID = vCon.ID; 
// Insert the new Case and it will be created and appended to the contact record 
//newCase.Description = myPlainText;  
    newCase.Description = email.htmlBody; 
    newCase.Priority = 'Medium';
    newCase.Status = 'New';
    newCase.Subject = email.subject;
    newCase.Origin = 'Email'; 
    newCase.ContactId = vconID;
    insert newCase;
    System.debug('New Case Object: ' + newCase );     

// If there is an exception with the query looking up and the exception will be written to the Apex Debug logs 
catch (System.QueryException e) { 
    System.debug('Query Issue: ' + e);


    try{     
        for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
        attch.add(new Attachment(Name = tAttachment.fileName,Body = Blob.valueOf(tAttachment.body),ParentId = newCase.Id));} 

    
        for (Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
          attch.add(new Attachment(Name = bAttachment.fileName,Body = bAttachment.body,ParentId = newCase.Id));  } 
        System.debug('Attachemnt attached' );
    }
    catch (System.NullPointerException e) { 
            System.debug('Attachment Issue: ' + e);
}    
    
insert attch;
// Set the result to true, no need to send an email back to the user with an error message 
result.success = true; // Return the result for the Force.com Email Service 
return result; } 
}
Hi, I understand that if I have to allow external software, i.e. SAP, to create,update External object in my org, I need to enable LIgthning Connect and define an OData adapter, but my question is : Where can I enable the Ligthning/Salsforce Connect within my org?

Thank you for your help.
Client needs to restrict the user to be login using mobile device to a specific device. For instance, the client will provide mobile devices to the users and the users can login to Salesforce only from the device which is provided by the client and no other device.