+ Start a Discussion
Matthew HofmannMatthew Hofmann 
Hello,

I'm creating an Apex class that creates a Salesforce File record and associates it with a parent record. I'm having a problem creating the association (ContentDocumentLink) record.

Here is what I'm doing:
  • Create a ContentVersion record. This creates a ContentDocument record automatically if you leave the ContentVersion.ContentDocumentId field blank. (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentdocument.htm - "To create a document, create a new version via the ContentVersion object without setting the ContentDocumentId. This automatically creates a parent document record.")
  • Insert ContentVersion record
  • DEBUG: Confirm ContentVersion.ContentDocumentId is set (Here is where the problem is because it is NULL; however if I SOQL query ContentVersion after the Apex completes, ContentVersion.ContentDocumentId is set and the corresponding ContentDocument record exists)
  • Create ContentDocumentLink record (commented out because it fails because ContentDocumentLink.ContentDocumentId is a required field)
  • Insert ContentDocumentLink record (commented out because it fails because ContentDocumentLink.ContentDocumentId is a required field)
Here is the code:
public class FileController {
    
    @AuraEnabled
    public static Id saveTheFile(Id parentId, String fileName, String base64Data, String contentType, Id contentDocumentId) { 
        base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
        
        ContentVersion cv = new ContentVersion();
        cv.ContentLocation = 'S';
        cv.ContentDocumentId = contentDocumentId;
        cv.VersionData = EncodingUtil.base64Decode(base64Data);
        cv.Title = fileName;
        cv.PathOnClient = filename;
        
        insert cv;
        
        //***This DEBUG statement must return an Id for the rest of the code to work***
        System.debug('contentDocumentId='+cv.ContentDocumentId);               
        
        //ContentDocumentLink cdl = new ContentDocumentLink();
        //cdl.ContentDocumentId = cv.ContentDocumentId;
        //cdl.LinkedEntityId = parentId;
        //cdl.ShareType = 'I';
        
        //insert cdl;
        
        return cv.Id;
    }

    @AuraEnabled
    public static Id saveTheFile(Id parentId, String fileName, String base64Data, String contentType) {         
        return saveTheFile(parentId, fileName, base64Data, contentType, NULL);
    }
}

Does anyone know what I'm doing wrong, not considering, etc?
Appreciate any thoughts and input!
Best Answer chosen by Matthew Hofmann
VineetKumarVineetKumar
Interesting..

Well the culprit in your code is the null value and way you are using it to assign the value to ContentDocumentLink.contentDocumentId.
You should query the content version object again to get the contentDocumentId (which is generated after the parent document is inserted by default because of you passing of null value).
Something like below :
ContentDocumentLink cdl = new ContentDocumentLink();
cdl.ContentDocumentId = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE Id =: cv.Id].ContentDocumentId;
cdl.LinkedEntityId = '00590000000a6dP';
cdl.ShareType = 'V';
insert cdl;

As per the salesforce documentation lines higlighted by you, "To create a document, create a new version via the ContentVersion object without setting the ContentDocumentId. This automatically creates a parent document record." it does create the parent document record as expected, but the contentDocumentId is still null in above initialised object. Id doesn't get updated automatically to the object instance. Infact you will have to pull out the corresponding Id as done in the above snippet.

Let me know if this helps.
Briana L.Briana L. 
I have a lightning component which is going to be used for a Quick Action on a record page. I have implemented force:QuickActionWithoutHeader because I need to have custom "save" and "cancel" buttons. However, the modal that pops up for the quick action has a lot of excess white space, which makes the header and footer look out of place. How can I fix this?

Current Output:
User-added image


Desired Output:
(Actually I would even like the modal pop-up to be smaller so that the input fields do not have so much excess white space, but if I can get the header and footer to look right I will settle for that)
User-added image


Component Code:
<aura:component implements="force:lightningQuickActionWithoutHeader,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="FileUploadController">

    <div class="modal-header slds-modal__header slds-size_1-of-1">
        <h4 class="title slds-text-heading--medium" >Upload File</h4>
    </div>
        
        <!-- MODAL BODY / INPUT FORM -->    
    <div class="slds-modal__content slds-p-around--x-small slds-align_absolute-center slds-size_1-of-1 slds-is-relative" aura:id="modalbody" id="modalbody">
        <form class="slds-form--stacked">
            <!-- All the fields for the form input -->
       </form> 
  
    </div>   <!-- End of Modal Content -->  
        
        <!-- MODAL FOOTER -->
		<div class="modal-footer slds-modal__footer slds-size_1-of-1">
            <div class="forceChangeRecordTypeFooter">
                <ui:button class="slds-button slds-button_neutral" label="Cancel" press="{! c.cancel}" /> 
                <ui:button class="slds-button slds-button--brand"
                       label="Save" press="{!c.save}"/>
            </div>
        </div>
</aura:component>

 
Best Answer chosen by Briana L.
Briana L.Briana L.
I was able to resolve this issue by adding the following aura:html tag to the my component, NOT in the CSS style part of the bundle.
<aura:html tag="style">
        .cuf-content {
            padding: 0 0rem !important;
        }
        .slds-p-around--medium {
            padding: 0rem !important;
        }       
        .slds-modal__content{
            overflow-y:hidden !important;
            height:unset !important;
            max-height:unset !important;
        }
    </aura:html>

 
Rodolfo CalvoRodolfo Calvo 
Hello team, 
I have this code
String soql = 'SELECT id, firstName, lastName, accountId FROM Contact';
I need to call all contacts from one simple account. 
I tried this: 
 
SELECT firstName, lastName, accountId FROM Contact WHERE accountid = '00000000000000'

This query worked fine, but my issue is calling all contact list from calling the account name: 
For example: I have Account_1, what I only have is the name, we imagine we do not have the ID, how could make this query by calling the name of the account?
I also tried this but there was no succeed.
String soql = 'SELECT id, firstName, lastName, accountId FROM Contact WHERE account.id;
How could I make this query correct? 
Thanks in advance
 
Best Answer chosen by Rodolfo Calvo
Arun GoelArun Goel
If you directly run the query in Developer c
SELECT id, firstName, lastName, accountId FROM Contact WHERE Account.name =  'Master Account'

onsole try this
Nidhi MeshramNidhi Meshram 
Trigger having all the events so in handler there are two methods which i not able to cover how to cover this methods:-

public void afterDelete(SObject so) {
    }
    
    public void afterUndelete(SObject so) {
    }
Best Answer chosen by Nidhi Meshram
Steve Schreiner 4Steve Schreiner 4
Remove the unused events from the trigger. Why have them if never used?
Carrie Nunemaker 10Carrie Nunemaker 10 
I am completely new to Apex and could really use some help with what seems to be a simple task.  I have a formula on the contact, Persona_True__c, that returns a 1 if the custom field "persona" is populated and a 0 if it is blank.

I would like to have a roll-up summary that sums this field at the account level in a field called Related_Personas__c.  

Because we can't roll-up from contact to account I'm reading that this type of action needs to be a trigger, but I don't even know where to start.  Does anyone have any thoughts or expertise they can share to help me out? 
Best Answer chosen by Carrie Nunemaker 10
Anthony McDougaldAnthony McDougald
Good Evening Carrie,
Hope that your day is off to an amazing start. We've constructed a trigger to your specifications. Please test and report back if anything. Hope this helps and may God bless you abundantly.
trigger ContactSumTrigger on Contact (after delete, after insert, after undelete, after update) {

Contact[] cons;
    if (Trigger.isDelete){ 
    cons = Trigger.old;
    }
    else{
    cons = Trigger.new;
    }
Set<ID> acctIds = new Set<ID>();
for (Contact con : cons) {
   acctIds.add(con.AccountId);
}

Map<ID, Contact> contactsForAccounts = new Map<ID, Contact>([SELECT Id, AccountId, Persona_True__c FROM Contact WHERE AccountId IN :acctIds]);

Map<ID, Account> acctsToUpdate = new Map<ID, Account>([SELECT Id, Related_Personas__c FROM Account WHERE Id IN :acctIds]);

for (Account acct : acctsToUpdate.values()) {
Set<Id> conIds = new Set<Id>();
Decimal totalValue = 0;
for (Contact con : contactsForAccounts.values()) {
    if (con.AccountId == acct.Id && con.Persona_True__c != NULL) {
        totalValue += con.Persona_True__c; 
    }
}
acct.Related_Personas__c = totalValue;
}
if(acctsToUpdate.values().size() > 0) {
    update acctsToUpdate.values();
}
}


Best Regards,
Anthony McDougald
iKnowSFDCiKnowSFDC 

I have a list I need to sort by a primary key as well as a secondary key - I tried ORDER BY fieldName AND fieldNAME as well as ORDER BY fieldName AND BY fieldName - neither one compiled on save. 

 

Any ideas? 

 

Thanks!

 

JoAnn

Best Answer chosen by Admin (Salesforce Developers) 
craigmhcraigmh

Order By fieldName1, fieldName2

Best Answer chosen by Pierce Hale 15
vijay kumar kvijay kumar k
Hi Pierce

Greetings to you,

All content document public links are got stored in ContentDistribution Object.
For object reference: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentdistribution.htm
Yes pierce, you can query public url from content distribution object with help of ContentDocumentID or ContentVersionId.

Ex : Select Id,ContentDocumentId,ContentDownloadUrl,DistributionPublicUrl from ContentDistribution where ContentDocumentId='0691000000FOq3nAAD'

I hope this is helpful to you. Please mark this as the best answer if it's useful to you.

Regards
Vijay
Agnibha Chakrabarti 10Agnibha Chakrabarti 10 
Hi,
I have to replicate the New Case to create a new case in lightning component. I have to create look up input box in that page.
and Store the value in case object after clicking the Save button.

Can anybody help me with the creation of lookup input field and storing it into the Case object?

Thanks
Best Answer chosen by Agnibha Chakrabarti 10
Devi ChandrikaDevi Chandrika (Salesforce Developers) 

Hi,
To create lookup input field in lightning we have to create custom lightning component.
Please refer below links which might help you with this
http://www.jitendrazaa.com/blog/salesforce/lookup-component-in-salesforce-lightning/
http://sfdcmonkey.com/2017/07/17/re-usable-custom-lookup/
https://developer.salesforce.com/blogs/developer-relations/2015/06/salesforce-lightning-inputlookup-missing-component.html

Here is an idea to vote on this
https://success.salesforce.com/ideaView?id=08730000000Dom1AAC

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards

YiQin HeYiQin He 
Hi, 

I created a lightning component as a quick action button. In the component, I have a cancel button that I want it closed when user clicks.
User-added image

But the problem is that I cannot find any document explain how to close the modal dialog. This is the ui code:
<aura:component controller="ContactController" implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" >
    <style>
        .changeRecordTypeRow {
        margin-top: 1.5rem;
        margin-bottom: 0;
        margin-left: 0;
        margin-right: 0;
        }
        
        .changeRecordTypeLeftColumn {
        float: left;
        text-align: right;
        padding-right: 1.5rem;
        width: 35%;
        font-size: .8125rem;
        color: rgb(84, 105, 141);
        }
        
        .changeRecordTypeRightColumn {
        float: right;
        text-align: left;
        width: 65%;
        }
        
        .modal-body
        {
        	height:auto !important;
        	padding:0;
        }
        
        .forceChatterLightningComponent .bodyWrapper{height:100%;width:100%;padding:0;box-sizing:border-box}
    </style>
    <div class="modal-header slds-modal__header">
        <h2 class="title slds-text-heading--medium" >Change Contact Type</h2>
    </div>
    <div class="scrollable slds-modal__content slds-p-around--medium">
        <div class="changeRecordTypeRow">
            <fieldset class="slds-form-element">
                <div class="changeRecordTypeLeftColumn">
                    <legend class="form-element__legend slds-form-element__label">Select a record type</legend>
                </div>
                <div class="changeRecordTypeRightColumn slds-form-element__control">

                    <span class="slds-radio">
                        <input type="radio" id="radio_PrimaryContact" name="recordType" />
                        <label class="slds-radio__label" for="radio_PrimaryContact">
                            <span class="slds-radio--faux"></span>
                            <span class="slds-form-element__label">Primary Contact</span>
                        </label>
                    </span>
                    <span class="slds-radio">
                        <input type="radio" id="radio_SecondaryContact" name="recordType" />
                        <label class="slds-radio__label" for="radio_SecondaryContact">
                            <span class="slds-radio--faux"></span>
                            <span class="slds-form-element__label">Secondary Contact</span>
                        </label>
                    </span>
                </div>
            </fieldset>
        </div>
	</div>
    <div class="modal-footer slds-modal__footer">
    	<div class="forceChangeRecordTypeFooter">
        	<button type="button" class="slds-button slds-button--neutral .slds-modal__close" aura:id="btnCancel" >
            	Cancel
            </button>
            <button type="button" class="slds-button slds-button--brand" aura:id="btnSave">
            	Save
            </button>
        </div>
    </div>
</aura:component>
Does anyone have similar experience? Thanks in advance.
Best Answer chosen by YiQin He
YiQin HeYiQin He
Hi Karthik,

Thanks for the reply. I've already found the solution.
Call this method $A.get("e.force:closeQuickAction").fire() will close the modal dialog.

Yiqin
SandrineSandrine 
Hello,

I alwaays get error when i try to save something from Dev console

Failed to create createContainerMember for containerId duplicate value found: <unknown> duplicates value on record with id: <unknown>
Best Answer chosen by Sandrine
AshlekhAshlekh
Hi,

Follow these stepsGo to Developer Console -> Work Space -> New Workspace
Create a new workspace
Save classes/triggers

*https://help.salesforce.com/apex/HTViewSolution?id=000204953&language=en_US

Try again, it should be fixedIf my answer helps resolve your query, please mark it as the 'Best Answer' and upvote it to benefit others and improve the overall quality of Discussion Forums.


-Thanks
Ashlekh Gera