I have attempted using a somewhat complex XPath syntax in the EventLogQuery to no avail. I have looked through all Microsoft docs I found by myself and through other posts here. I have primarily looked through these two posts:
EventLogQuery: How to form query string?
EventLogQuery time format expected?
Here are the queries, first one grabs all logon events with the LogonType attribute within a data node. This is redundant as all logon events will have this node, so I was going to further narrow the query to only type 11 for testing:
// This works fine
*[System/EventID=4624 and EventData/Data[#Name='LogonType']]
// This is considered invalid
*[System/EventID=4624 and EventData/Data[#Name='LogonType' and text()='11']]
What is wrong with this query and how could I fix it? I would prefer not to have to retrieve every single logon event and then filter again (i.e. loop through returns and only act on those with an 11) as this seems inefficient. I will be querying against domain controllers with millions of events currently on them.
For those still searching, I have likely found what the issue is. Microsoft did not fully implement XPath 1.0 for EventLogQuery. They half implemented it and twisted it into what they saw "useful" for querying events. text() is not a useable function. In order to achieve what I was trying, you have to use extremely long, ugly queries such as the following:
*[System/EventID=4624 and (EventData/Data[#Name='LogonType']='2' or EventData/Data[#Name='LogonType']='3' or EventData/Data[#Name='LogonType']='11')]
We have our system from where we want to push the records (e.g. Contact, Account, Opportunity, etc.) to SalesForce.
To achieve this, we have used ForceToolKit for .Net. We are able to insert\update the records successfully using the ForceToolKit functions.
Example:
dynamic contact = new ExpandoObject();
contact.FirstName = "FirstName";
contact.LastName = "Last";
contact.Email = "test#test.com";
contact.MobilePhone = "1234567890";
var successResponse = await forceClient.CreateAsync("Contact", contactList);
The Issue we are facing is as mentioned below.
In our source system, we have few custom fields which are not standard field in SalesForce and it can be different for different users.
So, first we have to map the custom fields between our source system and the SalesForce.
We want to fetch all the fields of SalesForce object in order to map the fields.
We are unable to find any function in ForceToolkitForNet.
As described here, we have tried QueryById function by using the dynamic return type, but it is throwing an exception.
var contactFields = await forceClient.QueryByIdAsync<dynamic>("Contact", successResponse.Id);
Exception: "SELECT FROM Contact where Id = '{contactId}' Incorrect syntax near FROM".
What are the ways to get the fields of any object of SalesForce.
Can anyone help us on getting the fields of an object using SalesForceToolkit or SalesForceApi?
SOQL doesn't have a SELECT * FROM Account concept, you need to learn the fields beforehand. You have few options here.
You can use "describe" calls. I've recently answered similar question but it was about REST API: https://stackoverflow.com/a/48436870/313628, I think your solution is SOAP-based.
If you'd be doing this by hand...
Start here: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_list_describe.htm
List of all objects visible to your user: describeGlobal()
Get details (incl field names) for one object: describeSobject() or more: describeSobjects()
As you're using the toolkit - there's a chance these methods already are in there somewhere. Experiment a bit. Between the C# examples under the links I gave you and the library you should be able to figure something out.
I mean I'm naive but just searching the repo for "describe" looks promising: https://github.com/developerforce/Force.com-Toolkit-for-NET/search?utf8=%E2%9C%93&q=describe&type=, maybe this example
There's also a way to not learn this info at runtime but consume a WSDL file generated out of Salesforce with all fields & generate C# code out of it. The downside is that you'd need to regenerate it every time you want to support new object/field in your app. Read about "Enterprise WSDL" to get started.
Last but not least - there are more or less friendly tools that dump the Salesforce metadata. i'm a fan of https://www.datasert.com/products/realforce/ but just have a look around. Hell, even exporting some records with DataLoader will give you all field names if that's all you need.
I have a .NET Web Api that has a search method to a sql server. Users can search in a textbox and on every new entered character the searchmethod will be called and query the database and return the results from the table.
For instance: SELECT * FROM Table WHERE Table.Name like '%UserSearchText%'
My question to this is:
Do you know any good practices for this scenario, in terms of: should I try to cache the results(Don't have to get the updated results immediately instead it could be 10 seconds old for instance) or should I just query the db everytime even though in would result in a lot of queries being made?
Anyone else implemented this before? It seems like a common task therefore I figured there could be a few smart ways to do it. If you have any input or know about any blog posts or any help whatsoever, I would highly appreciate that. Thanks!
EDIT
Query should be SELECT * FROM Table WHERE Table.Name like 'UserSearchText%'
I want to fetch one day older updated record from HubSpot Contacts,
and I have used bellow link from C# for fetch record but its return with 30 days old record from provided timeOffset.
serviceUrl1 = " https://api.hubapi.com/contacts/v1/lists/recently_updated/contacts/recent?hapikey=demo&property=email&property=lifecyclestage&count=100&timeOffset=1446767961000"
The Hubspot API doesn't directly support specifying a time-range for updates: it returns the latest results first, and the timeOffset and vidOffset parameters are used for paging through the results back in time (max. 100 per call).
If I've understood correctly that you want to retrieve contacts that have been updated in the last day, you should do the following:
Call /contacts/v1/lists/recently_updated/contacts/recent?hapikey=demo&count=100 to retrieve the most recent results.
Perform the following test on the response:
Is "has-more": true ?
AND Does the last result have a properties.lastmodifieddate.value which is less than one day ago ?
If so, take the timeOffset and vidOffset values and add them to the URL, which will return the next page of (older) results. Repeat the test above, adding the results from each successive call to one big list.
When the test is false your work is done: be sure to only add results that are less than a day old to your list of results (as the call will also return older ones if there are any!).
There is a third party solution that can help you here with filtering contacts by “Last Modified Date” field on export. It is Import2 Wizard whereafter you set it up for the first time you also have the option of scheduling the export using the automation feature if you wish.
Disclaimer: I am with the Import2 team
I am working in C#, and am trying to use DirectorySearch to query the groups of an extremely large Microsoft ActiveDirectory LDAP server.
So, in my application, I'm going to have a paged list of groups, with searching capability. Naturally, I don't want to hammer my LDAP server with passing me the entire result set for these queries every time I hit "Next Page".
Is there a way, using DirectorySearch, to retrieve ONLY a single arbitrary page's results, rather than returning the entire result-set in one method call?
Similar questions:
DirectorySearch.PageSize = 2 doesn't work
c# Active Directory Services findAll() returns only 1000 entries
Many questions like these exist, where someone asks about paging (meaning from LDAP server to app server), and gets responses involving PageSize and SizeLimit. However, those properties only affect paging between the C# server and the LDAP server, and in the end, the only relevant methods that DirectorySearch has are FindOne() and FindAll().
What I'm looking for is basically "FindPaged(pageSize, pageNumber)" (the pageNumber being the really important bit. I don't just want the first 1000 results, I want (for example) the 100'th set of 1000 results. The app can't wait for 100,000 records to be passed from the LDAP server to the app server, even if they are broken up into 1,000-record chunks.
I understand that DirectoryServices.Protocols has SearchRequest, which (I think?) allows you to use a "PageResultRequestControl", which looks like it has what I'm looking for (although it looks like the paging information comes in "cookies", which I'm not sure how I'd be supposed to retrieve). But if there's a way to do this without rewriting the entire thing to use Protocols instead, I'd rather not have to do so.
I just can't imagine there's no way to do this... Even SQL has Row_Number.
UPDATE:
The PageResultRequestControl does not help - It's forward-only and sequential (You must call and get the first N results before you can get the "cookie" token necessary to make a call to get result N+1).
However, the cookie does appear to have some sort of reproducible ordering... On a result set I was working on, I iterated one by one through the results, and each time the cookie came out thusly:
1: {8, 0, 0, 0}
2: {11, 0, 0, 0}
3: {12, 0, 0, 0}
4: {16, 0, 0, 0}
When I iterated through two by two, I got the same numbers (11, 16).
This makes me think that if I could figure out the code of how those numbers are generated, I could create a cookie ad-hoc, which would give me exactly the paging I'm looking for.
The PageResultRequestControl is indeed the way to do this, it's part of the LDAP protocol. You'll just have to figure out what that implies for your code, sorry. There should be a way to use it from where you are, but, having said that, I'm working in Java and I've just had to write a dozen or so request controls and extended-operation classes for use with JNDI so you might be out of luck ... or you might have to do like I did. Warning, ASN.1 parsing follows not that far behind :-|
Sadly, it appears there may not be a way to do this given current C# libraries.
All of the standard C#4.0 LDAP libraries return Top-N results (As in, FindAll(), which returns every result, FindOne(), which returns the first result, or SearchResult with PageResultRequestControl, which returns results N through N+M but requires you to retrieve results 1 through N-1 before you'll have a cookie token that you can pass with the request in order to get the next set.
I haven't been able to find any third-party LDAP libraries that allow this, either.
Unless a better solution is found, my path forward will be to modify the interface to instead display the top X results, with no client paging capabilities (obviously still using server-side paging as appropriate).
I may pursue a forward-only paging system at a later date, by passing the updated cookie to the client with the response, and passing it back with a click of a "More Results" type of button.
It might be worth pursuing at a later date, whether or not these cookies can be hand-crafted.
UPDATE:
I spoke with Microsoft Support and confirmed this - There is no way to do dynamic paging with LDAP servers. This is a limitation of LDAP servers themselves.
You can use Protocols and the Paging control (if your LDAP server supports it) to step forward at will, but there is no cross-server (or even cross-version) standard for the cookie, so you can't reasonably craft your own, and there's no guarantee that the cookie can be reused for repeated queries.
A full solution involves using Protocols (with Paging as above) to pull your pageable result set into SQL, whether into a temp table or a permanent storage table, and allow your user to page and sort through THAT result set in the traditional manner. Bear in mind your results won't be precisely up to date, but with some smart cache updating you can minimize that risk.
Maybe you want to iterate through your "pages" using the range-attribute accordingly:
----copy & paste----
This sample retrieves entries 0-500, inclusively.
DirectoryEntry group = new DirectoryEntry("LDAP://CN=Sales,DC=Fabrikam,DC=COM");
DirectorySearcher groupMember = new DirectorySearcher
(group,"(objectClass=*)",new string[]{"member;Range=0-500"},SearchScope.Base);
SearchResult result = groupMember.FindOne();
// Each entry contains a property name and the path (ADsPath).
// The following code returns the property name from the PropertyCollection.
String propName=String.Empty;
foreach(string s in result.Properties.PropertyNames)
{
if ( s.ToLower() != "adspath")
{
propName = s;
break;
}
}
foreach(string member in result.Properties[propName])
{
Console.WriteLine(member);
}
----copy & paste----
for more Information see:
Enumerating Members in a Large Group
https://msdn.microsoft.com/en-us/library/ms180907.aspx
Range Retrieval of Attribute Values
https://msdn.microsoft.com/en-us/library/cc223242.aspx
Searching Using Range Retrieval
https://msdn.microsoft.com/en-us/library/aa367017.aspx