+ Start a Discussion
Mukesh Kumar 470Mukesh Kumar 470 
public without sharing class FileUpload_ctrl {

    @AuraEnabled
    public static Id saveFile(Id parentId, String fileName, String base64Data, String contentType, String fileDescription )  { 
        
        ContentVersion contentToInsert = new ContentVersion(); 
        contentToInsert.Title = fileDescription + ' - ' + fileName; 
        contentToInsert.VersionData = EncodingUtil.base64Decode(EncodingUtil.urlDecode(base64Data, 'UTF-8'));
        contentToInsert.PathOnClient = '/' + fileName ;
        contentToInsert.Description = fileDescription;
        contentToInsert.IsMajorVersion = false;
        insert contentToInsert; 
        
        contentToInsert = [select id, ContentDocumentId from ContentVersion WHERE Id =: contentToInsert.Id];
        ContentDocumentLink cl = new ContentDocumentLink();
        cl.ContentDocumentId = contentToInsert.ContentDocumentId;
        cl.LinkedEntityId = parentId; 
        cl.ShareType = 'V';
        cl.Visibility = 'AllUsers';
        insert cl;
        
        return contentToInsert.id;
    }
}
 
Best Answer chosen by Mukesh Kumar 470
CharuDuttCharuDutt
Hii Mukesh
Try Below  Code
@isTest
public without sharing class FileUpload_ctrlTest {

   @isTest
    public static void Unittest()  { 
        Account Acc = new Account ();
        Acc.Name = 'Test Account';
        //Fill All Required fields
        insert Acc;

       Id parentId = Acc.Id; 
       String fileName = 'TestFile';
       String base64Data = EncodingUtil.urlDecode('Test base64Data For testing', 'UTF-8');
       String contentType = 'mp4'; 
       String fileDescription = 'Testing File';
        FileUpload_ctrl.saveFile(parentId,fileName,base64Data,contentType,fileDescription );
    }
}
Please Mark It As Best Answer If It Helps
Thank You!
Bogdan Andreev 2Bogdan Andreev 2 
Hey, i create this pdf file. I have one products.
User-added image
User-added image
If i add two products i have an error:  List has more than 1 row for assignment to SObject.
How can i fix it?
public class contr {
    public Opportunity opportunity {get; set;}
    public OpportunityLineItem oppLineItem {get; set;}
    public List<Opportunity> wonOppList {get; set;}
  

    
    public contr(){
        this.opportunity = [SELECT Id, Name, OwnerId, AccountId
                        FROM Opportunity
                        WHERE Id = '0065j00000CLKkxAAH'
                       ];
        
        this.oppLineItem = [SELECT OpportunityId, Name, Quantity, UnitPrice, TotalPrice
                           FROM OpportunityLineItem
                           WHERE OpportunityId = '0065j00000CLKkxAAH'                          
                          ];
       

    }
}
<apex:page controller="contr" applyHtmlTag="false" showHeader="false" renderAs="PDF">
    <html>
        <head>
           
        </head>
        <body>
            <div class="box--half">
                <h2 class="heading heading--sub">Bill To:</h2>
                <span>{!opportunity.Name}</span>
               <div>
                   {!$User.CompanyName } {!$User.Street } {!$User.FirstName} {!$User.LastName}
                </div>
            </div>
            
            <div class="box--full">
                <h2 class="heading heading--sub">Not Invoiced</h2>
                <table>
                    <tr>
                        <th>Name</th>
                        <th>Quantity</th>
                        <th>UnitPrice</th>
                        <th>TotalPrice</th>
                    </tr>
                    <apex:repeat value="{!oppLineItem}" var="oppLineItem">
                        <tr>
                            <td>{!oppLineItem.Name}</td>
                            <td>{!oppLineItem.Quantity}</td>
                            <td>{!oppLineItem.UnitPrice}</td>
                            <td>{!oppLineItem.TotalPrice}</td>
                        </tr>
                    </apex:repeat>
                </table>
            </div>
        </body>
    </html>
</apex:page>


 
Best Answer chosen by Bogdan Andreev 2
SwethaSwetha (Salesforce Developers) 
HI Bogdan,
Your query on OpportunityLineItem in the class contr is returning more than one record, but the variable 'oppLineItem' is a single instance and not a List of OpportunityLineItem which is the issue here. If you change the code as follows, it will work.
 
public List<OpportunityLineItem> oppLineItem{get;set;}

See similar posts: https://salesforce.stackexchange.com/questions/64812/system-queryexception-list-has-more-than-1-row-for-assignment-to-sobject

https://salesforce.stackexchange.com/questions/193665/getting-list-has-more-than-1-row-for-assignment-to-sobject-trying-to-fetch-pri

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
James Vlahos 2James Vlahos 2 
I have a managed package I want to uninstall so that I can install as an unmanaged package. Part of the package is a Permission Set. When I try to uninstall the package I get an error that says:

"This permission set is assigned to one or more users. You can only delete permission sets that aren't assigned to users."

I checked and there are no users assigned.

I also tried to remove the Permission Set first and got a differrent error that says:

"The value of the 'CsrfDelId' parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information."

I reported to customer support but they said they won't do anything because it's a developer org.
Best Answer chosen by James Vlahos 2
James Vlahos 2James Vlahos 2
I was able to find a work around. There was a user assigned to the PermisionSet that, for some reason, wasn't showing up in setup. I was able to use developer console to find and remove the PermissionSetAssignment record. I was then able to uninsall the package I was trying to uninstall.

James
inbox outbox 7inbox outbox 7 
Hi!

I am not looking for a link which directs me to the salesforce documentation or some blog/website. 
Kindly give me a scenario or an example. Please explain. 

Thank you. 
Best Answer chosen by inbox outbox 7
VinayVinay (Salesforce Developers) 
You can reach out to Financial Services Cloud group on https://trailhead.salesforce.com/trailblazer-community/groups/0F93A0000004gQJSAY for inputs on your ask.

Thanks,
Darren WaltonDarren Walton 
Hi,
Related Lists were on the right column (sidebar) of the Opportunity page.  They have now moved to the bottom of the page.
I have tried to use 'Edit Page' to move them back to the right, but there is no section on the right to move them to.
How can I restore Related Lists back to the right?
Thanks Darren
Best Answer chosen by Darren Walton
SwethaSwetha (Salesforce Developers) 
Can you change the template in the 'Edit Page' section and see if you can add the drag and drop the "Related list" component there?

User-added image
If this information helps, please mark the answer as best. Thank you
Best Answer chosen by Amruta Chaudhary
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Amruta,

As per the error it says that there is some ProcessBuilder/Flow with the name "APTS TX Service Quote Actions Update New". As this process builder failed so you are not able to update the record. You may need to debug the Process Builder and fix it.

If this solution helps, Please mark it as best answer.

Thanks
 
Andżela ŚrodaAndżela Środa 
Hello everyone! :) 

I know that can be a stupid question, but how to create history list based on status path on Work Order records?
I want to know who and when change the record status.
User-added image
 
Best Answer chosen by Andżela Środa
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Did you try enabling the history for that field . History tracking can track the status who changed it and old and new values of the field.

If this solution helps, Please mark it as best answer.

Thanks,
 
Liam JeongLiam Jeong 
Hey folks,

I would like to create a custom report type for Approval History(ProcessInstanceStep).

My first approach was creating a trigger or record-triggered flow on the ProcessInstanceStep object.
But for some reason, Salesforce doesn't allow me to create a trigger on the object.

Background information,
There are more than 2,000 submitted approvals daily based.
The client wants to maximize declarative tools' usability.(Not Programatical solution)

How should I resolve this issue?

Much obliged, in advance.
Liam
Best Answer chosen by Liam Jeong
Naveen KNNaveen KN
Thanks for the details, Liam.

I was in the assumption that it is for a single object. Then, it will be difficult to handle all the approval processes(multiple objects) from a single place.

I think we have to Go with Batch apex now!

--
Naveen 
 
Best Answer chosen by inbox outbox 7
PriyaPriya (Salesforce Developers) 

Hi 

While there is overlap, the Tooling API is specifically designed to help developers build IDE apps for salesforce, while the metadata API is more general purpose configuration migration. For example, you can get a symbol table for a class, such as it's members and functions, without writing your own parser. The metadata API is suitable for simple migrations, but the Tooling API gives developers a platform for debugging, code coverage, auto complete, and more.
Consider the migration toolkit versus the Force.com IDE, and you'll see the difference. One lets you move configuration changes, the other lets you develop new code entirely (minus, if course, the fact that auto complete isn't present in current IDE builds). The Developer Console also shows the power of the Tooling API.
Technically, the Tooling API could completely replace the metadata API, since the metadata API, came first and is less powerful, but it will be supported for some time to come yet.
New projects should probably use the Tooling API as much as practical, but the metadata API is widely supported, in comparison, so it will be a while yet until it is completely replaced.

Please mark it as best answer so that it can help others.

Regards,

Priya Ranjan

Raghu kattulaRaghu kattula 
Component



<aura:component controller="Class_Searchtext">
    
    <aura:attribute name="acc" type="Account[]" />
    <aura:attribute name="Search" type="String" />
    
  <lightning:card class="slds-m-around_medium" title="Accounts" iconName="standard:account">
       
       <aura:set attribute="actions">
            <lightning:buttonGroup>
            <lightning:button label="New" />
            <lightning:button label="Import" />
            <lightning:button label="Printable" />
            </lightning:buttonGroup>
       </aura:set>
      <div class="slds-m-around_medium">
          
      <lightning:layout>
          <lightning:layoutItem size="6">
     <lightning:input label="Enter name to search" value="{!v.Search}" />
          </lightning:layoutItem>
          
           <lightning:layoutItem size="6">
              
        <lightning:button label="Search" onclick="{!c.click}"  />
              </lightning:layoutItem>
          </lightning:layout>
          
          
          
         <lightning:layout multipleRows="true">
           
      <aura:iteration items="{!v.acc}" var="a">
          <lightning:layoutItem size="3" padding="around-small">
      Name:{!a.Name}
      Phone:{!a.Phone}
      Rating:{!a.Rating}
        </lightning:layoutItem>
          
          </aura:iteration>
          </lightning:layout>
      </div>
          
          
 </lightning:card>
</aura:component>


Apex class


public class Class_Searchtext
{
  @AuraEnabled
    Public Static List<Account> getaccount(String searchtext)
    {
        String query = 'select id,name,industry,phone,rating from Account where name like \'%'+searchtext+ '%\'';
        List<Account> accounts = Database.query(query);
        Return accounts;
    }
    
}


Controller



({
    click : function(component, event, helper)
    
    {
        var a= component.get("c.Search");
        var action = component.get("c.getaccount");
        
        action.setParams({"searchtext":a});
        action.setCallback(this,function(response){
            var st= response.getState();
            if(st=='SUCCESS')
            {
                var r = response.getReturnValue();
                alert('search results are ');
                component.set("v.acc",r);
            }
            
        });
                       
         $A.enqueueAction(action);                  
    }
})

Application


<aura:application extends="force:slds">
    <c:LC_SearchAccount_v2/>
    
</aura:application>
Best Answer chosen by Raghu kattula
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Raghu,

There was a small mistake in the controller. Can you please change it as below and check. Instead of 
component.get('v.Search');

you re using
var a= component.get("c.Search");

Can you make this change and check.
 
({
    click : function(component, event, helper)
    
    {
        var searchKey= component.get('v.Search');
       // var searchKey = component.find("searchKey").get("v.value");
        var action = component.get("c.getaccount");
        
        action.setParams({"searchtext":searchKey});
        action.setCallback(this,function(response){
            var st= response.getState();
            if(st=='SUCCESS')
            {
                var r = response.getReturnValue();
                alert('search results are ');
                component.set("v.acc",r);
            }
            
        });
                       
         $A.enqueueAction(action);                  
    }
})

If this solution helps, Please mark it as best answer.

Thanks,