• Michael Hedrick 2
  • SMARTIE
  • 530 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 100
    Questions
  • 243
    Replies
Hello,
I ahve 2 questions regarding my VFpage:
  1. why there are white spaces after the page blocks in my VF page.
  2. How can I increase the width where the label value
Thanks
M
<apex:page standardController="Account" extensions="SourcingAuditAccountController"  standardStylesheets="true" showQuickActionVfHeader="false" showheader="false">
  
<apex:form id="inpform" >
               
    <style type="text/css">
    .bPageBlock .pbTitle {
        width: 100%; 
        font-size:20px;   
        text-align: center;
    }
    </style> 
             
            <apex:pageBlock title="Sourcing Audit"></apex:pageBlock>           
             <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlock >
                   
             <div style="display: none;">
                <apex:inputField value="{!SourcingAudit.Account__c}" />
                 ['Name'='Sourcing Audit for {!Account.Name} on system.today().format())' ], true)}">
             </div>
                     
             <apex:pageBlockSection columns="1" >                   
                     <label style="display:block;margin-top:10px;margin-left:1px;" for="Contact__c"></label>
                    <apex:inputField style="margin-left:10px;" id="Contact__c" value="{!SourcingAudit.Contact__c}" required="true"/>
                               
                <apex:outputLabel  />            
                <apex:selectRadio required="true" value="{!SourcingAudit.Quality_Bale_Issue__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>  
               
                
                <apex:outputLabel /> 
                <apex:selectRadio style="margin-left:1px;display:block;width:250px;" required="true" value="{!SourcingAudit.Bales_Inspected__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
               
                <apex:outputLabel />
                <apex:selectRadio required="true"  value="{!SourcingAudit.Volume_Reviewed__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>      
             
                
                <apex:outputLabel  /> 
                <apex:selectRadio required="true"   value="{!SourcingAudit.Weight_Issues__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
               
                <apex:outputLabel /> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Admin_review__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>                        
                
                <apex:outputLabel /> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Referral__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
    
                <apex:outputLabel style="margin-left:1px;"/> 
                <apex:inputTextarea style="margin-left:1px;" id="Audit_Comment__c" rows="3" cols="30" value="{!SourcingAudit.Audit_Comment__c}" />
                <br></br>
                
                </apex:pageBlockSection>
                
                      
            <div style="margin-right:20%;" align="center" draggable="false" >
           
                <apex:commandButton action="{!save}" value="Save"></apex:commandButton> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <apex:commandButton action="{!cancel}" value="Cancel"></apex:commandButton>
          
            </div>
                
              </apex:pageBlock>           
                       
        </apex:form>
</apex:page>

 
Hello All,
The 'Save' button on my VF page is inactive if a user does not complete all of the required field.  
Also, can I chnage the location of the error message?  The Save button is at the bottom the screen(mobile) and the user will not see the error at the top of the page.
Thanks,
M

VF Page
<apex:page docType="html-5.0" standardController="Account" extensions="SourcingAuditAccountController"  standardStylesheets="true" lightningStylesheets="true" showheader="false">
  
<div id="startLat">
</div>

<div id="startLon">
</div>

 <script>
    window.onload = function() {
        var startPos;
        var geoSuccess = function(position) {
            startPos = position;
            document.getElementById('{!$Component.inpform.pb.pbs.startLat}').value=startPos.coords.latitude;
            document.getElementById('{!$Component.inpform.pb.pbs.startLon}').value=startPos.coords.longitude;
            //alert('@@@ ' + document.getElementsByClassName('findclass')[0].value);
           document.getElementsByClassName('Latclass')[0].value =startPos.coords.latitude;
           document.getElementsByClassName('Lonclass')[0].value =startPos.coords.longitude;

        };
        navigator.geolocation.getCurrentPosition(geoSuccess);
    };
  </script>
  
    <script type='text/javascript' src='/canvas/sdk/js/publisher.js'/>  
    <script>
        Sfdc.canvas.publisher.subscribe({name: "publisher.showPanel", onData:function(e) { 
            Sfdc.canvas.publisher.publish({name:"publisher.setValidForSubmit", payload:"true"}); 
        }});

        Sfdc.canvas.publisher.subscribe({ name: "publisher.post", onData: function(e) { 
            Sfdc.canvas.publisher.publish({name:"publisher.setValidForSubmit", payload:"false"}); 
            saveActivity();
        }});
    </script>
    
    <div>
        <apex:form id="inpform" >
            <apex:outputPanel id="out">           
                
             <apex:actionFunction action="{!Save}"  name="saveActivity" rerender="out"/> 

             <div style="display: none;">
                <apex:inputField value="{!SourcingAudit.Account__c}" />
                 ['Name'='Sourcing Audit for {!Account.Name} on system.today().format())' ], true)}">
             </div>
              
              <apex:outputPanel >  
                    <label style="display:block;margin-top:12px;margin-left:10px" for="account_name">Account</label>
                    <span style="margin-left:10px;" id="account_name">{!Account.Name}</span>
                    
                     <label style="display:block;margin-top:12px;margin-left:10px;" for="Contact__c">Select a Contact</label>
                    <apex:inputField style="margin-left:10px;" id="Contact__c" value="{!SourcingAudit.Contact__c}" required="true"/>
                </apex:outputPanel> 
               
                <br></br>
                     
                <apex:outputLabel style="margin-left:10px;"  value="Bale Quality Issue"/>            
                <apex:selectRadio required="true" value="{!SourcingAudit.Quality_Bale_Issue__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>  
                
                <br></br>
                
                <apex:outputLabel style="margin-left:10px;" value="Bale Inspected"/> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Bales_Inspected__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
                 <br></br>
            
                 <apex:outputLabel style="margin-left:10px;" value="Volume Review"/>
                <apex:selectRadio required="true"  value="{!SourcingAudit.Volume_Reviewed__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>      
                 <br></br>
                
                 <apex:outputLabel style="margin-left:10px;" value="Weight Issue"/> 
                <apex:selectRadio required="true"   value="{!SourcingAudit.Weight_Issues__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
                <br></br>
                
                <apex:outputLabel style="margin-left:10px;" value="Admin Review"/> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Admin_review__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>      
                
                 <br></br>
                
                 <apex:outputLabel style="margin-left:10px;" value="Referral"/> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Referral__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
    
                <apex:outputPanel >
                    <label style="display:block;margin-top:12px;margin-left:10px;" for="comments">Comment</label>
                    <apex:inputTextarea style="margin-left:10px;" id="Audit_Comment__c" rows="3" cols="30" value="{!SourcingAudit.Audit_Comment__c}" />
                    
              </apex:outputPanel>
  
            </apex:outputPanel> 
        </apex:form>
    </div>
</apex:page>
 
public class SourcingAuditAccountController{
    private Sourcing_Audit__c  SourcingAudit;
    private Account Account;
    public String defaultCheck{get;set;}
    public string calljavascript {get; set;}
    public string message {get; set;} 

    public SourcingAuditAccountController(ApexPages.StandardController controller) 
    {
        Account = [SELECT Id, Name FROM Account WHERE Id =: controller.getId()];
        SourcingAudit = new Sourcing_Audit__c();
        SourcingAudit.Account__c = Account.Id;
     
    if(defaultCheck==NULL)
    {defaultCheck='Winchester';}
    
    }    

    public string PostSaveMessage {get; set;}
    public string Close {get; set;}

   
    public Sourcing_Audit__c  getSourcingAudit() {
        return SourcingAudit ;
    }    

    public Account getAccount() {
        return Account;
    }
   
    public PageReference Save()
    
    {
             
     RecordType rt;
        if(SourcingAudit.Audit_Location__c!= null)
            rt = [Select Id From RecordType Where DeveloperName = 'Warehouse' And sObjectType = 'Sourcing_Audit__c'];
        else
            rt = [Select Id From RecordType Where DeveloperName = 'Facility' And sObjectType = 'Sourcing_Audit__c'];
        SourcingAudit.RecordTypeId = rt.Id;
        
        System.debug('In Save method.');
        
        try {
        
        Insert SourcingAudit;
        PageReference pg = new PageReference('/'+SourcingAudit.Id);
        pg.setRedirect(true);  
        return pg;  
                    
        } 
        catch (Exception ex) {
            string message = ex.getMessage();
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Fatal, message));
            return null;
        }
    }
   
}

 
Hello All,
I have a Batch Class where I am updating all of the Contact Owners to Match the Account owners.
I am unable to cober the condition in Class.
Here are the Classes.
@isTest

private class TestBatchContactownerUpdate 
{
    static List<Account> aList;
    static testMethod void myUnitTest() 
   
    {
        UpdateContactOwnerToAccountOwnerBatch bat = new UpdateContactOwnerToAccountOwnerBatch();
     
        bat.finish(null);
    }
    static testMethod void testSchedulable()
    {
        Test.startTest();        
        String cron = '0 0 0 17 11 ? 2033';
        System.schedule('BATR99zz', cron, new UpdateContactOwnerToAccountOwnerBatch());
        Test.stopTest();
    }
  
    {
     Account acc = new Account(
            Name = 'testaccount'
            ,BillingPostalCode='22821'      
            ,RecordTypeId = '222222' 
        );
        insert acc; 

      
        Account sacc= [SELECT Id, Name,OwnerID from Account Where name = 'testAccount' limit 1];
       
        Contact con = new Contact(
            AccountId = sacc.id
            ,Lastname = 'testcontact'
            ,Firstname ='testdude'
            ,RecordTypeId = '1111111'
        );
        insert con;


       
        Test.startTest();
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
            User u1= new User(Alias = 'standt', Email='testemail@junkmail.com', 
                        EmailEncodingKey='UTF-8', LastName='Tester', LanguageLocaleKey='en_US', 
                        LocaleSidKey='en_US', ProfileId = p.Id, 
                        TimeZoneSidKey='America/Los_Angeles', UserName='testemail@junkmail.com');
            
            System.runAs(u1) {
      // The following code runs as user 'u'  
       // create test contact
        Contact c1 = new Contact(FirstName='Jane',LastName='Doe', Account=acc);
        insert c1;
        
        //assert your results using system.assert and system.asserEquals

        //reload objects to make sure values are loaded
        c1 = [select id, name,  OwnerId from contact where id=:con.id];
        con = [select id, name, OwnerId from contact where id=:con.id];

        acc= [select id, ownerId from Account where id=:acc.id];
       // system.assert(c1.OwnerID = acc.OwnerID);
            
            
            
        Test.stopTest();
        }
    }
}
global class UpdateContactOwnerToAccountOwnerBatch implements Database.Batchable<sObject>, Schedulable{

        
    List<contact> contactsToChangeOwner = new List<contact>();
    global final String Query ='SELECT Id, AccountId, Ownerid, Account.ownerid from contact where AccountId != null';
       global Database.QueryLocator start(Database.BatchableContext BC){
          return Database.getQueryLocator(query);
       }
       
       global void execute(Database.BatchableContext BC, List<contact> scope){
        
        for(contact con: scope){     ----  No Coverage
            if(con.ownerid!=con.Account.ownerid){    ----  No Coverage
                con.ownerid = con.Account.ownerid;     ----  No Coverage
                contactsToChangeOwner.add(con);    ----  No Coverage
            }           
        }
        update contactsToChangeOwner;      ----  No Coverage
       }
       
    global void finish(Database.BatchableContext BC){}
    
    global void execute(SchedulableContext sc)
    {
      Database.executeBatch(new UpdateContactOwnerToAccountOwnerBatch ());
    } 
    
    
    
}

If someone would review my Test Class it would be greatly appreciated.
Cheers,
M
 
Hello,
I have a trigger that is not not reaching the 75% threshold.
I have 2 lines of code where I am calling another Class.  Any help would be greatly appreciated.
trigger warrantyValueCalculation on Warranties_and_Surveys__c (before insert, before update) {
    for (Warranties_and_Surveys__c warRec: trigger.new)
    {
         if((trigger.isInsert) && (warRec.Warranty_Survey_Account__c=='123' || warRec.Warranty_Survey_Account__c=='456' || warRec.Warranty_Survey_Account__c=='789' || warRec.Warranty_Survey_Account__c=='136' || warRec.Warranty_Survey_Account__c=='764' || warRec.Warranty_Survey_Account__c=='111')&&(warRec.Project_Country__c=='US')){
         warrantyAmountCalculation.beforeInsert(trigger.new); ---no coverage
        }
        //if((trigger.isUpdate) && ((trigger.oldMap.get(warRec.Id).Registration_Status__c == 'Registered') && (warRec.Registration_Status__c == 'Registered'))){
         if((trigger.isUpdate) && (warRec.Warranty_Survey_Account__c=='001f100001M2FVP' || warRec.Warranty_Survey_Account__c=='876' || warRec.Warranty_Survey_Account__c=='590' || warRec.Warranty_Survey_Account__c=='327' || warRec.Warranty_Survey_Account__c=='970' || warRec.Warranty_Survey_Account__c=='327')&&(warRec.Project_Country__c=='US')){
         warrantyAmountCalculation.beforeInsert(trigger.new); ---no coverage
        }
    }

}

 
I was originally using href to allow the users to access a website but I could not figure out a way to close the Quick Action so I changed the href to an output link.  But now the formatting and alignment is off.  If anyone has any suggection please advise. Thanks
<apex:page standardController="Account"  standardstylesheets="false" lightningStylesheets="true" showheader="false" >

<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">
    <head>
      <meta charset="utf-8" />
      <meta http-equiv="x-ua-compatible" content="ie=edge" />
      <title>SLDS ResponsiveDesign Visualforce Page in Salesforce Mobile</title>
      <meta name="viewport" content="width=device-width, initial-scale=1" />
      <apex:slds />
    </head>
    
    <script type='text/javascript' src='/canvas/sdk/js/publisher.js'></script>
    
    <script>
    function closeAction() {
        Sfdc.canvas.publisher.publish({name: "publisher.close", payload:{ refresh:"true"}});  
    }
    </script>
       
       
 <!-- String JDE = {!Account.JDE__c}; ---->
    
    <body>   
     <div class="slds-scope">
          <div class="SLDS">
            <div class="slds-grid slds-wrap">   
              <div class="slds-col">
               <!--     <div class="slds-box slds-box_small slds-text-align_center">             
                  <a href='https://test.com/format=HTML&Download=false&prompt=false&p_VendorNo={!Account.JDE__c}'>Test Report</a> ---></div> 
                  <apex:outputlink value="https://test.com/format=HTML&Download=false&prompt=false&p_VendorNo={!Account.JDE__c}" onclick="closeAction();" >Sourcing POs</apex:outputlink>
               
             <!--     </div>  --->
             </div>
          </div>
      </div>   
    </body>
  </html>
  </apex:page>

 
Currently I am captuign a users location via script within a visualforce page.
<script>
    window.onload = function() {
        var startPos;
        var geoSuccess = function(position) {
            startPos = position;
            document.getElementById('{!$Component.inpform.pb.pbs.startLat}').value=startPos.coords.latitude;
            document.getElementById('{!$Component.inpform.pb.pbs.startLon}').value=startPos.coords.longitude;
            //alert('@@@ ' + document.getElementsByClassName('findclass')[0].value);
           document.getElementsByClassName('Latclass')[0].value =startPos.coords.latitude;
           document.getElementsByClassName('Lonclass')[0].value =startPos.coords.longitude;

        };
        navigator.geolocation.getCurrentPosition(geoSuccess);
    };
  </script>

This is fine but makes I cannot reuse the logic.  Would it be a better option to use in in a Apex Class so that the location capturing process can be used on any Object?  If so, how can I make the Class univeral to any object?
Thanks
Hello,
Been trying to figure out how to save the latitude and latitude of the users current location when they save a custom record via a visualforce page.  I was able to use 
document.getElementById('startLat').value=startPos.coords.latitude;

and this would grab the latitude but I have not been able to save the value to the record. 

Is there a better way to aquaire the Lat and long of a users current location when the record is created and then saving the lat and long to the custom record.  
Thanks
Hello,
I have a script that gets the lat and long of a user when they initiate a VF page.
</script>
</head> 
<div id="startLat">
</div>
<div id="startLon">
</div>

<script>
    window.onload = function() {
        var startPos;
        var geoSuccess = function(position) {
            startPos = position;
            document.getElementById('startLat').innerHTML = startPos.coords.latitude;
            document.getElementById('startLon').innerHTML = startPos.coords.longitude;
        };
        navigator.geolocation.getCurrentPosition(geoSuccess);
    };
</script>
This works great but I am unable to bind it to the custom lat and long fields on the record.
I have tried both apex:outputField  and apex:inputputField and still unable to to save the lat and long field to the record
<label style="display:block;margin-top:12px;" for="Latitude__c"><span style="color:red;">*</span>Latitude</label>  <apex:inputField style="margin-left:0;" id="startLan" value="{!SourcingAudit.Latitude__c}" />
                    
                     <label style="display:block;margin-top:12px;" for="Longitude__c"><span style="color:red;">*</span>Longitude</label>    <apex:outputField style="margin-left:0;" id="startLon" value="{!SourcingAudit.Longitude__c}" />
Le me know what I am doing incorrect or if there is a better option.

Thanks

 
Hello All,
I have a custom object where a user completes a survey and saves it.  I would like to get the users current location.  What I am wondering is what is the best approach?  Custom button?  Issue is we care going to Lightning so would JS be an issue?  Reference an Apex Class on record save?  Create a VF Page to capture information and lat & long?
Your suggestions is appreciated.

Thanks,
M
Hello I was wondering can I add the addCustomDetail method to the Live Agent deployment code?  The Chat button is on a Public website

So currently the code looks like this
<script type='text/javascript' src='https://c.la9cs.salesforceliveagent.com/content/g/deployment.js'></script> 
<script type='text/javascript'> 
liveagent.init('https://d.la9cs.salesforceliveagent.com/chat', '57290000000PC4m', '00DO00000007EgL'); 
</script>


We created a custom webpage(pop up) to ask the custom to opt in before initiating the Chat window.  If they opt in, the chat window will start and I need the opt in value(boolean) value to be passed to the Chat Transcript record which is attached to the Case record. 
o can I add the addCustomDetail method to the Live Agent deployment code?
<script type='text/javascript' src='https://c.la9cs.salesforceliveagent.com/content/g/deployment.js'></script> 
<script type='text/javascript'> 
liveagent.addCustomDetail('Opt In', '{True}').saveToTranscript('OptIn__c'); 
liveagent.init('https://d.la9cs.salesforceliveagent.com/chat', '57290000000PC4m', '00DO00000007EgL'); 
</script>

Thanks
Hello All,
We have a Chat button on our public facing website which everyone can access.  I need to have an option to ask users to opt in if the are out of the US or Canada.  What is the simplist way to perform this?  Is there a way to have a prechat page pop up when a user selects the Chat button and only allow the Chat to be initiated if the user opts in and then pass that value to the Transcript record? Can this be done with a pre chat page even if this is on an external website?

Thanks,
M
Hello everyone,
I have a visualforce page thatreside on a public website.
The user enters information on 2 fields.  Then completes a  captcha. 
The user then clicks a button on the VF page.
Assuming the Captcha is succesful I need to go back to the Salesforce org to return Acount data based on the 2 field and populate fields on the same VF page.  I am familiar passing information from Salesforce to a VF page but I am not sure how to retrieve the data from Salesforce based on user input on a VF page.  Any suggestions would be greatly appreciated.

Thanks
Hello All,
I am trying to work with the ActivityHistory Object and wanted to confirm what I think the issue is.
I have a query where I want to return records where the record does not contain an activty:
Select Id,Name FROM test__c  WHERE  Status__c='Registered' AND ID NOT IN (SELECT WhatID FROM ActivityHistories where Activity_Subtype__c='stuff')

I am assuming that it is not possible to query against the ActivityHistory object correct?
Hello,
 I have the following Class and VF Page below.
 
Public with sharing class AccountDealerDashboardController {

    public Id selectedAccId{get;set;} 

    public String fieldValue {get; set;}
    public String selectedFields{get;set;}
    public String JDEValue {get; set;}
    public String selectedJDE{get;set;}
    public boolean showPanel { get; set; } //to show and hide graph
    public boolean showButton { get; set; } //to show and hide button
    
    public AccountDealerDashboardController (ApexPages.StandardController stdController)
    {
        showButton = false; // onload don't display button and panelGrid
        showPanel = false;
    }

    public void accountNameChanged()
    {
        valueSelectedShowButton();
        passValueToController();
    }
    
    public void valueSelectedShowButton() 
    {
        showButton = true;// after selecting value f
    }

   
    public List<SelectOption> getAccountNames() 
        {
            List<SelectOption> accOptions= new List<SelectOption>();
            system.debug(selectedAccId);
            
            accOptions.add( new SelectOption('','--Select--'));
            for(Account acc : [select Id,name,Site,JDE__c,Status__c from Account Where Status__c = 'Active' AND Partner_Type__c='Dealer' AND Indirect_Sales_YTD__c > 10 AND OwnerId =:UserInfo.getUserid() order by Name asc] ) 

        {
            accOptions.add(new SelectOption(acc.Id,acc.name));
           
        }
            return accOptions;
        }
  
    public void passValueToController()
        {
            fieldValue = selectedFields;
            JDEValue =selectedJDE;
            
        }
  
   public void commandButtonClick()     
        {
            showPanel = true; //on click of button show panel
        }
   
  }

<apex:page standardController="Account" standardStylesheets="true"  showHeader="True" sidebar="false" extensions="AccountDealerDashboardController" >
  
    <style>
        #col1,#col2{width:15%;display:inline-block;vertical-align:Top;}
    </style>
    
    <apex:form >
        <div id="col1">
        <apex:pageBlock title="Select Account">    
            <apex:outputpanel id="Outputtext"  >
        <!--    <apex:outputtext value="{!fieldValue}"/>  -->
            </apex:outputpanel>
            <apex:selectList value="{!selectedFields}" title="Select an Account from the DropDown List" size="1" style="width:100%">
                <apex:actionSupport event="onchange"  reRender="buttonId" action="{!accountNameChanged}"/>     <!-- after selecting value in picklist set showButton to true. rerender pageBlock "buttonId" so button will be rerendered-->         
                <apex:selectOptions value="{!AccountNames}" />
              
            </apex:selectList><br/><br/>   
                <apex:outputtext value="{!fieldValue}"/>   
                <br/> 
               
        </apex:pageBlock>  
       
         
    <apex:pageBlock id="buttonId">  
        <apex:commandButton value="Show Charts" rendered="{!showButton}" title="Click Show Charts button to load reports" alt="tooltip"  action="{!commandButtonClick}" / > <!--onclick button show graph panel    reRender="chart" --> 
            <br/> 
  <!--        <apex:outputText value="{!fieldValue}" label="You have selected:" id="values" /> <!--  used to verify Id -->    
    </apex:pageBlock>  

    </div>


        <div id="col2">
        <apex:outputPanel id="chart" rendered="{!showPanel}">
        
                  <apex:panelGrid columns="3" id="theGrid" rendered="{!showPanel}">
                    <analytics:reportChart showRefreshButton="false" reportId="123456" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!fieldValue}'}]" size="medium"> </analytics:reportChart>
                    <analytics:reportChart showRefreshButton="false" reportId="123456" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!fieldValue}'}]" size="medium"> </analytics:reportChart>
                    <analytics:reportChart showRefreshButton="false" reportId="123456" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!fieldValue}'}]" size="medium"> </analytics:reportChart>
                    <analytics:reportChart showRefreshButton="false" reportId="123456" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!fieldValue}'}]" size="medium"> </analytics:reportChart>
                    <analytics:reportChart showRefreshButton="false" reportId="123456" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!fieldValue}'}]" size="medium"> </analytics:reportChart>
                    <analytics:reportChart showRefreshButton="false" reportId="123456" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!fieldValue}'}]" size="medium"> </analytics:reportChart>
                    <analytics:reportChart showRefreshButton="false" reportId="123456" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!fieldValue}'}]" size="medium"> </analytics:reportChart> 
                    <analytics:reportChart showRefreshButton="false" reportId="123456" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!fieldValue}'}]" size="medium"> </analytics:reportChart>              
              </apex:panelGrid>
       
      </apex:outputPanel> 
     </div>
    </apex:form>
    
</apex:page>

My question is how can I add an additional required field to the VF page that will determine qhick query to call that will populate the Picklist field.
for example:
The user select option 'A' on teh VF page.
The query would be:
Account acc : [select Id,name,Site,JDE__c,Status__c from Account Where Status__c = 'Active' AND Partner_Type__c='Dealer' AND Indirect_Sales_YTD__c > 10 AND OwnerId =:UserInfo.getUserid() order by Name asc] )
But if the user selects option 'B' the query would be 
Account acc : [select Id,name,Site,JDE__c,Status__c from Account Where Status__c = 'Active' AND Partner_Type__c='Contractor' AND Indirect_Sales_YTD__c > 50 AND OwnerId =:UserInfo.getUserid() order by Name asc] )

Or would it it be better to use a Lookup.
I had to use the OwnerId =:UserInfo.getUserid() becasue I was returning over 1000 records.

Any suggestion would be appreciated.
 
Thanks,
M
Hello,
I have an Apex Trigger that I needs to perform the following:
  • prevent duplicate lead from being inserted during an import
  • add task to existing Lead that was found within SF
The trigger belows does meet my requiremtns except that it also adds a task to the newly inserted Lead.  The Newly inserted Lead does not exsit in Salesforce so I am not sure why a task is being added.
trigger LeadPreventDuplicate on Lead (after insert,after update) {

    Map<String, Lead> leadMap = new Map<String, Lead>();

      for (Lead lead : System.Trigger.new) 
      { 

       if ((lead.Email != null) && (System.Trigger.isInsert ||
            (lead.Email != System.Trigger.oldMap.get(lead.Id).Email))) 
            {
              leadMap.put(lead.Email, lead);
            }
      }

      List<task> addtask=New List<task>();
     
      for (Lead lead : [SELECT Email FROM Lead WHERE Email IN :leadMap.KeySet()]) 
      {
        Lead newLead = leadMap.get(lead.Email);
        addtask.add(new Task(
        WhoID =lead.id, 
        Status = 'Active',
        Subject = 'Test Task',
        ActivityDate = system.today()));
      
       } 
       insert addtask; 
      
       Lead[] dupes = new Lead[0];
          Set<String> email = new Set<String>(), dupEmail = new Set<String>();
              for(Lead record: Trigger.new)
              email.add(record.email);
              email.remove(null);
              for(Lead record: [SELECT Id, Email FROM Lead WHERE Email IN :email])
                    if(!Trigger.newMap.containsKey(record.id))
                    dupEmail.add(record.Email);
              for(Lead record: Trigger.new)
        if(dupEmail.contains(record.Email))
            dupes.add(record.clone(true));
        else
            dupEmail.add(record.Email);
    delete dupes;
}

Thanks for the assistance.
M
 
Hello All.
I have a class that looks for existing Leads with the same email address. 
If the email address exist add a task to the existing Lead.  This works.
The issue is that is still allows the creation of the duplicate Lead.  I do not want to throw an error message since the Leads may be imported via data loader.  If its creating a task because the email address already exist it should not be creating the lead.
Thanks,
M
trigger LeadPreventDuplicate on Lead (before insert,before update) {

    Map<String, Lead> leadMap = new Map<String, Lead>();
    for (Lead lead : System.Trigger.new) {
        
       //  Make sure we don't treat an email address that isn't changing during an update as a duplicate.  
    
        if ((lead.Email != null) && (System.Trigger.isInsert ||
                (lead.Email != System.Trigger.oldMap.get(lead.Id).Email))) {
                leadMap.put(lead.Email, lead);
       }
    }
    
    List<task> addtask=New List<task>();
    for (Lead lead : [SELECT Email FROM Lead
                      WHERE 
                      Email IN :leadMap.KeySet()]) {
        Lead newLead = leadMap.get(lead.Email);
        
       // newLead.Email.addError('A lead with this email '
                        //       + 'address already exists.');
        addtask.add(new Task(
        WhoID =lead.id, 
        Status = 'Active',
        Subject = 'Test Task',
        ActivityDate = system.today()
        ));
        
       } 
         insert addtask;        
                                                            
}

 
Hello All,
A fellow community member assited me with the Apex class below.
This process take leads with the same email address and merges all of the activties on these leads to the oldest lead.
Then the code deletes the remaining Leads.  All of the Leads are marked with a checkbox to indicate that they are a duplicate.
So instead of deleting I want to uncheck the checkbox on the new master Lead.
 In the class is the line of code t.WhoId = masterLead.Id; Assigning the master Lead?
can I add 
t.WhoId = masterLead.Id;
masterLead.checkbox = false;
And this would uncheck the checkbox just on the master lead and leave the checkbox checked on the other duplicate leads?
 
List<Lead> leads = [Select Id, Email, (Select Id, WhoId from Tasks), (Select Id, WhoId from Events) from Lead ORDER BY CreatedDate];

Map<String,List<Lead>> leadsMap = new Map<String,List<Lead>>();

for( Lead l : leads ) {
    if( !leadsMap.containsKey( l.Email ) ) {
        leadsMap.put( l.Email, new List<Lead>() );
    }

    leadsMap.get( l.Email ).add( l );
}

List<Event> eventsToUpdate = new List<Event>();
List<Task> tasksToUpdate = new List<Task>();
List<Lead> leadsToDelete = new List<Lead>();


for( String email : leadsMap.keySet() ) {
    List<Lead> leadsToMerge = leadsMap.get( email );
    if( leadsToMerge.size > 1 ) {
        Lead masterLead = leadsToMerge[0];

        for( Integer i = 1; i < leadsToMerge.size(); i++ ) {
            Lead mergedLead = leadsToMerge[index];
            for( Task t : mergedLead.Tasks ) {
                t.WhoId = masterLead.Id;
                tasksToUpdate.add( t );
            }

            for( Event e : mergedLead.Event ) {
                e.WhoId = masterLead.Id;
                eventsToUpdate.add( e );
            }
            leadsToDelete.add( mergedLead );
        }

    }
}

if( eventsToUpdate.size() > 0 ) update eventsToUpdate;
if( tasksToUpdate.size() > 0 ) update tasksToUpdate;
if( leadsToDelete.size() > 0 ) delete leadsToDelete;

Thanks,
M
Hello All,
I have been tasked to find duplicate Leads within our org.

Each Lead has an activity(s)
FInd the oldest lead and make this the master.
Take the activities from the other Leads and merge them to the Master Lead. 
Delete the duplicate Leads.

This wil be a once and done since we now have a process to marry all the Leads together based on the email address.
I just need some help on the best approach to resolve this issue.
I do not actually need to merge the vlaues on the Lead details record as much as I need to make sure I get all of the Activities into a single Leads record.

I thought about trying the below approach but I am not thinking it will meet all of me needs
List<AggregateResult> DuplicateList = 
[select count(email), id from lead where email != '' group by id having count(email) >1 limit 200];


For (AggregateResult Agm:DuplicateList){

   String LeadEmail = string.valueOf(agm.get('email'));
   Lead ToLead = [Select id, email from Lead where email like :LeadEmail limit 1];
   Lead FromLead = [Select id, email from Lead where Id != :ToLead.Id and email like :LeadEmail Limit 1];

   system.debug(LoggingLevel.Info,'*** FromLead: ' + FromLead.email+' ('+FromLead.Id+')');
   system.debug(LoggingLevel.Info,'*** ToLead  : ' + ToLead.email+' ('+ToLead.Id+')');
   database.merge(ToLead , FromLead );

}
Thanks,
M
 
Hello All,
I was wondering what are other developers using for version control and keeping their metadata synched between orgs.
Currently we a utilizing VS code and GIT which works great for working with apex classes & VF pages and this is working well but not sure how to get the changes back into the Salesforce org.  There are multiple people working in these org so we want to make sure we are all on the same page and not stepping on each others work.

Thanks
M
 
Hello Everyone,
I am hoping I could get some feedback on what is the best and secure way to acomplish the following:
  • Have external webservices that need to create records in a salesforce
  • Do not need to response to external webservice

I was thinking that I would create Rest Class and exposing them to the external web services. 
But was wondering, is this secure? Do I need to create a Connected App or what additional steps do I need to do to make sure that the call is coming from the correct external service.

Thanks,
M
Hello All,
I have created an email service that allows the user to send an email from the Lead object in Salesforce and have the replied email be attched to the Lead record as a Task. 
The issue is that if the Customer does not select "Reply All" the replied to email will not get associated back to the Lead record because the email service email address is being added to the email and is not hte default from email address. 
So is there a way to make Email Service Email Address selectable?  Or can the Email Service Email Address be an organizational wide email address? 
Thanks,
M
  
Hello All,
I have a simple VF page that opens a Chart on a Account Page Layout;

<apex:page standardController="Account">
<script type="text/javascript">
function Test(){
var url = '/00Oj0000004KjPM';
window.parent.location.replace(url);
}
</script>
<apex:outputLink onclick="Test();">
    <analytics:reportChart cacheResults="false" reportId="00Oj0000004KjPM"
        filter="{column:'FK_ACC_ID',operator:'equals',value:'{!Account.Id}'}"
        size="small">
    </analytics:reportChart>  
   </apex:outputLink>
</apex:page>

This works ok but I cannot get the report to open in a 'new' window and the report that does open is not filtered by the Account id.

Any thoughts or suggestions is alwys appreciated.

Regards,
M
Hello All,
The 'Save' button on my VF page is inactive if a user does not complete all of the required field.  
Also, can I chnage the location of the error message?  The Save button is at the bottom the screen(mobile) and the user will not see the error at the top of the page.
Thanks,
M

VF Page
<apex:page docType="html-5.0" standardController="Account" extensions="SourcingAuditAccountController"  standardStylesheets="true" lightningStylesheets="true" showheader="false">
  
<div id="startLat">
</div>

<div id="startLon">
</div>

 <script>
    window.onload = function() {
        var startPos;
        var geoSuccess = function(position) {
            startPos = position;
            document.getElementById('{!$Component.inpform.pb.pbs.startLat}').value=startPos.coords.latitude;
            document.getElementById('{!$Component.inpform.pb.pbs.startLon}').value=startPos.coords.longitude;
            //alert('@@@ ' + document.getElementsByClassName('findclass')[0].value);
           document.getElementsByClassName('Latclass')[0].value =startPos.coords.latitude;
           document.getElementsByClassName('Lonclass')[0].value =startPos.coords.longitude;

        };
        navigator.geolocation.getCurrentPosition(geoSuccess);
    };
  </script>
  
    <script type='text/javascript' src='/canvas/sdk/js/publisher.js'/>  
    <script>
        Sfdc.canvas.publisher.subscribe({name: "publisher.showPanel", onData:function(e) { 
            Sfdc.canvas.publisher.publish({name:"publisher.setValidForSubmit", payload:"true"}); 
        }});

        Sfdc.canvas.publisher.subscribe({ name: "publisher.post", onData: function(e) { 
            Sfdc.canvas.publisher.publish({name:"publisher.setValidForSubmit", payload:"false"}); 
            saveActivity();
        }});
    </script>
    
    <div>
        <apex:form id="inpform" >
            <apex:outputPanel id="out">           
                
             <apex:actionFunction action="{!Save}"  name="saveActivity" rerender="out"/> 

             <div style="display: none;">
                <apex:inputField value="{!SourcingAudit.Account__c}" />
                 ['Name'='Sourcing Audit for {!Account.Name} on system.today().format())' ], true)}">
             </div>
              
              <apex:outputPanel >  
                    <label style="display:block;margin-top:12px;margin-left:10px" for="account_name">Account</label>
                    <span style="margin-left:10px;" id="account_name">{!Account.Name}</span>
                    
                     <label style="display:block;margin-top:12px;margin-left:10px;" for="Contact__c">Select a Contact</label>
                    <apex:inputField style="margin-left:10px;" id="Contact__c" value="{!SourcingAudit.Contact__c}" required="true"/>
                </apex:outputPanel> 
               
                <br></br>
                     
                <apex:outputLabel style="margin-left:10px;"  value="Bale Quality Issue"/>            
                <apex:selectRadio required="true" value="{!SourcingAudit.Quality_Bale_Issue__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>  
                
                <br></br>
                
                <apex:outputLabel style="margin-left:10px;" value="Bale Inspected"/> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Bales_Inspected__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
                 <br></br>
            
                 <apex:outputLabel style="margin-left:10px;" value="Volume Review"/>
                <apex:selectRadio required="true"  value="{!SourcingAudit.Volume_Reviewed__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>      
                 <br></br>
                
                 <apex:outputLabel style="margin-left:10px;" value="Weight Issue"/> 
                <apex:selectRadio required="true"   value="{!SourcingAudit.Weight_Issues__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
                <br></br>
                
                <apex:outputLabel style="margin-left:10px;" value="Admin Review"/> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Admin_review__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>      
                
                 <br></br>
                
                 <apex:outputLabel style="margin-left:10px;" value="Referral"/> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Referral__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
    
                <apex:outputPanel >
                    <label style="display:block;margin-top:12px;margin-left:10px;" for="comments">Comment</label>
                    <apex:inputTextarea style="margin-left:10px;" id="Audit_Comment__c" rows="3" cols="30" value="{!SourcingAudit.Audit_Comment__c}" />
                    
              </apex:outputPanel>
  
            </apex:outputPanel> 
        </apex:form>
    </div>
</apex:page>
 
public class SourcingAuditAccountController{
    private Sourcing_Audit__c  SourcingAudit;
    private Account Account;
    public String defaultCheck{get;set;}
    public string calljavascript {get; set;}
    public string message {get; set;} 

    public SourcingAuditAccountController(ApexPages.StandardController controller) 
    {
        Account = [SELECT Id, Name FROM Account WHERE Id =: controller.getId()];
        SourcingAudit = new Sourcing_Audit__c();
        SourcingAudit.Account__c = Account.Id;
     
    if(defaultCheck==NULL)
    {defaultCheck='Winchester';}
    
    }    

    public string PostSaveMessage {get; set;}
    public string Close {get; set;}

   
    public Sourcing_Audit__c  getSourcingAudit() {
        return SourcingAudit ;
    }    

    public Account getAccount() {
        return Account;
    }
   
    public PageReference Save()
    
    {
             
     RecordType rt;
        if(SourcingAudit.Audit_Location__c!= null)
            rt = [Select Id From RecordType Where DeveloperName = 'Warehouse' And sObjectType = 'Sourcing_Audit__c'];
        else
            rt = [Select Id From RecordType Where DeveloperName = 'Facility' And sObjectType = 'Sourcing_Audit__c'];
        SourcingAudit.RecordTypeId = rt.Id;
        
        System.debug('In Save method.');
        
        try {
        
        Insert SourcingAudit;
        PageReference pg = new PageReference('/'+SourcingAudit.Id);
        pg.setRedirect(true);  
        return pg;  
                    
        } 
        catch (Exception ex) {
            string message = ex.getMessage();
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Fatal, message));
            return null;
        }
    }
   
}

 
Hello All,
I have a Batch Class where I am updating all of the Contact Owners to Match the Account owners.
I am unable to cober the condition in Class.
Here are the Classes.
@isTest

private class TestBatchContactownerUpdate 
{
    static List<Account> aList;
    static testMethod void myUnitTest() 
   
    {
        UpdateContactOwnerToAccountOwnerBatch bat = new UpdateContactOwnerToAccountOwnerBatch();
     
        bat.finish(null);
    }
    static testMethod void testSchedulable()
    {
        Test.startTest();        
        String cron = '0 0 0 17 11 ? 2033';
        System.schedule('BATR99zz', cron, new UpdateContactOwnerToAccountOwnerBatch());
        Test.stopTest();
    }
  
    {
     Account acc = new Account(
            Name = 'testaccount'
            ,BillingPostalCode='22821'      
            ,RecordTypeId = '222222' 
        );
        insert acc; 

      
        Account sacc= [SELECT Id, Name,OwnerID from Account Where name = 'testAccount' limit 1];
       
        Contact con = new Contact(
            AccountId = sacc.id
            ,Lastname = 'testcontact'
            ,Firstname ='testdude'
            ,RecordTypeId = '1111111'
        );
        insert con;


       
        Test.startTest();
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
            User u1= new User(Alias = 'standt', Email='testemail@junkmail.com', 
                        EmailEncodingKey='UTF-8', LastName='Tester', LanguageLocaleKey='en_US', 
                        LocaleSidKey='en_US', ProfileId = p.Id, 
                        TimeZoneSidKey='America/Los_Angeles', UserName='testemail@junkmail.com');
            
            System.runAs(u1) {
      // The following code runs as user 'u'  
       // create test contact
        Contact c1 = new Contact(FirstName='Jane',LastName='Doe', Account=acc);
        insert c1;
        
        //assert your results using system.assert and system.asserEquals

        //reload objects to make sure values are loaded
        c1 = [select id, name,  OwnerId from contact where id=:con.id];
        con = [select id, name, OwnerId from contact where id=:con.id];

        acc= [select id, ownerId from Account where id=:acc.id];
       // system.assert(c1.OwnerID = acc.OwnerID);
            
            
            
        Test.stopTest();
        }
    }
}
global class UpdateContactOwnerToAccountOwnerBatch implements Database.Batchable<sObject>, Schedulable{

        
    List<contact> contactsToChangeOwner = new List<contact>();
    global final String Query ='SELECT Id, AccountId, Ownerid, Account.ownerid from contact where AccountId != null';
       global Database.QueryLocator start(Database.BatchableContext BC){
          return Database.getQueryLocator(query);
       }
       
       global void execute(Database.BatchableContext BC, List<contact> scope){
        
        for(contact con: scope){     ----  No Coverage
            if(con.ownerid!=con.Account.ownerid){    ----  No Coverage
                con.ownerid = con.Account.ownerid;     ----  No Coverage
                contactsToChangeOwner.add(con);    ----  No Coverage
            }           
        }
        update contactsToChangeOwner;      ----  No Coverage
       }
       
    global void finish(Database.BatchableContext BC){}
    
    global void execute(SchedulableContext sc)
    {
      Database.executeBatch(new UpdateContactOwnerToAccountOwnerBatch ());
    } 
    
    
    
}

If someone would review my Test Class it would be greatly appreciated.
Cheers,
M
 
Hello,
I have a trigger that is not not reaching the 75% threshold.
I have 2 lines of code where I am calling another Class.  Any help would be greatly appreciated.
trigger warrantyValueCalculation on Warranties_and_Surveys__c (before insert, before update) {
    for (Warranties_and_Surveys__c warRec: trigger.new)
    {
         if((trigger.isInsert) && (warRec.Warranty_Survey_Account__c=='123' || warRec.Warranty_Survey_Account__c=='456' || warRec.Warranty_Survey_Account__c=='789' || warRec.Warranty_Survey_Account__c=='136' || warRec.Warranty_Survey_Account__c=='764' || warRec.Warranty_Survey_Account__c=='111')&&(warRec.Project_Country__c=='US')){
         warrantyAmountCalculation.beforeInsert(trigger.new); ---no coverage
        }
        //if((trigger.isUpdate) && ((trigger.oldMap.get(warRec.Id).Registration_Status__c == 'Registered') && (warRec.Registration_Status__c == 'Registered'))){
         if((trigger.isUpdate) && (warRec.Warranty_Survey_Account__c=='001f100001M2FVP' || warRec.Warranty_Survey_Account__c=='876' || warRec.Warranty_Survey_Account__c=='590' || warRec.Warranty_Survey_Account__c=='327' || warRec.Warranty_Survey_Account__c=='970' || warRec.Warranty_Survey_Account__c=='327')&&(warRec.Project_Country__c=='US')){
         warrantyAmountCalculation.beforeInsert(trigger.new); ---no coverage
        }
    }

}

 
Currently I am captuign a users location via script within a visualforce page.
<script>
    window.onload = function() {
        var startPos;
        var geoSuccess = function(position) {
            startPos = position;
            document.getElementById('{!$Component.inpform.pb.pbs.startLat}').value=startPos.coords.latitude;
            document.getElementById('{!$Component.inpform.pb.pbs.startLon}').value=startPos.coords.longitude;
            //alert('@@@ ' + document.getElementsByClassName('findclass')[0].value);
           document.getElementsByClassName('Latclass')[0].value =startPos.coords.latitude;
           document.getElementsByClassName('Lonclass')[0].value =startPos.coords.longitude;

        };
        navigator.geolocation.getCurrentPosition(geoSuccess);
    };
  </script>

This is fine but makes I cannot reuse the logic.  Would it be a better option to use in in a Apex Class so that the location capturing process can be used on any Object?  If so, how can I make the Class univeral to any object?
Thanks
Hello,
Been trying to figure out how to save the latitude and latitude of the users current location when they save a custom record via a visualforce page.  I was able to use 
document.getElementById('startLat').value=startPos.coords.latitude;

and this would grab the latitude but I have not been able to save the value to the record. 

Is there a better way to aquaire the Lat and long of a users current location when the record is created and then saving the lat and long to the custom record.  
Thanks
Hello,
I have a script that gets the lat and long of a user when they initiate a VF page.
</script>
</head> 
<div id="startLat">
</div>
<div id="startLon">
</div>

<script>
    window.onload = function() {
        var startPos;
        var geoSuccess = function(position) {
            startPos = position;
            document.getElementById('startLat').innerHTML = startPos.coords.latitude;
            document.getElementById('startLon').innerHTML = startPos.coords.longitude;
        };
        navigator.geolocation.getCurrentPosition(geoSuccess);
    };
</script>
This works great but I am unable to bind it to the custom lat and long fields on the record.
I have tried both apex:outputField  and apex:inputputField and still unable to to save the lat and long field to the record
<label style="display:block;margin-top:12px;" for="Latitude__c"><span style="color:red;">*</span>Latitude</label>  <apex:inputField style="margin-left:0;" id="startLan" value="{!SourcingAudit.Latitude__c}" />
                    
                     <label style="display:block;margin-top:12px;" for="Longitude__c"><span style="color:red;">*</span>Longitude</label>    <apex:outputField style="margin-left:0;" id="startLon" value="{!SourcingAudit.Longitude__c}" />
Le me know what I am doing incorrect or if there is a better option.

Thanks

 
Hello everyone,
I have a visualforce page thatreside on a public website.
The user enters information on 2 fields.  Then completes a  captcha. 
The user then clicks a button on the VF page.
Assuming the Captcha is succesful I need to go back to the Salesforce org to return Acount data based on the 2 field and populate fields on the same VF page.  I am familiar passing information from Salesforce to a VF page but I am not sure how to retrieve the data from Salesforce based on user input on a VF page.  Any suggestions would be greatly appreciated.

Thanks
Hello All,
I am trying to work with the ActivityHistory Object and wanted to confirm what I think the issue is.
I have a query where I want to return records where the record does not contain an activty:
Select Id,Name FROM test__c  WHERE  Status__c='Registered' AND ID NOT IN (SELECT WhatID FROM ActivityHistories where Activity_Subtype__c='stuff')

I am assuming that it is not possible to query against the ActivityHistory object correct?
Hello,
I have an Apex Trigger that I needs to perform the following:
  • prevent duplicate lead from being inserted during an import
  • add task to existing Lead that was found within SF
The trigger belows does meet my requiremtns except that it also adds a task to the newly inserted Lead.  The Newly inserted Lead does not exsit in Salesforce so I am not sure why a task is being added.
trigger LeadPreventDuplicate on Lead (after insert,after update) {

    Map<String, Lead> leadMap = new Map<String, Lead>();

      for (Lead lead : System.Trigger.new) 
      { 

       if ((lead.Email != null) && (System.Trigger.isInsert ||
            (lead.Email != System.Trigger.oldMap.get(lead.Id).Email))) 
            {
              leadMap.put(lead.Email, lead);
            }
      }

      List<task> addtask=New List<task>();
     
      for (Lead lead : [SELECT Email FROM Lead WHERE Email IN :leadMap.KeySet()]) 
      {
        Lead newLead = leadMap.get(lead.Email);
        addtask.add(new Task(
        WhoID =lead.id, 
        Status = 'Active',
        Subject = 'Test Task',
        ActivityDate = system.today()));
      
       } 
       insert addtask; 
      
       Lead[] dupes = new Lead[0];
          Set<String> email = new Set<String>(), dupEmail = new Set<String>();
              for(Lead record: Trigger.new)
              email.add(record.email);
              email.remove(null);
              for(Lead record: [SELECT Id, Email FROM Lead WHERE Email IN :email])
                    if(!Trigger.newMap.containsKey(record.id))
                    dupEmail.add(record.Email);
              for(Lead record: Trigger.new)
        if(dupEmail.contains(record.Email))
            dupes.add(record.clone(true));
        else
            dupEmail.add(record.Email);
    delete dupes;
}

Thanks for the assistance.
M