• talgiladi
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies

Hi,

Is there a way to pass the id of a view (contacts view for example) and get the filtered results?

I know the Id of one of the contacts view (like 00BA0000002ly8SaAQ) and want to pass it to a controller method or custom web service method and get in return the contacts in this view.

 

All I could find is how to pass the id of list view control and let the controller grab the selected value...

 

Thanks!

I am trying to use a post request to start a batch upsert.  I have managed to get this to work using Curl, but I always get a 400 Bad Response when using the native HttpWebRequest method

 

I am passing the postData as UTF-8 encoded, and include the following for the contentType and headers

 

Content-Type: application/xml; charset=UTF-8
X-SFDC-Session: 00D700000008rXl!AQMAQA1rjn2jPYeSQuRoChquzvncucoqSNHVSUydo1eM0eSV3PKmSYE0QoD8gkSxBb2tuaT3wd8Dd1fr_YahMGhtxYO7m7u2 

 

Below is the code; when I look at the request that works with Curl and my request in tcpTrace, they look identical.

 

public static string PostData(string url, byte[] postData, string contentType, KeyValuePair<string, string>[] headers, ITaskProgress progress)

{

int length = postData.Length;

Uri uri = new Uri(url);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

request.Method = "POST";request.ServicePoint.Expect100Continue =

false;

request.ContentType = contentType;

request.ContentLength = length;

request.ReadWriteTimeout = Timeout;

request.Timeout = Timeout;

request.AllowWriteStreamBuffering = false;

request.Accept = "application/xml";request.UserAgent =

"Salesforce Web Service Connector"; if (headers != null)

{

foreach (KeyValuePair<string, string> header in headers)

request.Headers.Add(header.Key, header.Value);

}

if (progress != null)

progress.CurrentTaskProgress = 0;

using (Stream writeStream = request.GetRequestStream())

{

int bytesSent = 0; while (bytesSent < length)

{

int bytesToSend = Math.Min(ChunkSize, length - bytesSent);

writeStream.Write(postData, bytesSent, bytesToSend);

bytesSent += bytesToSend;

if (progress != null)progress.CurrentTaskProgress = (int)((long)bytesSent * 100) / length;

}

}

if (progress != null)

progress.CurrentTaskProgress = 100;

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

...

 

Here is the actual post sent

 

POST /services/async/18.0/job HTTP/1.1
Content-Type: application/xml; charset=UTF-8
Accept: application/xml
User-Agent: Salesforce Web Service Connector
X-SFDC-Session: 00D700000008rXl!AQMAQA1rjn2jPYeSQuRoChquzvncucoqSNHVSUydo1eM0eSV3PKmSYE0QoD8gkSxBb2tuaT3wd8Dd1fr_YahMGhtxYO7m7u2
Host: localhost:8080
Content-Length: 626
Connection: Keep-Alive

<?xml version="1.0" encoding="utf-8"?><jobInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.force.com/2009/06/asyncapi/dataload">  <operation>upsert</operation>  <object>Leads</object>  <contentType>CSV</contentType>  <numberBatchesQueued>0</numberBatchesQueued>  <numberBatchesInProgress>0</numberBatchesInProgress>  <numberBatchesCompleted>0</numberBatchesCompleted>  <numberBatchesFailed>0</numberBatchesFailed>  <numberBatchesTotal>0</numberBatchesTotal>  <numberRecordsProcessed>0</numberRecordsProcessed>  <numberRetries>0</numberRetries></jobInfo>

 

Very very strange

Hi -

 

I have been trying for over a week now to get oauth working between salesforce and my application.  I have experience getting oauth to work with Twitter and Youtube, so I figured this would be easy... 

 

BTW, I have set up Remote Access in my salesforce setup.  

 

I'm having problems on the very first step of the oauth process. This is what I am sending to get the RequestToken (I added the returns for clarity after the &'s)

 

https://login.salesforce.com/_nc_external/system/security/oauth/RequestTokenHandler?oauth_consumer_key=<My key>&
oauth_nonce=8114382&
oauth_signature_method=HMAC-SHA1&
oauth_timestamp=1266716665&
oauth_version=1.0&
oauth_callback=https%3A%2F%2Fwww.catchthecloud.com%2FSalesforceOAuth.aspx&
oauth_signature=fH85OWR29G3IXSp1sc3uf4WMD7w%3D

 

This seems to be correct as per: https://ap1.salesforce.com/help/doc/user_ed.jsp?loc=help&section=help&hash=access_data&target=remoteaccess_authenticate.htm

 

However, I'm getting a 400 - bad request error when sending it.  I'm also having problems sending it via POST, or if I put it in an Authorization header...

 

The C# code that I am using to generate this string is as follows:

 

   

Uri uri = new Uri("https://login.salesforce.com/");
string nonce = this.GenerateNonce();
string timeStamp = this.GenerateTimeStamp();

//Generate Signature
string sig = this.GenerateSignature(uri,
this.ConsumerKey,
this.ConsumerSecret,
this.Token,
this.TokenSecret,
method.ToString(),
timeStamp,
nonce,
out outUrl,
out querystring);

querystring += "&" + this.UrlEncode("oauth_callback") + "=" + this.UrlEncode("https://www.catchthecloud.com/SalesforceOAuth.aspx");
querystring += "&" + this.UrlEncode("oauth_signature") + "=" + this.UrlEncode(sig);

NameValueCollection oauthtokendata = null;
HttpWebRequest request = System.Net.WebRequest.Create(url+"?"+querystring) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
using (TextReader reader = new StreamReader(response.GetResponseStream()))
{
oauthtokendata = HttpUtility.ParseQueryString(reader.ReadToEnd());
}
}

 

Towards the bottom of this code, I do a call to request.GetResponse(), and that's where it dies.  If I take the string that's been created and stick it in the address bar of a browser, I get the following response:

 

 1702Failed: Missing Consumer Key Parameter

 

 

On the first line of this code, --
Uri uri = new Uri("https://login.salesforce.com/");

 

 

 I have used several variations of Uri's in attempts to make this work, including https://login.salesforce.com/_nc_external/system/security/oauth/RequestTokenHandler, but nothing seems to work.

 

 

 

 

 

 

So -- hopefully someone can give me a tip to get this thing to work... I feel like I'm pretty close!

 

 

 

Thanks,

Beth 

 

The StandardSetController APEX class has getFilterId and setFilterId methods. My question is what are these filters and where are they found? How are they used? There is no filter object or any other reference in APEX or VF that I can find.

 

Mauricio Parra

  • September 10, 2009
  • Like
  • 0
Hi,

I'm using this code to set View Filters but it is not working:
Code:
List<Contact> ct = [Select AccountId, Id, Title, Phone, OwnerId, Name, MailingCity, LastName, FirstName, Email, Account.Name From Contact Order By LastName, FirstName];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(ct);
ssc.setFilterID('00B80000005xfRxEAI');
contacts=(List<Contact>)ssc.getRecords();


but contacts is still having all CONTACTS list records.

Can anyone provide me with some sample code with Custom list View Options working? Or shed some light on what IS Needed to be Done to make it working.

Thanks.





Message Edited by vchaddha on 11-28-2008 08:51 AM
  • November 28, 2008
  • Like
  • 0

Hello,

I faced issue working with views functionality. By "views" i mean : if you Click Leads tab for instance
you will see dropdown with existing views and ability edit/create new views.

So my task is very similar.I need develop custom "view" functionality.
-I need to receive existing views and add them to dropdown.
-On changing some view from dropdown i need select data based on particular filter criteria.

Please take a look at my testing code . Issues are marked in red color.
So there are two issues in code below:
1) setFilterId does not filter records :   ssc.setFilterID( this.m_SelectedView);
2) can't call size() method for getListViewOptions (exception raised) : List<SelectOption> result = ssc.getListViewOptions();

 


Code:
// Controller

public class TestViewPageController

{

private string m_SelectedView = '';



// Gets the selected view id.

public string getSelectedView()

{

return this.m_SelectedView;

}



// Sets the selected view id.

public void setSelectedView( string value )

{

this.m_SelectedView = value;

}



// Gets a list of users’ views. In order to display in drop down.

public List<SelectOption> getViewsList()

{

List<User> users = [SELECT id FROM User];



ApexPages.StandardSetController ssc = new ApexPages.StandardSetController( users );



List<SelectOption> result = ssc.getListViewOptions();



if ( null == this.m_SelectedView || '' == this.m_SelectedView)

{

/* Set the default selected view value. Code commented because raise error. Error always occurs when we

try access result collection. In that particular case exception will be trown trying to access result.size()



if result.size() > 0 )

{

this.m_SelectedView = result.get(0).getValue();

}

*/

}



return ssc.getListViewOptions();

}



// Gets a list of the users in the view.

public List<User> getUsers()

{

// Returns a empty list of users if view not selected.

if ( null == this.m_SelectedView || '' == this.m_SelectedView)

{

return new List<User>();

}



List<User> users = [SELECT id, name, email FROM User]; // SOQL



ApexPages.StandardSetController ssc = new ApexPages.StandardSetController( users );



// Sets a filter id value.

ssc.setFilterID( this.m_SelectedView);



// Should return filtered records but returns a list of records defined by SOQL. (All users)

return (List<User>)ssc.getRecords();

}



}



// Layout:





<apex:page controller="TestViewPageController" >



<apex:form >



<apex:pageBlock title="Title">



<apex:pageBlockButtons location="top">



<apex:selectList value="{!SelectedView}" multiselect="false" size="1">



<apex:selectOptions value="{!ViewsList}" />



<apex:actionSupport event="onchange" rerender="users" />



</apex:selectList>



</apex:pageBlockButtons>



<apex:outputPanel id="users">



<apex:pageBlockTable value="{!Users}" var="entry" width="100%">



<apex:column headertitle="Id" value="{!entry.Id}" />



<apex:column headertitle="Name" value="{!entry.Name}" />



<apex:column headertitle="Email" value="{!entry.Email}" />



</apex:pageBlockTable>



</apex:outputPanel>



</apex:pageBlock>



</apex:form>



</apex:page>


 

 

 Thanks in advance

 

 



Message Edited by Vasily on 10-10-2008 06:48 AM

Message Edited by Vasily on 10-10-2008 06:49 AM

Message Edited by Vasily on 10-13-2008 02:08 AM

Message Edited by Vasily on 10-13-2008 02:12 AM
  • October 10, 2008
  • Like
  • 0