• David Zhu 8
  • NEWBIE
  • 45 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 14
    Replies
Hi All,
I came across an issue of getting the Id of file loaded by community users.

In my case, community users can load file to a record of a custom object through Notes and Attachments related list.

I understand the file is loaded to contentversion object.

I tried to run soql: select id,title,owner.name from contentVersion. But the files are not listed until I share the file to admin (myself).

I am able to get those files through "Files" tab in Salesforce.

What is the trick here?

Thanks,
David
HI All,
We have a third party application which uses Visualforce page as REST API endpoint.
I checked the code and configuration and found there is NO connected app created in salesforce.

I was told that the third party application uses oauth2 to authenticate in Salesforce and sends http request to visual force page url, then reads the content of the visualforce page.
In the loggin history, I can see the login type is "other apex API".
On visualforce page, it is very simple
<apex:page contentType="text/plain; charset=UTF-8" controller="MobileIntegrationController" sidebar="false" showHeader="false" showChat="false" action="{!init}">
    {!responseString}
</apex:page>

It uses controller to generate the responseString and put as the content of the VF page.

Can someone please help me on this?

Thanks,
David

 
I am using Partner WSDL and C# to connect to Salesforce. Login has no issue.
After login, I am trying to access a VF Page and get the content but no luck. I am keeping getting this error.
I believe it is the sessionID was not passed properly. What could be wrong? My code is attached.

Thanks,
David
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

<script>
if (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('https://test.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.cs20.visual.force.com%252Fapex%252Fpromopage'); }  else 
if (window.location.replace){ 
window.location.replace('https://test.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.cs20.visual.force.com%252Fapex%252Fpromopage');
} else {;
window.location.href ='https://test.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.cs20.visual.force.com%252Fapex%252Fpromopage';
} 
</script>

</head>

</html>


<!-- Body events -->
<script type="text/javascript">function bodyOnLoad(){if(window.PreferenceBits){window.PreferenceBits.prototype.csrfToken="null";};}function bodyOnBeforeUnload(){}function bodyOnFocus(){}function bodyOnUnload(){}</script>
			
</body>
</html>


<!--
...................................................................................................
...................................................................................................
...................................................................................................
...................................................................................................
-->


 
​string /userName = "xxx@xxx.com.full";
            string password = "xxxxxxxFbrTKKU8nrvr00Aq3TG9";

            SFDCPartner.SforceService SfdcBinding = null;
            SFDCPartner.LoginResult CurrentLoginResult = null;
            SfdcBinding = new SFDCPartner.SforceService();

            try
            {
                CurrentLoginResult = SfdcBinding.login(userName, password);

                SfdcBinding.SessionHeaderValue = new SFDCPartner.SessionHeader();
                SfdcBinding.SessionHeaderValue.sessionId = CurrentLoginResult.sessionId;
                SfdcBinding.Url = CurrentLoginResult.serverUrl;

                

                var request = (HttpWebRequest)WebRequest.Create("https://cs20.salesforce.com/apex/promopage");

                var postData = "promo={\"Type\":\"TestMethod\",\"UserName\":\"4991431\",\"Password\":\"123\",\"Program\":\"Test\"}";
                var data = Encoding.ASCII.GetBytes(postData);

                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = data.Length;

                request.Headers.Add("Authorization", "Bearer " + CurrentLoginResult.sessionId);

                //request.Headers.Add("SESSIONID", CurrentLoginResult.sessionId);

                using (var stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                System.IO.Stream data1 = response.GetResponseStream();
                string html = String.Empty;
                using (StreamReader sr = new StreamReader(data1))
                {
                    html = sr.ReadToEnd();
                }
                

            }
            catch (Exception e)
            {
                // This is something else, probably comminication
                SfdcBinding = null;
                throw (e);
            }





 
Hi All,
I have a application requires using asymmetric cryptography to encrypt/decrypt messages in Apex code. Salesforce currently has not built in functions for that.
I have no experiece with encryption. Can someone shed some light how to implement that? or if there is salesforce App could be used?

Thanks,
David
HI All,
Our company needs to build public facing website using Salesforce Sites. It would be roughly 20 sites in total.
I read some posts mentioning there is a limit of 500,000 page view per month for Enterprise edition (which our company uses). without extra cost
I have some questions regarding this.
1.Can someone please provide me the office SFDC url regarding the page view limit?
2.How the page view is calculated? ie. On a VF page, checkbox A controls the visibility of an outputpanel B. Is it counted as a page view every time the user check or uncheck the checkbox A?
3.I would like to know 500,000 Page view is for all sites or only one site.

Thanks,
David
Hi All,
We have a requirement to load Salesforce data to Azure SQL DB by developing an Azure Application. I have no knowledge of Azure but with strong experiece of C# and SQL.
Can someone please give me some ideas where to start regarding Salesforce/Azure integration?

Thanks,
David
 
Hi All,
We have a custom field set on Case object. We use it to build soql query string dynamically using schema.field set class.

i.e we have field set named: CaseFieldSet. It has three fields added:  Status,Priority, and Subject. Those fields were added to CaseFieldSet in different time.

We have a requirement to get the datetime for each field added to the field set. It means we want to know what exact time of those three fields were added to CaseFieldSet.

I assume the soqy would be similar to :
select id, createddate from fieldset where name = 'CaseFieldSet'

If having no such hidden object, how can I get the date time?

Thanks,
David
I have Sandbox on CS4. It started getting error message: "Invalid State Code Invalid state specified for field" this Monday on one of my visual force page. Instead of showing the correct infomration on the page, it only shows this error message on the screen.

The page was fine in the past even on last Friday. There was no change in the last week. This sandbox is only used by me.

My Visualfoce page actually uses google map which could cause this error.  I tried debug in Salesforce and Developer tool in Chrome but no indication of such error.

I search my code,validation rule, trigger, workflow rule, and there is no place to display such error message.

The only change I noticed is SFDC upgraded this sandbox to Windows'16.

Does any one experience the same issue?

Thanks,
David

 
Hi All,
We experienced a very weired issue last month. I am struggling to find the root cause.
We have a Visualforce page used by all users. This happened at mid-night EST roughly from 11:30PM to 1:00AM.
All users got an error message saying:
 
An administrator has changed the definition of page or component /apex/takecall. Refresh your page and try again
Previous version = 30. Current version = 29.”
 
This type of error message usually means a changed has been made to the page while it is in use.
We confirmed nobody changed the code during that time. Actually, the last code change was two months ago.

If you take a look of the red highlighted text, it says current version is lower than previous version. The version is reverted.

Have you every seen such problem before? Salesforce support says it is our vf page issue.

Thanks,
David
 
Hi all,
I came across a problem that SOSL returns less rows than expected. SOQL returns the right number of rows.
Basically, in below snippet, I tried to get all rows which string 205640 exists in vin_person__c field.
SOSL only returns 2 rows. But SOQL return 6 rows including 2 rows in SOSL result.

What could be the problem?
 
list<list<sobject>> slist =[FIND '*205640*'  IN all FIELDS RETURNING VIN__c (Id,Name,Program__c,VIN_Person__c,Person__c,Car__c where Program__r.Account__c='001o000000ODW6lAAH' AND Inactive__c=FALSE ) LIMIT 100];

system.debug(slist);

list<vin__c> svin = [select Id,Name,Program__c,VIN_Person__c,Person__c,Car__c from vin__c where Program__r.Account__c='001o000000ODW6lAAH' AND VIN_Person__c LIKE '%205640%' AND Inactive__c=FALSE LIMIT 100];
system.debug(svin);



Thanks,
David
 
We have an Service Cloud application using custom VF Pages. 
In the mostly used page, there are 1200 lines of Javascript and 300 lines of style setting in a 3000 lines VF page. I don't think it is the best practice at all.

Javascript uses Salesforce Remoting to interact with Salesforce class.
The following is a snippet.
Visualforce.remoting.Manager.invokeAction(
                    '{!$RemoteAction.CaseExtension.findVINs}',
                    query,
                    programQueryFilter,
                    typeOfCase,
                    function(lstresult, event){        
                        for (var n=0; n<lstresult.length; n++){
                            var result = {
                                value: lstresult[n].Id,
                                label: lstresult[n].VIN_Person__c, 
                                name: lstresult[n].Name, 
                                car: lstresult[n].Car__c,
                                person: lstresult[n].Person__c
                            };
                            data.push(result);
                        }
                        callback(data);
                    }
                );


On this page, it has different sections to display different information. Users use buttons to switch displayed sections.

Users are complaining, when switching the information section, some entered information is missing, or dropdown is not populated.

Could thie problem be related to the performance of Salesforce Remoting from Javascript?

What is the best practice to move javascript and styles into static resource?

Thanks,
David



 
Hi All,
I came across a scenario that I noticed one class was not updated by a developer by checking the class's modified date and name.
Then I was told he did "Soft Save". I asked what is "soft save". He said " A "soft save" is simply the action of clicking edit, then clicking save (without making changes), hence the change in the last modified date."

I really cannot do "soft save" on my own. I always get time modifed if using his method.

Did somebody know "soft save" in salesforce?

Thanks,
David
Hi all,
I have a VF page displaying google map.
I want to archive two goals:
1. displaying case locations on the map.
2.when click marker on the map, the related case will be open.

I don't have any issue to display those locations on the map.The problem is when clicking any marker, it always opens the last case in both Console or non console application.
Can someone help me out?



Thanks,
David
 
for (var i = 0; i < locations.length; i++) 
{
    try
    {
        var icn = "/resource/Img/reddot.png";
       	
						    	
        var marker = new google.maps.Marker({
                title: locations[i].title,
                position: new google.maps.LatLng(locations[i].lat, locations[i].lng),
                icon: icn,
                url: locations[i].url,
                map: map
            });

        google.maps.event.addListener(marker, 'click', function () {
        if(isConsole)
            sforce.console.openPrimaryTab(null,marker.url,true,marker.casenumber,function(result){},marker.casenumber);
        else
            window.open( marker.url,'_blank');
        });
			
    }
    catch(err){}
}

 
Hi All,
Our Salesforce application uses web service callout to intergrate to a partner's system (non-salesforce).
The partner is asking if it is OK to enable TLS 1.1/1.2 on their firewal.
I refered to this document https://help.salesforce.com/apex/HTViewSolution?id=000221207
Browser supports TLS 1.1/1.2.
My questions are:
1. from code wise, do we need to make any change?
2. Do I need to enabled TLS in my Salesforce org?
3. We have other partners not using TLS 1.1/1.2. Will the same code work for both?

This is the code snippet:
 
HttpRequest req = new HttpRequest();
        String end_point = host+(port!=NULL?+(':'+port):'')+url_path+url_params+starter;

        req.setEndpoint(end_point);
        req.setMethod('GET');
        req.setTimeout(5000);
        try {
            Http http = new Http();
            HTTPResponse res;
            res = http.send(req);

            final_url = 'Success';
            final_url+=('\n\n'+res.getBody());
            final_url+=('\n\n'+req.toString());
            integration.Parameters__c=(integration.Parameters__c+'\n\n'+final_url);
            //update integration;
        } catch(Exception e) {
            final_url = 'Error: ' + e.getMessage();
            final_url+=('\n\n'+req.toString());
            integration.Parameters__c=(integration.Parameters__c+'\n\n'+final_url);
            
        }




Thanks,
David

 
Hi All,
I have a Javascript function to get case geolocation information and put on google map. I follow Salesforce Ajax Kit Dev Guide, but it keeps get "undefined" value when getting the query result. Specifically, in the following lines:

var cid = car.id;
var lat =car.Breakdown_Location__latitude__s;
var lng =car.Breakdown_Location__longitude__s;
alert(cid); //show undefined
alert(lat); //show undefined
alert(lng); //show undefined

I can see local variable "car" has value ""{"type":"Case","Id":"500P0000004ILDvIAO","Breakdown_Location__Latitude__s":"44.8561002","Breakdown_Location__Longitude__s":"-79.9970188"}".

What am I missing?

Thanks,
David
function loadMap() 
    {
    
        var latlng = new google.maps.LatLng(54.351179,-95.502741);
        var myOptions = {
        zoom: 5,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP};
        
        map = new google.maps.Map(document.getElementById("map_canvas"),  myOptions);   
        sforce.connection.sessionId = "{!$Api.Session_ID}";
        var result = sforce.connection.query("select id,Breakdown_Location__latitude__s,Breakdown_Location__longitude__s from case where createddate > 2016-01-10T00:00:00Z and Breakdown_Location__longitude__s <> null limit 3");
        
        //alert(result);
        
        var records = result.getArray("records");
       

        for (var i = 0;i<records.length;i++) 
        {
            //alert(records[i]);

            //debugger;
            
            var car = records[i];   
            //alert(car);
            //debugger;
            var cid = car.id;
            var lat =car.Breakdown_Location__latitude__s;
	        var lng =car.Breakdown_Location__longitude__s;
            //debugger;
			   
           alert(cid); //show undefined
	   alert(lat);   //show undefined
	   alert(lng);  //show undefined
            
            
            marker = new google.maps.Marker({  
            position: new google.maps.LatLng(lat,lng),  
                map: map});      
        }

​

 
Hi there,
If  salesforce ip ranges are  whitelisted on my company's network, does it mean it opens the door for all Salesforce applications to access to my company's network?
If yes, how to limit only my salesforce org's application to access?

thanks,
David
Hi,
I had a dev org which used my yahoo email as login ID. But I use my previous employer's email as contact email.
The problem comes up when I moved to another company. When i login to my DEV org, it asks for verification code which was sent to my previous employer's email. I contacted SFDC support and was told coming to this forum for help.
How to fix this problem?

Thanks,
David
HI All,
Our company needs to build public facing website using Salesforce Sites. It would be roughly 20 sites in total.
I read some posts mentioning there is a limit of 500,000 page view per month for Enterprise edition (which our company uses). without extra cost
I have some questions regarding this.
1.Can someone please provide me the office SFDC url regarding the page view limit?
2.How the page view is calculated? ie. On a VF page, checkbox A controls the visibility of an outputpanel B. Is it counted as a page view every time the user check or uncheck the checkbox A?
3.I would like to know 500,000 Page view is for all sites or only one site.

Thanks,
David
Hi All,
Our Salesforce application uses web service callout to intergrate to a partner's system (non-salesforce).
The partner is asking if it is OK to enable TLS 1.1/1.2 on their firewal.
I refered to this document https://help.salesforce.com/apex/HTViewSolution?id=000221207
Browser supports TLS 1.1/1.2.
My questions are:
1. from code wise, do we need to make any change?
2. Do I need to enabled TLS in my Salesforce org?
3. We have other partners not using TLS 1.1/1.2. Will the same code work for both?

This is the code snippet:
 
HttpRequest req = new HttpRequest();
        String end_point = host+(port!=NULL?+(':'+port):'')+url_path+url_params+starter;

        req.setEndpoint(end_point);
        req.setMethod('GET');
        req.setTimeout(5000);
        try {
            Http http = new Http();
            HTTPResponse res;
            res = http.send(req);

            final_url = 'Success';
            final_url+=('\n\n'+res.getBody());
            final_url+=('\n\n'+req.toString());
            integration.Parameters__c=(integration.Parameters__c+'\n\n'+final_url);
            //update integration;
        } catch(Exception e) {
            final_url = 'Error: ' + e.getMessage();
            final_url+=('\n\n'+req.toString());
            integration.Parameters__c=(integration.Parameters__c+'\n\n'+final_url);
            
        }




Thanks,
David

 
HI All,
We have a third party application which uses Visualforce page as REST API endpoint.
I checked the code and configuration and found there is NO connected app created in salesforce.

I was told that the third party application uses oauth2 to authenticate in Salesforce and sends http request to visual force page url, then reads the content of the visualforce page.
In the loggin history, I can see the login type is "other apex API".
On visualforce page, it is very simple
<apex:page contentType="text/plain; charset=UTF-8" controller="MobileIntegrationController" sidebar="false" showHeader="false" showChat="false" action="{!init}">
    {!responseString}
</apex:page>

It uses controller to generate the responseString and put as the content of the VF page.

Can someone please help me on this?

Thanks,
David

 
I am using Partner WSDL and C# to connect to Salesforce. Login has no issue.
After login, I am trying to access a VF Page and get the content but no luck. I am keeping getting this error.
I believe it is the sessionID was not passed properly. What could be wrong? My code is attached.

Thanks,
David
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

<script>
if (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('https://test.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.cs20.visual.force.com%252Fapex%252Fpromopage'); }  else 
if (window.location.replace){ 
window.location.replace('https://test.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.cs20.visual.force.com%252Fapex%252Fpromopage');
} else {;
window.location.href ='https://test.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.cs20.visual.force.com%252Fapex%252Fpromopage';
} 
</script>

</head>

</html>


<!-- Body events -->
<script type="text/javascript">function bodyOnLoad(){if(window.PreferenceBits){window.PreferenceBits.prototype.csrfToken="null";};}function bodyOnBeforeUnload(){}function bodyOnFocus(){}function bodyOnUnload(){}</script>
			
</body>
</html>


<!--
...................................................................................................
...................................................................................................
...................................................................................................
...................................................................................................
-->


 
​string /userName = "xxx@xxx.com.full";
            string password = "xxxxxxxFbrTKKU8nrvr00Aq3TG9";

            SFDCPartner.SforceService SfdcBinding = null;
            SFDCPartner.LoginResult CurrentLoginResult = null;
            SfdcBinding = new SFDCPartner.SforceService();

            try
            {
                CurrentLoginResult = SfdcBinding.login(userName, password);

                SfdcBinding.SessionHeaderValue = new SFDCPartner.SessionHeader();
                SfdcBinding.SessionHeaderValue.sessionId = CurrentLoginResult.sessionId;
                SfdcBinding.Url = CurrentLoginResult.serverUrl;

                

                var request = (HttpWebRequest)WebRequest.Create("https://cs20.salesforce.com/apex/promopage");

                var postData = "promo={\"Type\":\"TestMethod\",\"UserName\":\"4991431\",\"Password\":\"123\",\"Program\":\"Test\"}";
                var data = Encoding.ASCII.GetBytes(postData);

                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = data.Length;

                request.Headers.Add("Authorization", "Bearer " + CurrentLoginResult.sessionId);

                //request.Headers.Add("SESSIONID", CurrentLoginResult.sessionId);

                using (var stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                System.IO.Stream data1 = response.GetResponseStream();
                string html = String.Empty;
                using (StreamReader sr = new StreamReader(data1))
                {
                    html = sr.ReadToEnd();
                }
                

            }
            catch (Exception e)
            {
                // This is something else, probably comminication
                SfdcBinding = null;
                throw (e);
            }





 
Hi All,
I have a application requires using asymmetric cryptography to encrypt/decrypt messages in Apex code. Salesforce currently has not built in functions for that.
I have no experiece with encryption. Can someone shed some light how to implement that? or if there is salesforce App could be used?

Thanks,
David
Hi All,

Just so I'm clear, I am not a developer. I can kind of read it and make small changes, but trying to learn to write it gives me a headache.

I have a vf page that was created for me, but when a Save is done it is saving all fields instead of just the fields that were edited. This is causing issues of data being deleted because the change was made in a record and not on the vf page. I hope that made sense. 

Here is the page and controller. I do hope that someone can help with a small change to this code and a whole new page doesn't have to be created.
I cannot paste all code with the limit of 32,000 characters.

<apex:page controller="MyOpenTasksController">
    <apex:includeScript value="{!$Resource.JS_Busy_Indicator}"/>
    <script>
        function showFilterData(){
            filterData();
        }
        function setUser(){
            setUser();
        }
        var xval;
        function block_viewport() {
            xval=getBusyOverlay('viewport',{color:'black', opacity:0.35, text:'processing...', style:'text-shadow: 0 0 3px black;font-weight:bold;font-size:12px;color:white'},{color:'#fff', size:75, type:'o'});
        }
    </script>
    <apex:form id="frm">
    
    <apex:actionFunction name="filterData" action="{!filterTaskData}" reRender="frm,pgBlock" oncomplete="xval.remove();"/>
    <apex:actionFunction name="setUser" action="{!setCurrentUser}" reRender="frm,pgBlock" oncomplete="xval.remove();"/>
    
    <apex:pageBlock title="My Open Tasks" id="pgBlock">
    
    
        <apex:pageBlockButtons >
            <apex:commandButton onclick="block_viewport();" oncomplete="xval.remove();" value="Update To Tomorrow" action="{!updateToTomorrow}" reRender="frm,pgBlock" disabled="{!Not(taskList.size > 0)}"/>
            <apex:commandButton onclick="block_viewport();" oncomplete="xval.remove();" value="Save" action="{!saveChanges}" reRender="frm,pgBlock" disabled="{!Not(taskList.size > 0)}"/>            
            <apex:commandButton onclick="block_viewport();" oncomplete="xval.remove();" value="Cancel" action="{!cancelChanges}" reRender="frm,pgBlock" disabled="{!Not(taskList.size > 0)}"/>
        </apex:pageBlockButtons>
        <br/>
        <apex:outputPanel >
            
            
Controller:
public with sharing class MyOpenTasksController {

    public String eventObject { get; set; }
    public Integer recordsSize {get;set;}
    public Integer totalNumberOfPages { get; set; }
    public Integer pageNumber {get;set;}
    public Boolean hasNext {get;set;}
    public Boolean hasPrevious {get;set;}
    
    public List<SelectOption> contactAttendeeList{get;set;}
    public List<SelectOption> mailingStateList{get;set;}
    public List<SelectOption> activeUsersList{get;set;}
    public Id selectedUserId {get;set;}
    public boolean showUserPicklist {get;set;}
    public String selectedAttendee{get;set;}
    public String selectedState{get;set;}
    public string selectedPriority {get;set;}
    public string selectedTimezone {get;set;}
    
    public List<Task> taskList {get;set;}
    
    private List<Id> taskListWithAllRecords;
    private Integer noOfRecordsPerPage = 50;
    
    public MyOpenTasksController(){
        activeUsersList = new List<SelectOption>();
        
        showUserPicklist = false;
        for(User_Information__c usrInfo : User_Information__c.getAll().values()){
            if(usrInfo.User_Id__c == String.valueOf(UserInfo.getUserId()).substring(0,15)){
                showUserPicklist = true;
            }
        }
        selectedUserId = UserInfo.getUserId();
        activeUsersList.add(new SelectOption(UserInfo.getUserId(),'Current User'));
        for(User usr : [Select Id, Name from User where IsActive = true]){
            if(usr.id != UserInfo.getUserId()){
                activeUsersList.add(new SelectOption(usr.Id,usr.Name));
            }
        }
        populateSelectOptions();
        populateTaskData();
    }
    
    private void populateTaskData(){
        recordsSize = 0;
        totalNumberOfPages = 0;
        pageNumber = 0;
        hasNext = false;
        hasPrevious = false;
        
        //taskList = new List<Task>();
        taskListWithAllRecords = new List<Id>();
        // String Query to have a list of cases for a respective End-user.
        //String soql = 'Select ActivityDate, Status, Priority, Atendee__c, Dummy_Contact__c, WhatId,Dummy_Contact__r.Name,What.Name, Description, Dummy_Contact__r.Title, Dummy_Contact__r.Key_Exec__c, Dummy_Contact__r.Exec_Type__c, Dummy_Contact__r.Direct_Dial__c, Dummy_Contact__r.MobilePhone, Dummy_Contact__r.Phone, Dummy_Contact__r.MailingState, Dummy_Contact__r.Timezone__c, Dummy_Contact__r.Task_Attendee__c from Task where IsClosed = false AND OwnerID =:selectedUserId';
        
        String soql = 'Select id from Task where IsClosed = false AND OwnerID =:selectedUserId';
        if(selectedPriority == null && selectedTimezone == null  && selectedAttendee == null  && selectedState == null){
            
        }
        else if (selectedPriority != null && selectedTimezone == null  && selectedAttendee == null  && selectedState == null){
            soql = soql + ' AND Priority = :selectedPriority '; 
        }
        else if(selectedPriority == null && selectedTimezone != null  && selectedAttendee == null  && selectedState == null){
            soql = soql + ' AND Dummy_Contact__r.Timezone__c = :selectedTimezone '; 
        }
        else if(selectedPriority == null && selectedTimezone == null  && selectedAttendee != null  && selectedState == null){
            soql = soql + ' AND Attendee__c = :selectedAttendee '; 
        }
        else if(selectedPriority == null && selectedTimezone == null  && selectedAttendee == null  && selectedState != null){
            soql = soql + ' AND Dummy_Contact__r.MailingState = :selectedState '; 
        }
        else if(selectedPriority != null && selectedTimezone != null  && selectedAttendee == null  && selectedState == null){
            soql = soql + ' AND Priority = :selectedPriority AND Dummy_Contact__r.Timezone__c = :selectedTimezone '; 
        }
        else if(selectedPriority == null && selectedTimezone != null  && selectedAttendee != null  && selectedState == null){
            soql = soql + ' AND Dummy_Contact__r.Timezone__c = :selectedTimezone AND Attendee__c = :selectedAttendee '; 
        }
        else if(selectedPriority != null && selectedTimezone == null  && selectedAttendee != null  && selectedState == null){
            soql = soql + ' AND Priority = :selectedPriority AND Attendee__c = :selectedAttendee ';
        }
        else if(selectedPriority != null && selectedTimezone == null  && selectedAttendee == null  && selectedState != null){
            soql = soql + ' AND Priority = :selectedPriority AND Dummy_Contact__r.MailingState = :selectedState ';
        }
        else if(selectedPriority == null && selectedTimezone != null  && selectedAttendee == null  && selectedState != null){
            soql = soql + ' AND Dummy_Contact__r.Timezone__c = :selectedTimezone AND Dummy_Contact__r.MailingState = :selectedState ';
        }
        else if(selectedPriority == null && selectedTimezone == null  && selectedAttendee != null  && selectedState != null){
            soql = soql + ' AND Attendee__c = :selectedAttendee AND Dummy_Contact__r.MailingState = :selectedState ';
        }
        else if(selectedPriority != null && selectedTimezone != null  && selectedAttendee != null  && selectedState == null){
            soql = soql + ' AND Priority = :selectedPriority AND Dummy_Contact__r.Timezone__c = :selectedTimezone AND Attendee__c = :selectedAttendee ';
        }
        else if(selectedPriority != null && selectedTimezone != null  && selectedAttendee == null  && selectedState != null){
            soql = soql + ' AND Priority = :selectedPriority AND Dummy_Contact__r.Timezone__c = :selectedTimezone AND Dummy_Contact__r.MailingState = :selectedState ';
        }
        else if(selectedPriority != null && selectedTimezone == null  && selectedAttendee != null  && selectedState != null){
            soql = soql + ' AND Priority = :selectedPriority AND Attendee__c = :selectedAttendee AND Dummy_Contact__r.MailingState = :selectedState ';
        }
        else if(selectedPriority == null && selectedTimezone != null  && selectedAttendee != null  && selectedState != null){
            soql = soql + ' AND Dummy_Contact__r.Timezone__c = :selectedTimezone AND Attendee__c = :selectedAttendee AND Dummy_Contact__r.MailingState = :selectedState ';
        }
        else{
            soql = soql + ' AND Priority = :selectedPriority AND Dummy_Contact__r.Timezone__c = :selectedTimezone AND Attendee__c = :selectedAttendee AND Dummy_Contact__r.MailingState = :selectedState ';
        }
        
        // Passing the String array to a list with Selected field sorting.
        for(Task tsk : Database.query(soql + ' order by ' + sortExpression + ' ' + sortDirection  + ' NULLS LAST')){
            taskListWithAllRecords.add(tsk.id);
        }
        
        recordsSize = taskListWithAllRecords.size();
        if(Math.mod(recordsSize,noOfRecordsPerPage) != 0){
            totalNumberOfPages = (recordsSize / noOfRecordsPerPage) + 1;
        }
        else{
            totalNumberOfPages = recordsSize / noOfRecordsPerPage;
        }
        Set<Id> taskIds = new Set<Id>();
        if(recordsSize > noOfRecordsPerPage){
            for(Integer i=pageNumber*noOfRecordsPerPage ; i<noOfRecordsPerPage ; i++){
                taskIds.add(taskListWithAllRecords[i]);
            }
            hasNext = true;
        }
        else{
            taskIds.addAll(taskListWithAllRecords);
        }
        pageNumber++;
        
        String soqlQuery = 'Select ActivityDate, Status, Priority, Attendee__c, Dummy_Contact__c, WhatId,Dummy_Contact__r.Name,What.Name, Description, Dummy_Contact__r.Title, Dummy_Contact__r.Key_Exec__c, Dummy_Contact__r.Exec_Type__c, Dummy_Contact__r.Direct_Dial__c, Dummy_Contact__r.MobilePhone, Dummy_Contact__r.Phone, Dummy_Contact__r.MailingState, Dummy_Contact__r.Timezone__c, Dummy_Contact__r.Attendee_Contact__c, Dummy_Contact__r.Task_Attendee__c from Task where Id In :taskIds order by ' + sortExpression + ' ' + sortDirection  + ' NULLS LAST';
        taskList = new List<Task>();
        taskList = Database.query(soqlQuery);
    }
    
    private void populateSelectOptions(){
        contactAttendeeList = new List<SelectOption>();
        contactAttendeeList.add(new SelectOption('','---None---'));
        
        mailingStateList = new List<SelectOption>();
        mailingStateList.add(new SelectOption('','---None---'));
        Set<String> setOfAttendee = new Set<String>();
        Set<String> setOfStates = new Set<String>();
        for(Task tsk : [Select Attendee__c,Dummy_Contact__r.Task_Attendee__c, Dummy_Contact__r.MailingState from Task where IsClosed = false AND OwnerID =:selectedUserId]){
            if(tsk.Attendee__c != null){
                setOfAttendee.add(tsk.Attendee__c);
            }
            if(tsk.Dummy_Contact__r.MailingState != null){
                setOfStates.add(tsk.Dummy_Contact__r.MailingState);
            }
        }
        if(setOfAttendee.size() > 0){
            List<String> sortedListOfAttendee = new List<String>();
            sortedListOfAttendee.addAll(setOfAttendee);
            sortedListOfAttendee.sort();
            for(String attendee : sortedListOfAttendee){
                contactAttendeeList.add(new SelectOption(attendee,attendee));
            }
        }
        if(setOfStates.size() > 0){
            List<String> sortedListOfStates = new List<String>();
            sortedListOfStates.addAll(setOfStates);
            sortedListOfStates.sort();
            for(String state : sortedListOfStates){
                mailingStateList.add(new SelectOption(state, state ));
            }
        }
    }
    
    // returns the previous page of records
    public void previous() {
        hasNext = true;
        //taskList = new List<Task>();
        Set<Id> taskIds = new Set<Id>();
        pageNumber--;
        for(Integer i= (pageNumber-1)*noOfRecordsPerPage; i<noOfRecordsPerPage*pageNumber ; i++){
            taskIds.add(taskListWithAllRecords[i]);
        }
        if(pageNumber > 1){
            hasPrevious = true;
        }
        else{
            hasPrevious = false;
        }
        
        String soqlQuery = 'Select ActivityDate, Status, Priority, Attendee__c, Dummy_Contact__c, WhatId,Dummy_Contact__r.Name,What.Name, Description, Dummy_Contact__r.Title, Dummy_Contact__r.Key_Exec__c, Dummy_Contact__r.Exec_Type__c, Dummy_Contact__r.Direct_Dial__c, Dummy_Contact__r.MobilePhone, Dummy_Contact__r.Phone, Dummy_Contact__r.MailingState, Dummy_Contact__r.Timezone__c, Dummy_Contact__r.Attendee_Contact__c, Dummy_Contact__r.Task_Attendee__c from Task where Id In :taskIds order by ' + sortExpression + ' ' + sortDirection  + ' NULLS LAST';
        taskList = new List<Task>();
        taskList = Database.query(soqlQuery);
    }

    // returns the next page of records
    public void next() {
        hasPrevious = true;
        //taskList = new List<Task>();
        Set<Id> taskIds = new Set<Id>();
        if((pageNumber+1)*noOfRecordsPerPage < taskListWithAllRecords.size()){
            for(Integer i = pageNumber*noOfRecordsPerPage ; i<(pageNumber+1)*noOfRecordsPerPage ;i++){
                taskIds.add(taskListWithAllRecords[i]);
            }
        }
        else{
            for(Integer i=pageNumber*noOfRecordsPerPage ; i<recordsSize ;i++){
                taskIds.add(taskListWithAllRecords[i]);
            }
            hasNext = false;
        }
        pageNumber++;
        
        String soqlQuery = 'Select ActivityDate, Status, Priority, Attendee__c, Dummy_Contact__c, WhatId,Dummy_Contact__r.Name,What.Name, Description, Dummy_Contact__r.Title, Dummy_Contact__r.Key_Exec__c, Dummy_Contact__r.Exec_Type__c, Dummy_Contact__r.Direct_Dial__c, Dummy_Contact__r.MobilePhone, Dummy_Contact__r.Phone, Dummy_Contact__r.MailingState, Dummy_Contact__r.Timezone__c, Dummy_Contact__r.Attendee_Contact__c, Dummy_Contact__r.Task_Attendee__c from Task where Id In :taskIds order by ' + sortExpression + ' ' + sortDirection  + ' NULLS LAST';
        taskList = new List<Task>();
        taskList = Database.query(soqlQuery);
    }
    
    public void sortData() {
        // simply toggle the direction
        sortDirection = sortDirection.equals('asc') ? 'desc' : 'asc';

        populateTaskData();
    }
    
    // the current sort direction. defaults to asc
    public String sortDirection {
        // To set a Direction either in ascending order or descending order.
        get  { if (sortDirection == null) {  sortDirection = 'asc'; } return sortDirection;}
        set;
    }

    // the current field to sort by. defaults to last name
    public String sortExpression {
        // To set a Field for sorting.
        get  { if (sortExpression == null) {sortExpression = 'ActivityDate'; } return sortExpression;  }
        set;
    } 
    
    public PageReference filterTaskData() {
        populateTaskData();
        return null;
    }
    
    public PageReference updateToTomorrow() {
        DateTime dateToBeChanged = system.Today().addDays(1);
        
        Datetime dt = DateTime.newInstance(System.today(), Time.newInstance(0, 0, 0, 0));
        String dayOfWeek=dt.format('EEEE');
        
        if(dayOfWeek == 'Friday'){
            dateToBeChanged = system.Today().addDays(3);
        }
        else if(dayOfWeek == 'Saturday'){
            dateToBeChanged = system.Today().addDays(2);
        }
        List<Task> listOfTaskToUpdate = new List<Task>();
        for(Task tsk : [Select ActivityDate from Task where IsClosed = false AND OwnerID =:selectedUserId]){
            if(tsk.ActivityDate <= system.today()){
                tsk.ActivityDate = Date.valueOf(dateToBeChanged);
                listOfTaskToUpdate.add(tsk);
            }
        }
        
        if(listOfTaskToUpdate.size() > 0){
            update listOfTaskToUpdate;
        }
        return null;
    }
    
    public PageReference cancelChanges() {
        return null;
    }
    
    public PageReference saveChanges() {
        Set<Id> conIds = new Set<Id>();
        Set<Contact> setOfContacts = new Set<Contact>();
        List<Contact> listOfContactToUpdate = new List<Contact>();
        
        for(Task tsk : taskList){
            if(tsk.Dummy_Contact__c != null){
                conIds.add(tsk.Dummy_Contact__c);
            }
        }
        for(Contact con : [Select Name,Title, Key_Exec__c, Exec_Type__c, Direct_Dial__c, MobilePhone, Phone, MailingState, Timezone__c, Attendee_Contact__c, Task_Attendee__c from Contact where id in :conIds]){
            for(Task tsk : taskList){
                if(tsk.Dummy_Contact__c == con.id){
                    con.Title = tsk.Dummy_Contact__r.Title;
                    con.Key_Exec__c = tsk.Dummy_Contact__r.Key_Exec__c;
                    con.Exec_Type__c = tsk.Dummy_Contact__r.Exec_Type__c;
                    con.Direct_Dial__c = tsk.Dummy_Contact__r.Direct_Dial__c;
                    con.MobilePhone = tsk.Dummy_Contact__r.MobilePhone;
                    con.Phone = tsk.Dummy_Contact__r.Phone;
                    con.MailingState = tsk.Dummy_Contact__r.MailingState;
                    con.Timezone__c = tsk.Dummy_Contact__r.Timezone__c;
                    setOfContacts.add(con);
                }
            }
        }
        if(setOfContacts.size() > 0){
            listOfContactToUpdate.addAll(setOfContacts);
            update listOfContactToUpdate;
        }
        
        if(taskList.size() > 0){
            update taskList;
        }
        return null;
    }
    public PageReference setCurrentUser() {
        populateSelectOptions();
        populateTaskData();
        return null;
    }
}
Hello,

I am creating code that allows me to store the information of my products, such as name, description, price and their relationship in one place on a Visualforce Page. To gather it I am using queries to get all the information I need regarding the products and their relationships. So far the code that I have exceeds the SOQL governor limits. I took out some of the relationships but still having the products and their first relationship causes the limit to be 29 which is too big if I want to add the rest of the relationships and information like I need to do. Since I am new to Apex coding, would anyone be able to look at my code and determine why the queries are running so much? I have looked at the forums and the suggestions that Salesforce has on governor limits and tried my best to follow the advice, but I am not sure I am implementing it properly since I am fairly new to using Apex and programming.

Here is my code:
 
public class CCQueries9 {
    
    List<DisplayProduct> productsParent; 
     
    //Queries the Product Information
    public List<DisplayProduct> getProducts() {
        if(productsParent == null) {
            productsParent = new List<DisplayProduct>();
            List<Product2> item = [SELECT Id, Name, HTML_Description__c FROM Product2 WHERE Account_Relatable__c = true ORDER BY Order__c];
            for(Product2 prod : item ) {
                productsParent.add(new DisplayProduct(prod));            
            }        
        }
        return productsParent; 
    }//End of Query Code
    
    
    public class DisplayProduct {
        
        List<Id> productParentId = new List<Id>();
        List<Id> ChildrenProductIds = new List<Id>();
        List<DisplaySuite> productsChildren {get;set;}
        
        private Product2 product;
        public DisplayProduct(Product2 item) {
            
           this.product = item;
           
            productParentId.add(this.product.Id); 
           
        }
        
        public String name {
            get {return product.Name;}
        }
         
        public String description {
            get {return product.HTML_Description__c;}
        }
        //Code to determine Query Limits
          public String GetCharlie {
            get {return String.valueOf(Limits.getQueries());}
        }

        //Query for the Childrens of Products 
        public List<DisplaySuite> getProductsChildren() {
        	
            if(productsChildren == null) {
            	
            	
         
            List<Product_Relationship__c> relationships = new List<Product_Relationship__c>(); 

         	 
            relationships = [SELECT Master_Product__c, Child_Product__c, CalculatorOrder__c, Child_Product__r.Name 
            				 FROM Product_Relationship__c 
            				 WHERE Master_Product__c IN : productParentId   
            				 ORDER BY CalculatorOrder__c,Child_Product__r.Name]; 
            
            
            for(Product_Relationship__c c:relationships){
               ChildrenProductIds.add(c.Child_Product__c);
            }
            
            if(ChildrenProductIds != null) {
			// query the product2 table for those products in the relationship, store in the final list        
                productsChildren = new List<DisplaySuite>();
                List<Product2> item = [SELECT Id, Name, HTML_Description__c FROM Product2 WHERE Id IN :ChildrenProductIds ORDER BY Order__c]; 
                for(Product2 children : item ) { 
                    productsChildren.add(new DisplaySuite(children));            
                }
            }        
            }
            return productsChildren;
        }
      
        
    }
    
    public class DisplaySuite {
        
        List<Id> productParentId = new List<Id>();
        List<Id> ChildrenProductIds = new List<Id>();
        List<DisplaySuite> productsChildren {get;set;}
        
        private Product2 product;
        
        public DisplaySuite(Product2 item) {
            this.product = item;
            productParentId.add(this.product.Id); 
        }
        public String name {
            get {return product.Name;}
        }
        public String description {
            get {return product.HTML_Description__c;}
        }
        //Code to determine Query Limits
          public String GetCharlie {
            get {return String.valueOf(Limits.getQueries());}
        }
            
     }
      
        
    }

And here is the page that I am calling the information on.
 
<apex:page showHeader="false" sidebar="false" Controller="CCQueries9" standardStylesheets="false">
       
    <apex:repeat value="{!products}" var="pitem"> <!-- Repeat for Product Information -->
      
        <apex:outputPanel >
                
            <apex:outputText escape="false" value="{!pitem.Name}"/><br/>
          		{! pitem.getCharlie } <br/>
            <div style="margin-left: 30px;">
           
            <apex:repeat value="{!pitem.productsChildren}" var="sitem"> <!-- Repeat for Suite Information -->
            
                <apex:outputPanel >                  
           
                    <apex:outputText escape="false" value="{!sitem.Name}"/><br/>
                    	{! sitem.getCharlie } <br/>
          	        	 
                </apex:outputPanel>
          
            </apex:repeat>   
            
            </div>
        
        </apex:outputPanel>
    
    </apex:repeat>  
    
</apex:page>

Thanks for any advice in advance!  
HI,
trigger insertMember2 on Member__c (after insert) {
 Set<Id> Ids= new Set<Id>();
    for (Member__c member : Trigger.new)
    {
        Ids.add(member.Id);        
    }
 List<Member__c> memberList = new List<Member__c>([Select Id,FirstName__c,LastName__c  From Member__c e where Id in :Ids]);

    for(Member__c temp : memberList )
    {
        Member2__c member2 = new Member2();
        member2.FirstName__c = temp.FirstName__c;
        member2.LastName__c = temp.LastName__c;
        insert member2;

    }


 }
Regards,Chanti
 
Hi All,
We have a custom field set on Case object. We use it to build soql query string dynamically using schema.field set class.

i.e we have field set named: CaseFieldSet. It has three fields added:  Status,Priority, and Subject. Those fields were added to CaseFieldSet in different time.

We have a requirement to get the datetime for each field added to the field set. It means we want to know what exact time of those three fields were added to CaseFieldSet.

I assume the soqy would be similar to :
select id, createddate from fieldset where name = 'CaseFieldSet'

If having no such hidden object, how can I get the date time?

Thanks,
David
Hi All,
We experienced a very weired issue last month. I am struggling to find the root cause.
We have a Visualforce page used by all users. This happened at mid-night EST roughly from 11:30PM to 1:00AM.
All users got an error message saying:
 
An administrator has changed the definition of page or component /apex/takecall. Refresh your page and try again
Previous version = 30. Current version = 29.”
 
This type of error message usually means a changed has been made to the page while it is in use.
We confirmed nobody changed the code during that time. Actually, the last code change was two months ago.

If you take a look of the red highlighted text, it says current version is lower than previous version. The version is reverted.

Have you every seen such problem before? Salesforce support says it is our vf page issue.

Thanks,
David
 
Hi all,
I came across a problem that SOSL returns less rows than expected. SOQL returns the right number of rows.
Basically, in below snippet, I tried to get all rows which string 205640 exists in vin_person__c field.
SOSL only returns 2 rows. But SOQL return 6 rows including 2 rows in SOSL result.

What could be the problem?
 
list<list<sobject>> slist =[FIND '*205640*'  IN all FIELDS RETURNING VIN__c (Id,Name,Program__c,VIN_Person__c,Person__c,Car__c where Program__r.Account__c='001o000000ODW6lAAH' AND Inactive__c=FALSE ) LIMIT 100];

system.debug(slist);

list<vin__c> svin = [select Id,Name,Program__c,VIN_Person__c,Person__c,Car__c from vin__c where Program__r.Account__c='001o000000ODW6lAAH' AND VIN_Person__c LIKE '%205640%' AND Inactive__c=FALSE LIMIT 100];
system.debug(svin);



Thanks,
David
 
Hi all,
I have a VF page displaying google map.
I want to archive two goals:
1. displaying case locations on the map.
2.when click marker on the map, the related case will be open.

I don't have any issue to display those locations on the map.The problem is when clicking any marker, it always opens the last case in both Console or non console application.
Can someone help me out?



Thanks,
David
 
for (var i = 0; i < locations.length; i++) 
{
    try
    {
        var icn = "/resource/Img/reddot.png";
       	
						    	
        var marker = new google.maps.Marker({
                title: locations[i].title,
                position: new google.maps.LatLng(locations[i].lat, locations[i].lng),
                icon: icn,
                url: locations[i].url,
                map: map
            });

        google.maps.event.addListener(marker, 'click', function () {
        if(isConsole)
            sforce.console.openPrimaryTab(null,marker.url,true,marker.casenumber,function(result){},marker.casenumber);
        else
            window.open( marker.url,'_blank');
        });
			
    }
    catch(err){}
}

 
Hi All,
I have a Javascript function to get case geolocation information and put on google map. I follow Salesforce Ajax Kit Dev Guide, but it keeps get "undefined" value when getting the query result. Specifically, in the following lines:

var cid = car.id;
var lat =car.Breakdown_Location__latitude__s;
var lng =car.Breakdown_Location__longitude__s;
alert(cid); //show undefined
alert(lat); //show undefined
alert(lng); //show undefined

I can see local variable "car" has value ""{"type":"Case","Id":"500P0000004ILDvIAO","Breakdown_Location__Latitude__s":"44.8561002","Breakdown_Location__Longitude__s":"-79.9970188"}".

What am I missing?

Thanks,
David
function loadMap() 
    {
    
        var latlng = new google.maps.LatLng(54.351179,-95.502741);
        var myOptions = {
        zoom: 5,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP};
        
        map = new google.maps.Map(document.getElementById("map_canvas"),  myOptions);   
        sforce.connection.sessionId = "{!$Api.Session_ID}";
        var result = sforce.connection.query("select id,Breakdown_Location__latitude__s,Breakdown_Location__longitude__s from case where createddate > 2016-01-10T00:00:00Z and Breakdown_Location__longitude__s <> null limit 3");
        
        //alert(result);
        
        var records = result.getArray("records");
       

        for (var i = 0;i<records.length;i++) 
        {
            //alert(records[i]);

            //debugger;
            
            var car = records[i];   
            //alert(car);
            //debugger;
            var cid = car.id;
            var lat =car.Breakdown_Location__latitude__s;
	        var lng =car.Breakdown_Location__longitude__s;
            //debugger;
			   
           alert(cid); //show undefined
	   alert(lat);   //show undefined
	   alert(lng);  //show undefined
            
            
            marker = new google.maps.Marker({  
            position: new google.maps.LatLng(lat,lng),  
                map: map});      
        }

​