• Snehil Karn
  • NEWBIE
  • 15 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
I am trying to implement an intermidiary page which will display after login but before landing on the home page. I am using visualforce login flow for that. I tried the example provided in salesforce help page

https://dreamevent.secure.force.com/articleView?id=security_login_flow_visualforce.htm&type=0

However when I login with the user, it shows the following error and the user is stuck here itself. I do not understand what wrong I am doing:

User-added image

Here are the code snippets:
VF Page
<apex:page showHeader="false" controller="VFLoginFlowController">
  <h1>You are in VF Login Flow</h1>
  <apex:form >
    <apex:commandButton action="{!FinishLoginFlowHome}" value="Finish and Go to Home"/>
    <apex:commandButton action="{!FinishLoginFlowStartUrl}" value="Finish and Go to StartUrl"/>
  </apex:form>
</apex:page>

Controller
public class VFLoginFlowController {

    public PageReference FinishLoginFlowStartUrl() {
        //do stuff
        
        //finish the login flow and send you to the startUrl (account page in this case)
        return Auth.SessionManagement.finishLoginFlow('/001');
    }


    public PageReference FinishLoginFlowHome() {
        //do stuff
        
        //finish the login flow and send you the default homepage
        return Auth.SessionManagement.finishLoginFlow();
    }
}

 
Hello everyone,

I recently went through a trigger which had a SOQL query like this:
 
trigger SoqlTriggerBulk on Account(after update) {  
    // Perform SOQL query once.    
    // Get the accounts and their related opportunities.
    List<Account> acctsWithOpps = 
        [SELECT Id,(SELECT Id,Name,CloseDate FROM Opportunities) 
         FROM Account WHERE Id IN :Trigger.New];
  
    // Iterate over the returned accounts    
    for(Account a : acctsWithOpps) { 
        Opportunity[] relatedOpps = a.Opportunities;  
        // Do some other processing
    }
}

Here I see that in the WHERE clause of the SOQL, user directly passed Trigger.new with IN clause. Is this the correct method? if yes, Is this method encouraged? How can you pass a list of object in the IN clause?

Till now I would have used either a list of Ids to pass in the IN clause or Trigger.newMap.Keyset().
This is also mentioned in on of the trails: https://trailhead.salesforce.com/trails/force_com_dev_beginner/modules/apex_triggers/units/apex_triggers_bulk
I am trying to implement an intermidiary page which will display after login but before landing on the home page. I am using visualforce login flow for that. I tried the example provided in salesforce help page

https://dreamevent.secure.force.com/articleView?id=security_login_flow_visualforce.htm&type=0

However when I login with the user, it shows the following error and the user is stuck here itself. I do not understand what wrong I am doing:

User-added image

Here are the code snippets:
VF Page
<apex:page showHeader="false" controller="VFLoginFlowController">
  <h1>You are in VF Login Flow</h1>
  <apex:form >
    <apex:commandButton action="{!FinishLoginFlowHome}" value="Finish and Go to Home"/>
    <apex:commandButton action="{!FinishLoginFlowStartUrl}" value="Finish and Go to StartUrl"/>
  </apex:form>
</apex:page>

Controller
public class VFLoginFlowController {

    public PageReference FinishLoginFlowStartUrl() {
        //do stuff
        
        //finish the login flow and send you to the startUrl (account page in this case)
        return Auth.SessionManagement.finishLoginFlow('/001');
    }


    public PageReference FinishLoginFlowHome() {
        //do stuff
        
        //finish the login flow and send you the default homepage
        return Auth.SessionManagement.finishLoginFlow();
    }
}

 
One of our clients has a requirement to migrate attachments to Salesforce Files. Salesforce Files (ContentDocument) object doesn't support insert().
They have also enabled this option from Winter '16 to allow file uploads to goto salesforce files instead of attachments.
User-added image

I have confirmed from Salesforce docs and data loader pertaining ContentDocument's supported calls. Now, is there a way I can still pull this task off of migrating attachments to salesforce files?

I am attempting to design a trigger to insert new Content (ContentVersion) when a new attachment is added.  We are switching from using attachments to Content.  However, the majority of files are added through via the desktop email programs (using Maildrop and Salesforce for Outlook) so I have written a trigger to copy the file to Content. Unfortunately, I can't seem to get it working for the body/file.  After insert, the attachment body referenced seems to be in some temp location and before insert the attachment has yet to be loaded so it can't find any body.

 

When I use before insert, I get the following error: Error: Required fields are missing: [Body]

 

When I use after insert, I get the following error: Error: Apex trigger NewAttachment caused an unexpected exception, contact your administrator: NewAttachment: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, java.io.FileNotFoundException: /tmp/bvf/cmp_5879646311450005283.def (No such file or directory): []: Trigger.NewAttachment: line 56, column 5

 

Any suggestions?

 

Here's my trigger:

 

trigger NewAttachment on Attachment (before insert) {

List<Attachment_Tracker__c> tracker = new List<Attachment_Tracker__c>();
List<ContentVersion> CV = new List<ContentVersion>();

for (Integer i = 0; i < Trigger.new.size(); i++) {
	String AttParent = Trigger.new[i].ParentId;
	String ContentDesc = '';
	String FileName = Trigger.new[i].Name;
	Blob BodyData = Trigger.new[i].Body;
		// Check to make sure there is a ParentID for the attachment and if records already exist for this Parent
		if(AttParent!=null) {
			String AttParSub = AttParent.substring(0,15);
			Map<String,ID> TrackMap = new Map<String,ID>();
			for (Attachment_Tracker__c c: [select Contact__c, id from Attachment_Tracker__c Where Contact__c =:AttParent] ) {
				TrackMap.put(c.Contact__c, c.id);
			}

			// Make sure the ParentID is a ContactID and it isn't already in the Attachment Tracker
			if(AttParent.startsWith('003')) {
				//Get the Contact Name
				Contact FullName = [SELECT Name, AccountID, Title FROM Contact WHERE Id = :AttParent];
				ContentDesc = FullName.Name+' ('+FullName.Title+' at '+FullName.AccountID+')';
				String ContName = FullName.Name;
				String ContAcct = FullName.AccountID;
				String ContTit = FullName.Title;
				// Get ID to set the Workspace to Resumes
				ContentWorkspace Workspace = [select id from ContentWorkspace where name = 'Resumes' limit 1];

				////////////////////////////////////////
				// First Copy Attachemnet to Content //
				//////////////////////////////////////
			    CV.add(new ContentVersion(
			    	FirstPublishLocationId = Workspace.id, 
			    	// Title = Trigger.new[i].Name,
			    	Contact__c = Trigger.new[i].ParentId,
			    	PathOnClient = Trigger.new[i].Name, 
			    	VersionData = BodyData
			    	) );

				////////////////////////////////////////
				// Now Update the Attachment Tracker //
				//////////////////////////////////////	
				if(!TrackMap.containsKey(AttParent)){
					tracker.add(new Attachment_Tracker__c(
		            Contact__c = Trigger.new[i].ParentId,
					File_Name__c = Trigger.new[i].Name,
					ContactName__c = ContName,
					Job_Title__c = ContTit,
					Company__c=ContAcct
	                ) ) ;
				}
	        }
		}
    insert tracker;
	insert CV;
	}
}