Thursday, 4 July 2019

Export Apex Result To CSV File

Use Case : Get the Contract object Field Label  and Field Name (API) name & Export that result to CSV file and Send Email Notification.


//To get all the objects details    
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map<String, Schema.SObjectField> fieldMap = schemaMap.get('Contract').getDescribe().fields.getMap();
string header = 'FIELD LABEL , FIELD NAME\n'; //CSV Header Row
string contrExcelStr = header ;

//Loop through the field map and get the object field label & field name(API Name)
for(Schema.SObjectField sfield : fieldMap.Values())
{
 schema.describefieldresult descField = sfield.getDescribe();
 mapResult.put(descField.getLabel(),descField.getname());
 string recordString = descField.getLabel() +','+descField.getname() +'\n';
 contrExcelStr = contrExcelStr +recordString;
}

 //Email Notification
Messaging.EmailFileAttachment contrCsvAttch = new Messaging.EmailFileAttachment();
blob csvBlob = Blob.valueOf(contrExcelStr);
string csvname= 'Contract.csv';
contrCsvAttch.setFileName(csvname);
contrCsvAttch.setBody(csvBlob);
Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
String[] toAddresses = new list<string> {'test@gmail.com'};
String subject ='Contract CSV';
email.setSubject(subject);
email.setToAddresses( toAddresses );
email.setPlainTextBody('Contract CSV ');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{contrCsvAttch});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

//Sent Email 


Tuesday, 2 July 2019

Salesforce 2 Salesforce Connect

S2S File Sharing Refer

1.What is Salesforce 2 Salesforce Connect ?
It is point-and-click integration tool that allows you to replicate data between 2 orgs.
Ex: Create account in one org and that should share with another org

2. All standard & custom objects records can be shared?
No,You can publish only certain objects
  • Account
  • Attachment (unencrypted)
  • Case
  • Case Comment
  • Contact
  • Lead
  • Opportunity
  • Opportunity Product
  • Product
  • Task
  • Custom Object
3.Pros & Cons of S2S ?
Pros :
1.S2S allows you and your business partners to collaborate more easily and effectively.
2.You can share records with one or more connections.
Cons :
1.S2S can be between 2 sandboxes / 2 production org not between sandbox & production org.
2.You can’t accept forwarded records on the Salesforce mobile app.
3. You can not publish the look up Id's.
4. There is no upsert on the object 'PartnerNetworkRecordConnection',Only Insert can perform.

4.Explain with business use case ?
In real time,Consider a company acquired 2 different companies & Each has its own ERP system and then required to merge those systems,
Ex: Opportunity of one system should trigger to another system and the remaining business rules will trigger in other system.

5.Explain Steps for S2S implementation?
1.Enabling Salesforce to Salesforce (S2S),In both source & target org.
A new user named “Connection User” is created on the enable.
"Connection user"  - Is the user that performs the actions on behalf of the shared connection

2.S2S integration user in Source & Target Org


3.Create Contact & Account in Source & Target Org - Use the same email id of the contact in both the orgs.

4.Setup a connection,The connection tab will be available only after S2S enabled.


5.Send Invite to the contact on the new connection establishment request,The contact of the source & target will be pointed to same email id,Consider this as "Connection User" exist in both orgs.If invite is accepted then connection gets established.



6.Publish Objects

7.Subscribe Objects & Auto-Accept
If Auto-Accept is not selected then administrator has to review the incoming records and then accept,

8.Field Mapping & Pick List Field Value Mapping (Click on the Edit Values to map)


9.Share Record By Forward To Connection


10.The shared record system info details,The created by is "Connection user"

11.External Shared Related List,If not available add to the page layout.


6.Is it possible to automate S2S configuration / Field Mapping ?
No. There's no SOAP, REST, Tooling, or Metadata object that represents a field mapping for S2S,
Either through manual / Scripting (Selenium)/ Browser Control Technique (UI Path).
Refer

7.How to know the status of shared record ?
If we select option "Send Email",It will send an email with the details of shared record / In case of any error while sharing the record that details will be sent & Same will be available in the "Connection History" of the connection.




8.Expected errors & Solutions ?
1.Insufficient Privileges on click of connection establishment link
Sln:Enable S2S in this org
2.Forward To Connections button not found
Sln:
-->The 'Forward to Connections' button is only visible when the User viewing the object list view has the 'Manage Connections' permission enabled either via the Profile or via a Permission Set.

-->Add that button in the Search layout -->List View Layout


8.What are the PartnerNetworkConnection & PartnerNetworlRecordConnection?

PartnerNetworkConnection
PartnerNetworkRecordConnection
This object represents a Salesforce to
Salesforce connection
between Salesforce organizations.
This object represents a record shared
between Salesforce organizations using
Salesforce to Salesforce.
9.How to share the record programmatically in S2S apart from using the 'Forward To Connection' button ?
------------------------------------------------------------------------------------------------------------------------
// Define Network id String connectionName = 'SF_Bytes' List<PartnerNetworkConnection> partnerNetConList = [Select id from PartnerNetworkConnection where connectionStatus = 'Accepted' and connectionName = :connectionName]; Id networkId = partnerNetConList.get(0).Id; // Send Parent & Child (Attachment File) programatically PartnerNetworkRecordConnection newConnection = new PartnerNetworkRecordConnection( ConnectionId = networkId, LocalRecordId = '0010S00000OnyrK', SendClosedTasks = false, SendOpenTasks = false, SendEmails = true); insert newConnection;
------------------------------------------------------------------------------------------------------------------------

Wednesday, 15 May 2019

Lightning Knowledge - Insert Article Content Into Emails

1. Enable Email-to-Case

2. Add Email quick action [Send Email] to the expected record type page layout

3. If the Email button is not reflecting ,Go and check the Email Deliverability,It should be 'All Email'

4. After settings verify the display of Email button in Feed tab

5. Enable user as 'Knowledge User',If already enabled no changes required & User Profile should have "CustomizeApplication", "Manage Salesforce Knowledge" permissions

6.Knowledge settings :
6.1 Support Settings :


6.2 Feed View Settings :


7. Communication Channel Mappings
Note : Please note for which record type this is been creating & If requires create for all the record types as per business requirement.



8. After all the above successful steps can see 'Insert Article Contents into Email ' button on article




Issues :
1.May be not finding the 'Insert Article Contents into Email' button ?
Ans : Verify the communication channel mapping is created for that article record type or not.
If not please create and verify.

2.Error :The email publisher is unavailable. Contact your admin to enable the email publisher.
Ans : Navigate the Feed tab & Select Email sub tab and then select the option 'Insert Article Contents into Email ' in the article


References :
Refer1
Refer2
Refer3



Thursday, 9 May 2019

Salesforce Latest Released Features

There are many features in every release,Listing the features which i came across & Felt cool  :)

Salesforce Summer ’19 Release Notes 

Quick Filters on Related List :

Its very much required feature,Which helps to filter the related list records.

Ex: Account has many Cases,So this feature helps to filter and see the result as expected.


Limitation :

Cloning Sandboxes :

This feature will be useful when need's to deploy complete Metadata + Data from one sandbox to other.

It will helps in Saving Time & Deployment efforts.

How to clone  ? Is the same way how sandbox is created from production,Instead of production give the source as the expected sandbox which needs to be cloned.



Friday, 3 May 2019

Salesforce Advanced FAQ2

1. Can you search/filter Salesforce related list??


Yes,Refer

2. Why users cannot be deleted in Salesforce?


Yes, there is no option to delete the created user in Salesforce only you can deactivate.
     Reason is  the user might have created some records and part of some ownership so deletion
    of the user creates orphan records and impacts the business.

3. Cannot be created from Case object only allow from Account related list, How to implement this?


We can’t hide ‘new’ Button on Standard Object we can override it with Visualforce 
      Page / Write Java-script code for Home Page Components.

      Note: If it is available from Account related list means the user has permission to create the case ,
      So from case object also it will be available.


4. Search layouts can be assigned profile level?


No,Currently while page layouts are assigned to profiles, there is no way to assign search layouts 
     to profiles. We would like the ability to assign different "search layouts" to different profiles.
     Refer


5. Attachment object is supported in process builder?


No,As of now ,It not supported in WorkFlow & Process Builder
    Refer

    NoteAttachment is deprecated in Lightning using Salesforce Files
    Refer

6. Where the attached files to a record will be saved ?


In lightning when you upload attachments, it save as salesforce files
     Lightning uses ContentDocument for attachments
    Classic uses Attachment object for attachment
    Refer 

    NoteAttachment is deprecated in Lightning using Salesforce Files
    Refer


7. Case Document Attachment Notification to owner when attached by other user?

Refer

8. Send email notification to the case followers ?


 Using "Chatter Streams ,Whenever chatter feed post happens will trigger an email notification 
      to the followers.
      Note : Only for post not for field tracking  
      Refer
      
      


9. Send email notification to the case contact on case close ?



    Case "Send notification email to contact " is enabled only for Case Creation Template in lightning.
    So on any update on case you can check this to send notification to contact.
      Refer
   




10. Can't access all enhanced notes records via SOQL query ?

Yes,Refer