Generate invoice with Salesforce - 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

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

Salesforce - how can I search for all Opportunity custom fields that are empty (never been populated) for every Opportunity record?

I need to search for any opportunity's custom field that are empty for every record, so that I can delete those fields that are not used by the users. Can I do this by report or by DevConsole, with some query?
I think there are three options that would work best:
Data Loader
Use their Data Loader to export all of your opportunities into a CSV. Load it up in Excel or some other software of your choice and manually dig through the columns ending in __c looking for at least one value.
SOQL
You could manually write a SOQL query that looks at each field (e.g. SELECT Id FROM Opportunity WHERE YourCustomField1__c != null and repeat for each field)
SOQL (Dynamic)
If you're willing to get your programming hands dirty you could make a describe API call to fetch all the fields on the opportunity object. Once you know all the fields you could find fields that end in __c again and write a dynamic SOQL statement to hit the API with.
The Field Trip app (free in the AppExchange) will do this for you. Here's a link:
https://appexchange.salesforce.com/listingDetail?listingId=a0N30000003HSXEEA4
Run it for an object and it gives you a report that lists all the field and tells you what % of records are filled in for each field. My organization has been using it for several years now.
I'm not connected with Qandor. I'm just a satisfied user.

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?

Recommended method to handle record editing with approval in CakePHP?

I haven't been able to find any information regarding the best way to handle record editing with approval in CakePHP.
Specifically, I need to allow users to edit data in a record, but the edited data should not overwrite the original record data until administrators have approved the change. I could put the edited records in a new table and then overwrite the originals when I approve them but I wonder if there is an easier way since this idea doesn't seem to play well with the cake philosophy so to speak.
You are going to need somewhere to store that data until an administrator can approve it.
I'm not sure how this can be easier than creating another table with the new edits and the original post id. Then when an administrator approves the edit, the script overwrites the old record with the edited version.
I'm working on a similar setup and I'm going with storing the draft record in the same table but with a flag set on the record called "draft". Also, the original record has a "draft_id" field that has the id of the draft record stored in it.
Then in the model when the original record is loaded by the display engine it shows it normally. But when the edit or preview actions try to load the record, it checks the "draft_id" field and then loads the other record if it's set.
The "draft" flag is used to keep list and other group find type actions from grabbing the draft records too. This might also be solved by a more advanced SQL query but I'm not quite that good with SQL.

Resources