how to display salesforce attachments in asp.net website to download - salesforce

we are creating asp.net website which uses salesfoce webservice api and pull all the information. We have a functionality within the site to display a contact "notes and attachments" which can be downloaded. I have been googling a lot about it, but no use.
Can any one guide me please.?
thanks,

You have to query the Attachment table, either directly:
SELECT Id, Name, Body, BodyLength, ContentType, CreatedBy.Name, CreatedDate, Description, Owner.Name, ParentId
FROM Attachment
LIMIT 10
Or indirectly with a subquery:
SELECT Id, Name, Email, (SELECT Name FROM Attachments ORDER BY CreatedDate DESC)
FROM Contact
LIMIT 10
The actual content of the file is stored in the Body column, base64-encoded. You'll have to decode it and (based on content type?) save as text / binary file, server to the user with the proper content header...
The inclusion of the Body column slows things down a bit - I'd recommend you skip it initially in the "see attachments related list" part of your ASP application and retrieve them (by Id for example) only when user actually wants it... I've noticed that you can get just 1 row returned (initially) with Body queried for so if you really want to do it all in one go - check out the documentation for queryMore() function and make sure your app has processed whole query locator ("cursor" if you're familiar with that word).
So, the above should work both in SOAP API and REST API as long as you can send queries (you didn't specify which one you use... "webservice api" sounds like you're limited to using few selected Apex classes exposed as webservice). Additionally REST API has special retrieve() command.

Related

How to fetch Notes related to specific Accounts in Salesforce?

How can I fetch Notes data related to a specific Account using SOQL query in Salesforce?
I tried with the below SOQL query but it gives me empty rows.
SELECT Id, Title, Body FROM Note WHERE ParentId = '<Account_id>'
I am attaching a screenshot for better understanding.
I want to query the Notes which are marked in red color in the above image.
PS: Am new to Salesforce
Uh, bit tricky for first task :)
Note is old object primarily used in old Salesforce UI, maybe you have heard of "classic" or "aloha". You are using new Lightning UI and the object you're looking for is ContentNote.
Old: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_erd_documents.htm
New: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_erd_contentnote.htm
To make matters bit messier ContentNotes are built on top of the solution for uploading Files, they're a special type of file. And that one is split into 2 tables - the header that can be linked to from many areas in the system (ContentDocument), wasting space on disk only once... and actual payload which can be versioned (ContentVersion)
Anyway: this should work
SELECT ContentDocument.Title, ContentDocument.LatestPublishedVersion.VersionData
FROM ContentDocumentLink
WHERE LinkedEntityId = '001...'
AND ContentDocument.FileType = 'SNOTE'
Another, simpler way would be to use a flatter, readonly view of all the "files" linked to the record (old school attachments, new files, stuff uploaded as Chatter posts, stuff cross-linked from SharePoint for example...). You'd have to experiment with CombinedAttachment
SELECT Name, (SELECT Title FROM CombinedAttachments)
FROM Account
WHERE Id= '001...'

How to download all attachments of all records of a custom object in Salesforce?

I am new to file handling in Salesforce. I want to grab all the files attached to all the records of a custom object. Can anyone help me with it?
Old-school SF used Attachment object and you could simply go SELECT Body, ContentType, Name FROM Attachment WHERE ParentId = '...'.
In Lightning there's high chance your attachments are called "Files" (the actual API name is ContentDocument / ContentVersion). Check if the attachment's ID starts with 068 or 069. They aren't linked directly to your record. Instead there's ContentDocumentLink table sitting in between, used to cross-share same file. (You upload it and waste database space once, then you can cross-link it in Chatter posts, groups, other records...)
The official ERD isn't great, try to click through it in Setup -> Schema Builder or this answer might help: https://salesforce.stackexchange.com/a/160285/799. There's a sample query which you might have to fine-tune a bit, for example to SELECT ContentDocument.LatestPublishedVersion.VersionData to get the actual payload.
Check out other questions around here about ContentVersion. For example https://stackoverflow.com/a/48668673/313628 (it's other way around, about upload but should give you good idea).
You can export all notes and attachments using open-source sfdx-hardis plugin command
First, define a files export
sfdx hardis:org:configure:files
When prompted for SOQL request, you can input SELECT Id,Name FROM YourCustomObjectName__c
Then, run the files export
sfdx hardis:org:files:export
More details in this article
Disclaimer: My company authors sfdx-hardis plugin

How to parse HTML table data using angularjs

There's a site called NPI registry lookup which will show the information about the doctor you're searching for. Here's the URL https://npiregistry.cms.hhs.gov/registry/search-results-table?number=1023070703. This will list the information in table form for the doctor whose NPI number is 1023070703, for example. What I want to do is build an angular site that will allow users to enter the NPI number, which I'd get the data using $http.get(url). I received the data but it's HTML instead of just the values. How can I parse the HTML table so that I can only pick the data I need? Or is there another better way of fetching the data?
It may sound silly to create another site when there already exists one, but it's for internal purpose only which we need to save a list of doctors that are not yet in our list.
Please read the sites API which is on top right.
For interactive demo:
https://npiregistry.cms.hhs.gov/api/demo
1023070703 becoming something like:
https://npiregistry.cms.hhs.gov/api/?number=1023070703

Get merged account IDs

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

Generate invoice with Salesforce

I am new in Salesforce and I would like to know how to generate an invoice.
I think to different solutions and I don't know if there are possible, time-consuming, difficult...
A service has different steps.
The service must be invoiced when the step is "completed". a new record have to be added in the table "Invoice" and a link to the invoice document (PDF or Word format)
For the moment, I think to use the section "Note and Attachment Fields". but perhaps that the object "document" is better...
Invoice Creation: I can use the standard button to create a new record but I would like to create it automatically when the status of the file is changed to "completed" for example.
1.I have read the workflow description but I am not sure that it could be use to create automaticaly a specific record in a table.
2.I have also thought to use a button that could fill in the fields and create the record. I fand information to update field with onclick javascript code. But I don't know how to add a record.
Electronic invoice: how can I generate the invoice in PDF or Word format ? and make it available from the record "Invoice n°10" ?
For exemple, the record "Invoice_10" would have an attachment field that contain a link to the document "Inv_010.pdf". The user could open the document from the link.
You might also consider using the standard quote object for your purpose. It comes with a neat PDF generator that is easy to set up. If you set it up right you can (ab)use the quote functionality for creating invoices related to an opportunity. Customizing the New Quote button would allow you to enable this functionality only after the opportunity is closed (using JavaScript). Regarding MS Word generation I recommend DocMocracy: http://www.cloudgizmos.com/salesforce-sfdc-word-excel-document-generator since it is really cheap and you can create read-only word documents.
To answer your first question, you want to write an Apex trigger — run it on your service object (sounds like Opportunity) after insert, and after update, and if the status has been changed to completed then generate your invoice record.
As for generating a PDF invoice you can do this by creating a Visualforce Page and using the renderAs="pdf" attribute in the <apex:page> tag. Storing it against a record will be a bit more tricky, though I suggest you look at examples of how you can attach a Visualforce PDF to an email, you can likely use the same blob object (which stores the content) as a document in Salesforce.
There is already an application: Invoices for Salesforce listed on the Appexchange that automatically creates invoices - records and PDF, straight out of your sales data. The application includes an invoice template editor that gives you complete freedom to design your invoice documents. In addition, the application can automatically deliver the invoices via email, or can group the invoices in files for batch printing in case you need to send them by post or fax.
Check it out: http://www.invoicesforsalesforce.com

Resources