Get merged account IDs - salesforce

I am about to do the process of mass de-duping in Salesforce. However, our team uses excel spread sheets where they have Account IDs. When I will merge accounts, then some of them won't exist in Salesforce anymore. I would like to get merged Account IDs to use vlookup in Excel, to replace invalid values.
I tried to pull this data out via Account History report... I wasn't able to do this. Also I went to Recycle Bin, where deleted Accounts are stored. However, there I can find only Account names instead of Account IDs
Does anyone know how can I get the merged Account IDs?

You could use some screenscraping thingie to inspect the HTML of Recycle Bin page. The Id of deleted record is hidden in the checkbox you click.
<input id="ids0" name="ids" onclick="..."
title="Select Sample Account" type="checkbox" value="001xxxxxxxxxxxx">
But that's a very crappy solution.
Better would be to use an API tool (I usually recommend Real Force Explorer but if it's an one-time action the web-based workbench.developerforce.com might do too).
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_merge.htm
To find all records that have been merged since a given point in time,
you can use queryAll() with a SELECT statement similar to the
following:
SELECT Id FROM Contact WHERE isDeleted=true and masterRecordId != null
AND SystemModstamp > 2006-01-01T23:01:01+01:00
In your case something like this should give you both old and new Id - perfect for mapping in Excel!
SELECT Id, Name, MasterRecordId, MasterRecord.Name
FROM Account
WHERE isDeleted=true and MasterRecordId != null

Use a soql query tool or apex with soql query. The old accounts should be there and marked with IsDeleted true
I work on Mac and use SOQLExplorer
You can also use th SF Workbench. Log onto SF and under your name look for it

Related

how do I use soql to get a the value of a calculated field in the activity table for simple_salesforce

I know this works on the workbench:
SELECT Id,bizible2__BizibleId__c FROM Task
where bizible2__BizibleIid__c is on the activity table.
This works too:
SELECT Id,bizible2__BizibleId__c,owner_manager__c FROM Task
but it doesn't work in simple_salesforce. No clue why. So I tried to simulate it because owner_manager__c is a calculated field that equals:
Owner:User.Manager.FirstName &" " & Owner:User.Manager.LastName
the owner is a standard relationship for the task table and presumably the activity table. My attempt:
SELECT Id,bizible2__BizibleId__c,Owner.name FROM Task
works, but
SELECT Id,bizible2__BizibleId__c,Owner.Manager.FirstName FROM Task
Didn't work. Manager is a hierarchy thingy. I thought it could be because the owner relationship is user,calendar,something else and not just user, so I tried
SELECT Id,bizible2__BizibleId__c,LastModifiedBy.Manager.FirstName FROM Task
and that didn't work.
I figured it out. You have to go to the directory simple_salesforce is in: site-packages\simple_salesforce\api.py. then in the line DEFAULT_API_VERSION = '42.0', change 42.0 to 51.0. That, of course, is a terrible hack, so I asked this question:
How do I change the api version of Simple Saleforce
But so far there is no answer other than what I did.
From what I remember "simple salesforce" uses REST and this API respects field level security. Are you sure you have access to the field? Just because you're sysadmin and bypass stuff in UI doesn't mean your Profile is all right. Workbench might be using SOAP API which is bit old and doesn't enforce the fields (yet).
What does this do for you?
SELECT Id,
TYPEOF Owner
WHEN User THEN Username, Manager.Name
END
FROM Task
On mutant fields sometimes you need to use polymorphic SOQL to get the fields you want. But still, the formula should work OK.

How can I traverse through multiple related objects based on ID and return some related field?

I'm a little stuck.
I am trying to generate a report that determines whether anyone has made a manual change to certain fields within our order framework. I have figured out the proper fields and structures to audit, and even how to make the report, but I used a combination of extracts from the Dataloader and Excel xlookups to make it. Now, I'm being asked to find a way to automate the generation of the report, and I suspect that means I need to write a SOQL query to figure it out. I'm having trouble traversing multiple relationships based on these ID fields. Essentially, what I'm trying to do is make multiple "left joins" based on the 18 digit Salesforce IDs and extract some related piece of information from those other objects.
For example, if I'm starting with order_product_history (with a field OrderProductID to identify the order product) and I want to bring in "Product Name", I have to first match OrderProductID with the ID field in my order_product "table", then I have to match the Product2ID field in my order_product "table" with the ID in my product "table", then I have to get the matching Product Name as a column in my report:
Matching/Traversal Process
Desired Result
That's one example for one field. I also have to bring in things like User Name from the users "table", and order number from the orders table, but once I get the general idea, I think I'll be OK. I also want to filter the results to only include my Fee__c and UnitPrice fields, ignore the automated users and set a date filter--not sure if I have to do that using a WHERE clause just in my main query, or if I have to filter the subqueries as well.
I am not a programmer and I have no formal Salesforce training; I am just an analyst who is technically inclined and sort of fell into the role of Salesforce Admin. I am familiar with programming concepts and have been writing things using the flow application and have even dipped my toes into some Apex stuff, but it can be a bit of a struggle. I am not asking you to do my job for me and I am willing to work at the problem and learn; any help is appreciated. Sorry about the links; SO won't let me embed images yet.
There's high chance you don't have to write any code for it. I'll give you some tips, experiment a bit and edit the question or post new one?
This diagram might help: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_products.htm
Developer way
It's all about writing the right query. You can play with it in Developer Console or Workbench for example. Read up about relationship queries in SF.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_understanding.htm
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_hist.htm
I don't have org with orders enabled but this should be a good start:
SELECT CreatedById, Created.Name,
Parent.Name, Parent.Product2.Name, Parent.Order.Name,
Field, OldValue, NewValue, CreatedDate
FROM OrderItemHistory
If it throws errors about "Parent" see if "OrderItem" will work. Once you have it - WHERE Field IN ('UnitPrice', 'Fee__c') AND CreatedDate = LAST_WEEK might be good next step. (dates can be filtered by date but there are few "constants" that are more human-readable too)
You could even export this with Data Loader, you just have to start the wizard on Order Product history table. But you can ignore the whole query creator and paste a query you've created.
Admin way
Have you ever created a report in Salesforce? There are self-paced trainings (for Lightning and Classic UI) and tons of YouTube videos. Get a feel of making few reports.
What you want might be doable with built-in report type (see if there's new report -> order product history). If nothing exciting - as admin you can make new report type in setup. For example Orders -> Order Products -> Order Product History. Screenshots from here might help.
Just wanted to update this for anyone looking for a solution in the future.
Turns out you can traverse these as a parent-child relationship in the SOQL query. Here's the query I ended up using:
SELECT CreatedBy.Name, FORMAT(CreatedDate), OrderItem.Order.OrderNumber, OrderItem.Product2.Name, OrderItem.Product2.ProductCode, Field, OldValue, NewValue
FROM OrderItemHistory
WHERE (Field = 'Fee__c' OR UnitPrice) AND (CreatedBy.Name != 'Integration User') AND (Created Date >= 2020-11-24T00:00:00.000Z) ORDER BY CreatedDate DESC

Set up relation on two existing Salesforce objects

I have a custom object in Salesforce which I need to setup a Master Detail relationship from Accounts. Accounts being the Master and CompHist being the Detail. The problem I am running into is that I need to set the relation to work off of custom fields within the objects. Example:
1.) Accounts has a custom field called CustomerId.
2.) CompHist also has custom field called CustomerId.
3.) I need to be able to have this linked together by CustomerId field for report generation.
About 2,000 records are inserted into CompHist around the 8th of each month. This is done from a .NET application that kicks off at the scheduled time, collects info from our databases and then uploads that data to salesforce via the SOAP API.
Maybe I'm misunderstanding how Salesforce relationships work as I am fairly new (couple months) to salesforce development.
Thanks,
Randy
There is a way to get this to work without triggers that will link the records or pre-querying the SF to learn Account Ids in .NET before you'll push the CompHistories.
Setup
On Account: set the "External ID" checkbox on your CustomerId field. I'd recommend setting "Unique" too.
On CompHist: you'll need to make decision whether it's acceptable to move them around or when the relation to Account is set - it'll stay like that forever. When you've made that decision tick / untick the "reparentable master-detail" in the definition of your lookup / m-d to Account.
And if you have some Id on these details, something like "line item number" - consider making an Ext. Id. for them too. Might save your bacon some time in future when end user questions the report or you'll have to make some kind of "flush" and push all lines from .NET (will help you figure out what's to insert, what's to update).
At this point it's useful to think how are you going to fill the missing data (all the nulls in the Ext. Id) field.
Actual establishing of the relationship
If you have the external ids set it's pretty easy to tell salesforce to figure out the linking for you. The operation is called upsert (mix between update and insert) and can be used in 2 flavours.
"Basic" upsert is for create/update solving; means "dear Salesforce, please save this CompHist record with MyId=1234. I don't know what's the Id in your database and frankly I don't care, go figure this out will ya?"
If there was no such record - 1 will be created.
If there was exactly 1 match - it will be updated.
If there were more than 1 found - SF won't know which one to update and throw error back at you (that's why marking as "unique" is a good idea. There's a chance you'll spot errors sooner).
"Advanced" upsert is for maintaining foreign keys, establishing lookups. "Dear SF, please hook this CompHist up to Account which is marked as "ABZ123" in my DB. Did I mention I don't care about your Ids and I can't be bothered to query your database first prior to me uploading my stuff?"
Again - exact match - works as expected.
0 or 2 Accounts with same ext. id value = error.
Code plz
I'd recommend you to play with Data Loader or similar tool first to get a grasp. of what exactly happens, how to map fields and how to not be confused (these 2 flavours of upsert can be used at same time). Once you'll manage to push the changes the way you want you can modify your integration a bit.
SOAP API upsert: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_upsert.htm (C# example at the bottom)
REST API: http://www.salesforce.com/us/developer/docs/api_rest/Content/dome_upsert.htm
If you'd prefer an Salesforce Apex example: Can I insert deserialized JSON SObjects from another Salesforce org into my org?

Matching DB records to Active Directory entries?

I have been tasked with coming up with a solution where I am not sure if there is a solid answer:
How can I match username records from an application's database to users in our Active Directory?
I have two applications this needs to be done for - 1st application I only have firstname and lastname information. Second application i have the application's username, which is similar to activeD's but not a definate match. I also have firstname lastname info.
Now, simply put I can just write a script that matches all the records in ActiveD that match the firstname lastname in the application DB, but that is fraught with errors.
Having no unique identifier to begin with might make this an impossible task, but before I start to task someone else with manually comparing the data after running the script, I thought I would ask the delightful StackOverflow crew to chew on it. There are always methods I don't think of, after all.
So any brilliant ideas out there to accomplish this task?
Thanks guys
Once you get them matched up automatically and the exceptions by hand, make a custom attribute in Active directory where you can store the information to keep them matched up in the future.
You could store the Active Directory object GUID against the database record.
Well, the one thing that will be indeed unique in AD is the sAMAccountName for each user. If you find a way to associate your users in your two databases with a SAM Account Name, you should have no big trouble anymore to do an automatic sync check with AD.
That property is already available in AD, you don't need to add any additional artificial IDs, and it's much easier to read than a GUID.
Marc

Retrieving deleted records from Apex data loader?

Does anyone have any idea how to retrieve deleted records data from Apex data loader or otherwise from Salesforce except from the Web service?
Check the documentation: https://na7.salesforce.com/help/doc/en/salesforce_data_loader.pdf
If using the GUI version v20 or above, you'll have the Export All button.
From the Command Line version, the process-config.xml file should have the process.operation attribute value set equal to "extract_all" (the documentation states "Extract All" but that doesn't work).
Using either of these above options will extract soft deleted records, and will allow you to filter on IsDeleted = true or false. (You can include this filter regardless, but without using the above options, IsDeleted=true will always return zero records).
Hope that helps.
P.S. In Apex, it's slightly different. Your SOQL query will be [Select Id from Account where IsDeleted=false all rows] The 'all rows' appendage is the Apex equivalent of 'extract all'.
In Dataloader, use the EXPORT ALL button, not the EXPORT button
This gives you access to deleted & archived records.
You can't. The only way to get deleted records through the API is to use queryAll, and DataLoader doesn't use queryAll ever.
(Sorry for the resurrection here.)
Roll them back with a few lines of Apex code in the System Log. For instance:
Account[] a = [select id from Account where isDeleted=true ALL ROWS];
undelete a;
system.debug(a);
This should work as long as you didn't use emptyRecycleBin() (which will still return query results, but won't allow undelete as the records would now be marked for physical deletion). Take a few of the ids from the USER_DEBUG results for a to confirm that it worked.
Try extract, extract_all, hard_delete.
I hope it's not to late.
There are three ways to do it.
Recycle bin. In recycle bin change the option to all recycle bin. It is like soft delete we can get the record. If you didn't get your record from recycle bin
Workbench. In workbench select soql query and your required object and create a query like this example.
SELECT Id,Name,AccountId,Isdeleted,CreatedDate,StageName
FROM Opportunity where isdeleted =true
in this section we didn't get the record we know the information of the opportunity record.
Dataloader. It also works like workbench and you can retrive the information of the record. Select exportall option and select the required fields and put a filter like is deleted is true.

Resources