• ForceRookie
  • NEWBIE
  • 110 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 49
    Questions
  • 69
    Replies

Please help me, I can't see any reference on how to make test class for it..

public class ProcessController {
    public ProcessController(ApexPages.StandardSetController stdController) {}
    public PageReference runBatch() {
        MyUpdateBatch batch = new MyUpdateBatch ();
        Database.executeBatch(batch);
        
        return new ApexPages.Action('{!List}').invoke();
    }
}

Thanks!

I have created a trigger callout but I am getting this error..

Please help me get through..

Handler:

public class FileDeleteHandler {
    @future(callout=true)
    public void fileDeleteMethod(List<ContentDocument> scope) {
        List<CustomSettings__c> settings =  [SELECT BucketName__c, ClientKey__c, Region__c, SecretKey__c FROM CustomSettings__c LIMIT 1];

        String bucketName = '';
        String region = '';
        String clientKey = '';
        String secretKey = '';

        if(!settings.isEmpty()){
            bucketName = settings[0].BucketName__c;
            region = settings[0].Region__c;
            clientKey = settings[0].ClientKey__c;
            secretKey = settings[0].SecretKey__c;
            if(String.isBlank(bucketName)||String.isBlank(region)||
                String.isBlank(clientKey)||String.isBlank(secretKey)){
                return;
            }
        }
        Set<Id> fileIds = new Set<Id>();
        for (ContentDocument cv : scope) {
            fileIds.add(cv.Id);
        }

        List<Custom_Object__c> coList = [SELECT Id, Name, Path__c, File_ID__c, File_Saved__c FROM Custom_Object__c WHERE File_ID__c =: fileIds];

        if (!coList.isEmpty()) {
            if (coList[0].File_Saved__c== true) {
                //make callout
                //delete file from AWS
                List<ContentVersion> cvs = [SELECT Title, ContentDocumentId, FileExtension, FileType, VersionData FROM ContentVersion WHERE ContentDocumentId IN :fileIds];

                String path = coList[0].Path__c; //Salesforce/ObjectName/RecordId/Filename

                String formattedDateString = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z');
                Blob data = cvs[0].VersionData; // System.ListException: List index out of bounds: 0

                HttpRequest req = new HttpRequest();
                Http http = new Http();

                req.setHeader('Content-Type', cvs[0].FileExtension);
                req.setMethod('DELETE');
                req.setHeader('Host','s3.amazonaws.com');
                req.setEndpoint('https://s3.amazonaws.com'+'/'+bucketName+'/'+path);
                req.setHeader('Date',formattedDateString);
                req.setHeader('Authorization', createAuthHeader('DELETE', cvs[0].FileExtension, path, formattedDateString, bucketName, clientKey, secretKey));
                req.setBodyAsBlob(data);
                req.setHeader('Content-Length', String.valueOf((EncodingUtil.base64Encode(data)).length()));

                try{
                    HTTPResponse res = http.send(req);

                    System.debug('MYDEBUG: ' + cvs[0].Title + ' RESPONSE STRING: ' + res.toString());
                    System.debug('MYDEBUG: ' + cvs[0].Title + ' RESPONSE STATUS: '+res.getStatus());
                    System.debug('MYDEBUG: ' + cvs[0].Title + ' STATUS_CODE:'+res.getStatusCode());

                } catch(System.CalloutException e) {
                    System.debug('AWS Callout Exception on ' + cvs[0].Title + 'ERROR: ' + e.getMessage());
                }
            } else if (coList[0].File_Saved__c== false) {
                 delete coList;
            }
        }
    }

    public string createAuthHeader(String method,String contentType,String filename,String formattedDateString,String bucket,String client,String secret){
        string auth;
        String stringToSign = method+'\n\n'+contentType+'\n'+formattedDateString+'\n/'+bucket+'/'+filename;
        Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof(secret));
        String sig = EncodingUtil.base64Encode(mac);
        auth = 'AWS' + ' ' + client + ':' + sig;
        return auth;
    }
}


Trigger:

trigger DocumentTrigger on ContentDocument (before delete) {
    if (Trigger.isBefore) {
        if (Trigger.isDelete) {
            FileDeleteHandler handler = new FileDeleteHandler();
            handler.fileDeleteMethod(Trigger.old);
        }
    }
}

Hi! I am trying to upload an Atttachments based on the selection and criteria from Lightning Component that will be saved to Custom Setting.

For example, the criteria is Opportunity - Stage - Closed Won, I need to query to get all attachments from Closed Won Opportunity and upload them to AWS.

But I don't know how to do it dynamically, please help me.

User-added image

global class UploadAttachments implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id, Objects__c, Fields__c, Field_Value__c FROM ForUploadCustomSettings__c';
        return Database.getQueryLocator(query);
    }

       global void execute(Database.BatchableContext BC, List<sObject> scope) {
        String formattedDateString = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z');   
        String host = 's3.amazonaws.com';
        String method = 'PUT';
        
        HttpRequest req = new HttpRequest();
        Http http = new Http();
        
        Set<Id> Ids = new Set<Id>();
        for (sObject so : scope) {
            Ids.add(so.Id);
        }
        List<Attachment> att = [SELECT Id, Name, Body, ContentType FROM Attachment WHERE ParentId IN :Ids];
        
        List<AWScredentialsSettings__c> values = [SELECT Id, ClientKey__c, SecretKey__c, BucketName__c FROM AWScredentialsSettings__c LIMIT 1];
        if (!att.isEmpty() && !values.isEmpty()) {
            String bucketname = values[0].BucketName__c;
            String key = values[0].ClientKey__c;
            String secret = values[0].SecretKey__c;
            String attachmentBody = EncodingUtil.base64Encode(att[0].Body);
            String filename = att[0].Name;
            
            req.setMethod(method);
            req.setEndpoint('https://' + host + '/' + bucketname + '/' + filename); // The file should be uploaded to this path in AWS -- ObjectName/Salesforce Id/Secret Files/filename
            req.setHeader('Content-Length', String.valueOf(attachmentBody.length()));
            req.setHeader('Content-Encoding', 'UTF-8');
            req.setHeader('Content-type', att[0].ContentType);
            req.setHeader('Connection', 'keep-alive');
            req.setHeader('Date', formattedDateString);
            req.setHeader('ACL', 'public-read');
            req.setBody(attachmentBody);
            
            String stringToSign = method+'\n\n\n'+ att[0].ContentType + '\n' + formattedDateString +'\n/'+ bucketname +'/' + filename;
            Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof(secret));
            String signed  = EncodingUtil.base64Encode(mac);
            String authHeader = 'AWS' + ' ' + secret + ':' + signed;
            req.setHeader('Authorization',authHeader);
            
            HTTPResponse res = http.send(req);
            System.debug('*Resp:' + String.ValueOF(res.getBody()));
            System.debug('RESPONSE STRING: ' + res.toString());
            System.debug('RESPONSE STATUS: ' + res.getStatus());
            System.debug('STATUS_CODE: ' + res.getStatusCode());
        }
    }
    
    global void finish(Database.BatchableContext BC) {
        
    }
}

I'm doing an upload attachment to AWS, but I'm getting this error -- 'You have uncommitted work pending. Please commit or rollback before calling out'
How do I fix this?

@AuraEnabled
    public static void savePDupcsSettings(ForUploadCustomSettings__c upcsSet, String recId){
        ForUploadCustomSettings__c upcs = new ForUploadCustomSettings__c();
        upcs = upcsSet;
        if (upcs.Objects__c != null) {
			if (recordId != null) {
                upcs.Name = upcs.Objects__c +'-'+ upcs.Fields__c +'-'+ upcs.Value__c;
			    update upcs;
            } else {
                ForUploadCustomSettings__c newVal = new ForUploadCustomSettings__c();
                newVal.Name = upcs.Objects__c +'-'+ upcs.Fields__c +'-'+ upcs.Value__c;
                newVal.Objects__c = upcs.Objects__c;
                newVal.Fields__c = upcs.Fields__c;
                newVal.Value__c = upcs.Value__c;
                insert newVal;
            }
        }
        
        String stage = 'Closed Won';
        ForUploadCustomSettings__c csList = [SELECT Id, Id, Objects__c, Fields__c, Value__c 
                                                              FROM ForUploadCustomSettings__c 
                                                              WHERE Value__c = :stage LIMIT 1];
        if (csList != null) {
            Set<Id> Ids = new Set<Id>();
			for (Opportunity opp : [SELECT Id, Name FROM Opportunity WHERE IsClosed = true AND IsWon = true]) {
				Ids.add(opp.Id);
			}

			String formattedDateString = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z');   
			String host = 's3.amazonaws.com/';
			String method = 'PUT';
			
			HttpRequest req = new HttpRequest();
			Http http = new Http();

			List<Attachment> att = [SELECT Id, Name, Body, ContentType FROM Attachment WHERE ParentId IN :Ids];
			List<AWScredentialsSettings__c> creds = [SELECT Id, ClientKey__c, SecretKey__c, BucketName__c FROM AWScredentialsSettings__c LIMIT 1];
			if (!att.isEmpty() && !creds.isEmpty()) {
				String bucketname = creds[0].BucketName__c;
				String key = creds[0].ClientKey__c;
				String secret = creds[0].SecretKey__c;
				String attachmentBody = EncodingUtil.base64Encode(att[0].Body);
				String filename = att[0].Name;
				
				req.setMethod(method);
				req.setEndpoint('https://' + host + bucketname + '/' + filename); // The file should be uploaded to this path in AWS -- Opportunity/Salesforce Id/Secret Files/filename
				req.setHeader('Content-Length', String.valueOf(attachmentBody.length()));
				req.setHeader('Content-Encoding', 'UTF-8');
				req.setHeader('Content-type', att[0].ContentType);
				req.setHeader('Connection', 'keep-alive');
				req.setHeader('Date', formattedDateString);
				req.setHeader('ACL', 'public-read');
				req.setBody(attachmentBody);
				
				String stringToSign = method+'\n\n\n'+ att[0].ContentType + '\n' + formattedDateString +'\n/'+ bucketname +'/' + filename;
				Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof(secret));
				String signed  = EncodingUtil.base64Encode(mac);
				String authHeader = 'AWS' + ' ' + secret + ':' + signed;
				req.setHeader('Authorization',authHeader);
			}
			
			HTTPResponse res = http.send(req);
			System.debug('*Resp:' + String.ValueOF(res.getBody()));
			System.debug('RESPONSE STRING: ' + res.toString());
			System.debug('RESPONSE STATUS: ' + res.getStatus());
			System.debug('STATUS_CODE: ' + res.getStatusCode());
        }
    }

So, I have a Lightning Component, when changes occurs there, it will save on Custom Settings.

If Object__c = Opportunity and Value__c = Closed Won from CustomSettings, I have to find the Opportunity record that meets the condition. If the Opporutnity record has Notes and Attachments, it will be uploaded to AWS.

Should I do it on Controller class or another trigger or class?

Please help me if this is correct:

String formattedDateString = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z');   
		String host = 's3.amazonaws.com/';
        String method = 'PUT';
        
        HttpRequest req = new HttpRequest();
		Http http = new Http();
        
        Set<Id> Ids = new Set<Id>();
        for (Opportunity opp : [SELECT Id, Name FROM Opportunity WHERE IsClosed = true AND IsWon = true]) {
            Ids.add(opp.Id);
        }
		List<Attachment> att = [SELECT Id, Name, Body, ContentType FROM Attachment WHERE ParentId IN :Ids];
        
        List<AWScredentialsSettings__c> values = [SELECT Id, ClientKey__c, SecretKey__c, BucketName__c FROM AWScredentialsSettings__c LIMIT 1];
        if (!att.isEmpty() && !values.isEmpty()) {
			String bucketname = values[0].BucketName__c;
			String key = values[0].ClientKey__c;
			String secret = values[0].SecretKey__c;
        	String attachmentBody = EncodingUtil.base64Encode(att[0].Body);
            String filename = att[0].Name;
            
            req.setMethod(method);
            req.setEndpoint('https://' + host + bucketname + '/' + filename); // The file should be uploaded to this path in AWS -- Opportunity/Salesforce Id/Secret Files/filename
            req.setHeader('Content-Length', String.valueOf(attachmentBody.length()));
            req.setHeader('Content-Encoding', 'UTF-8');
            req.setHeader('Content-type', att[0].ContentType);
            req.setHeader('Connection', 'keep-alive');
            req.setHeader('Date', formattedDateString);
            req.setHeader('ACL', 'public-read');
            req.setBody(attachmentBody);
            
            String stringToSign = method+'\n\n\n'+ att[0].ContentType + '\n' + formattedDateString +'\n/'+ bucketname +'/' + filename;
            Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof(secret));
            String signed  = EncodingUtil.base64Encode(mac);
            String authHeader = 'AWS' + ' ' + secret + ':' + signed;
            req.setHeader('Authorization',authHeader);
        }
        
        HTTPResponse res = http.send(req);
        System.debug('*Resp:' + String.ValueOF(res.getBody()));
        System.debug('RESPONSE STRING: ' + res.toString());
        System.debug('RESPONSE STATUS: ' + res.getStatus());
        System.debug('STATUS_CODE: ' + res.getStatusCode());
	}
The scenario is, if Opportunity is Closed Won in Custom Settings, and if the Opportunity will meet the condition, the process will move the Attachments from this record to the AWS and will be deleted from this record.
The files should be uploaded from this path in AWS -- Opportunity/Salesforce Id/Secret Files/filename
Please help me improve my code here:
global class UploadAttachments implements Database.Batchable<sObject> {
	
	global Database.QueryLocator start(Database.BatchableContext BC) {
        String csname = 'OpportunityClosedWon';
		String query = 'SELECT Id, Objects__c, Fields__c, Field_Value__c FROM ForUploadCustomSettings__c WHERE Name = :csname';
		return Database.getQueryLocator(query);
	}

   	global void execute(Database.BatchableContext BC, List<Opportunity> scope) {
        String formattedDateString = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z');   
		String host = 's3.amazonaws.com/';
        String method = 'PUT';
        
        HttpRequest req = new HttpRequest();
		Http http = new Http();
        
        Set<Id> Ids = new Set<Id>();
        for (Opportunity opp : [SELECT Id, Name FROM Opportunity WHERE IsClosed = true AND IsWon = true]) {
            Ids.add(opp.Id);
        }
		List<Attachment> att = [SELECT Id, Name, Body, ContentType FROM Attachment WHERE ParentId IN :Ids];
        
        List<AWScredentialsSettings__c> values = [SELECT Id, ClientKey__c, SecretKey__c, BucketName__c FROM AWScredentialsSettings__c LIMIT 1];
        if (!att.isEmpty() && !values.isEmpty()) {
			String bucketname = values[0].BucketName__c;
			String key = values[0].ClientKey__c;
			String secret = values[0].SecretKey__c;
        	String attachmentBody = EncodingUtil.base64Encode(att[0].Body);
            String filename = att[0].Name;
            
            req.setMethod(method);
            req.setEndpoint('https://' + host + bucketname + '/' + filename); // The file should be uploaded to this path in AWS -- Opportunity/Salesforce Id/Secret Files/filename
            req.setHeader('Content-Length', String.valueOf(attachmentBody.length()));
            req.setHeader('Content-Encoding', 'UTF-8');
            req.setHeader('Content-type', att[0].ContentType);
            req.setHeader('Connection', 'keep-alive');
            req.setHeader('Date', formattedDateString);
            req.setHeader('ACL', 'public-read');
            req.setBody(attachmentBody);
            
            String stringToSign = method+'\n\n\n'+ att[0].ContentType + '\n' + formattedDateString +'\n/'+ bucketname +'/' + filename;
            Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof(secret));
            String signed  = EncodingUtil.base64Encode(mac);
            String authHeader = 'AWS' + ' ' + secret + ':' + signed;
            req.setHeader('Authorization',authHeader);
        }
        
        HTTPResponse res = http.send(req);
        System.debug('*Resp:' + String.ValueOF(res.getBody()));
        System.debug('RESPONSE STRING: ' + res.toString());
        System.debug('RESPONSE STATUS: ' + res.getStatus());
        System.debug('STATUS_CODE: ' + res.getStatusCode());
	}
	
	global void finish(Database.BatchableContext BC) {
		
	}
	
}

 

Help me to code it on APEX, the records should be visible to the user if the current user is the CreatedBy.

public class MyFilesSharingHandler {
	public void shareRecord(List<CustomObject__c> scope) {
		if (Trigger.isInsert) {
			
			List<CustomObject__Share> shareLst = new List<CustomObject__Share>();
			for (CustomObject__c c : scope) {
				CustomObject__Share share = new CustomObject__Share();
				share.AccessLevel = 'Read';
				share.ParentId = c.Id;
				share.UserOrGroupId = c.CreatedById;
				shareLst.add(share);
			}
			if (!shareLst.isEmpty()) {
				insert shareLst;
			}
		}
	}
}

How can I get all Objects except the System Objects in SF?

Here's my code. But I need to revise it to get only the needed Objects.

@AuraEnabled
	public static List<SelectOption> fetchAllObjects(){
        Set<String> listObjs = new Set<String>();
        for(MyCustomSettings__c cs : [Select Id, Objects__c From MyCustomSettings__c]){
            listObjs.add(cs.Objects__c);
        }

		List<SelectOption> objList = new List<SelectOption>();
        Set<String> csObjNames = new Set<String>();
        Map<String, String> mapName = new Map<String, String>();
        Map<String, String> mapLabel = new Map<String, String>();
		for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values()){
            System.debug(objTyp.getDescribe().getLabel());

            if ( objTyp.getDescribe().isCreateable()) {
                csObjNames.add(objTyp.getDescribe().getLabel());
                    mapName.put(objTyp.getDescribe().getLabel(), objTyp.getDescribe().getName());
                    mapLabel.put(objTyp.getDescribe().getName(), objTyp.getDescribe().getLabel());
            }
		}

        List<String> objNamesCast = new List<String>();
        objNamesCast.addAll(csObjNames);
        objNamesCast.sort();

        for(String s : objNamesCast){
            String objTypeName = mapName.get(s);
            String objTypeLabel = mapLabel.get(objTypeName);
            if(!listObjs.contains(objTypeName)) objList.add(new SelectOption(objTypeName,objTypeLabel));
            else objList.add(new SelectOption(objTypeName,objTypeLabel, true));
        }

		return objList;   
	}

Help me on how to code the Test Connection to AWS. Please.

and should I put it on the controller?
User-added image

Help me on how to set the Name based on selected Object (from dropdown) on upsert.

I'm using Custom Settings.

@AuraEnabled
    public static void saveCustomSettings(MyCustomSettings__c cs){
        MyCustomSettings__c cust = new MyCustomSettings__c();
        cust = cs;
        upsert cust;
    }

User-added image

I converted my lightning:combobox into slds combobox to use data attributes, now, dropdown is not showing. Please help me.

And also, how to put the selected item into input textbox?

<aura:attribute name="myObject" type="List"/>
<aura:attribute name="myCustomSettings" type="MyCustomSettings__c[]"/>

<aura:iteration items="{!v.myCustomSettings}" var="obj" indexVar="index">
	<tr class="slds-hint-parent">
		<td role="gridcell" data-label="Object">
			<div class="slds-form-element slds-form-element__control">
				<div class="slds-combobox_container">
					<div aura:id="open" class="slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click" aria-expanded="true" aria-haspopup="listbox" role="combobox">
						<div class="slds-combobox__form-element slds-input-has-icon slds-input-has-icon_right" role="none">
							<input type="text" class="cellField slds-input slds-combobox__input" role="textbox" autocomplete="off" readonly="true"
									aura:id="allObjects"
									placeholder="-Select-"
									data-id="{!'index-' + index + 1}"
									data-value="{!index + 1}"
									value="{!obj.Object__c}"
									onfocus="{!focus}"/>
							<span class="slds-icon_container slds-icon-utility-down slds-input__icon slds-input__icon_right">
								<lightning:icon class="slds-icon slds-icon-text-default slds-icon_xx-small" iconName="utility:down" size="xx-small" variant="brand" />
							</span>
						</div>
						<div aura:id="options" class="slds-dropdown slds-dropdown_length-5 slds-dropdown_fluid" role="listbox">
							<ul class="slds-listbox slds-listbox_vertical" role="presentation">
								<aura:iteration items="{!v.myObject}" var="myLst" indexVar="i">
									<li aura:id="selectObj" role="presentation" class="slds-listbox__item" onclick="{!c.itemSelected}" data-id="{!'index-' + i + 1}" data-value="{!i + 1}">
										<div id="{!i + 1 + '-item'}" aura:id="is-selected" class="slds-media slds-listbox__option slds-listbox__option_plain slds-media_small" role="option">
											<span class="slds-media__figure slds-listbox__option-icon"></span>
											<span class="slds-media__body">
												<span class="slds-truncate" title="{!myLst.label}">{!myLst.label}</span>
											</span>
										</div>
									</li>
								</aura:iteration>
							</ul>
						</div>
					</div>
				</div>
			</div>
		</td>
	<tr>
<aura:iteration/>
 
focus : function (component, event, helper) {
	var open = component.find("open");
	$A.util.toggleClass(open, 'slds-is-open');
},
 
itemSelected : function(component, event, helper) {
        var selectedItem = event.currentTarget;
        var id = selectedItem.dataset.id;
        var elements = component.find('selectObj');
        for (var i = 0; i < elements.length; i++) {
            var val = elements[i].getElement().getAttribute('data-id');
            if(val == id) {
                console.log(val);
                //put the selected item to input textbox
            }
        }
    },

Help me on how can I make this lightning:combobox to slds combobox. I'm confused on slds site because it is hardcoded.

<aura:attribute name="myObject" type="List"/>
<aura:attribute name="myCustomSettings" type="MyCustomSettings__c[]"/>
<aura:iteration items="{!v.myCustomSettings}" var="cs" indexVar="index">
<div data-label="Object">
    <lightning:combobox type="text" aura:id="object"
                         name="object"
                         placeholder="-Select-"
                         value="{!v.myCustomSettings.Object__c}"
                         options="{!v.myObject}"
                         onchange="{!c.handleObjChange}"/>
</div>
</aura:iteration>
Help me. What's wrong with the code? I'm trying to get All the Fields of Object.
@AuraEnabled
    public static List<SelectOption> getAllObjectFields(String objectName) {
        List<SelectOption> fieldList = new List<SelectOption>();
        Map <String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap();
        for(Schema.SObjectField sfield : fieldMap.values()) {
            if (sfield.getDescribe().isAccessible()) {
                fieldList .add(new SelectOption(sfield.getDescribe().getName(),sfield.getDescribe().getLabel()));
            }
        }
        return fieldList ;
    }

 

Help me to upsert records to Custom Settings (List)

<aura:attribute name="myCustSettings" type="myCustomSettings__c[]"/>
<table class="slds-table slds-table--bordered slds-table--cell-buffer slds-table--striped slds-max-medium-table--stacked-horizontal"
	   role="grid">
	<thead>
		<tr>
			<th class="slds-is-sortable slds-cell-wrap" scope="col">
				Object
			</th>
			<th class="slds-is-sortable slds-cell-wrap" scope="col">
				Field
			</th>
			<th class="slds-is-sortable slds-cell-wrap" scope="col">
				Value
			</th>
			<th class="slds-is-sortable slds-cell-wrap" scope="col"></th>
		</tr>
	</thead>
	<tbody>
		<aura:iteration items="{!v.myCustSettings}" var="obj" indexVar="index">
			<tr class="slds-hint-parent">
				<td role="gridcell" data-label="Object">
					<div data-label="Object">
						<lightning:combobox type="text" aura:id="object"
											name="object"
											placeholder="-Select-"
											value="{!obj.Object__c}"
											options="{!v.objectList}"
											onchange="{!c.handleObjChange}"/>
					</div>
				</td>
				<td role="gridcell" data-label="Field">
					<div data-label="Field">
						<lightning:combobox aura:id="field"
											name="field"
											placeholder="-Select-"
											value="{!obj.Field__c}"
											options="{!v.fieldList}"
											onchange="{!c.handleFldChange}"/>
					</div>
				</td>
				<td role="gridcell" data-label="Value">
					<div data-label="Value">
						<lightning:input type="text" aura:id="value"
										 name="value"
										 placeholder="Type here"
										 placeholder="Type here"
										 value="{!obj.Value__c}"/>
					</div>
				</td>
				<td>
					<a onclick="{!c.removeRow}" data-record="{!index}">
						<lightning:icon iconName="utility:delete" size="small" alternativeText="Delete"/>
						<span class="slds-assistive-text">Delete</span>
					</a>
				</td>
			</tr>
		<!--/aura:iteration-->
	</tbody>
</table>
<div class="slds-grid" style="margin-bottom:15px;margin-top: 30px;text-align:center;">
	<lightning:button aura:id="add"
					  label="+ Add another row"
					  class="slds-m-top--medium"
					  variant="brand"
					  onclick="{!c.btnAdd}"/>
</div>

User-added image

Can someone help me how to populate a combobox with Objects?
Please, I’m new to Lightning.

<lightning:combobox type="text" aura:id="object"
                                                                name="object"
                                                                placeholder="-Select-"
                                                                options="{!v.objects}"
                                                                onchange="{!c.handleChange}"/>

Help me with my Save function, please?

Component

<aura:component controller="MyCustomSettingsController">
	<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
	<aura:attribute name="CustSettings" type="MyCustomSettings__c"/>
	<div class="divform">
		<form>
			<table>
				<tbody>
					<tr>
						<td>
							<span class="slds-text-heading--small">Client Key</span>
							<lightning:input type="text" aura:id="clientKey"
											 name="client"
											 value="{!v.CustSettings.Client_Key__c}"/>
						</td>
						<td>
							<span class="slds-text-heading--small">Secret Key</span>
							<lightning:input type="text" aura:id="secretKey"
											 name="secret"
											 value="{!v.CustSettings.Secret_Key__c}"/>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="slds-grid">
				<lightning:button aura:id="save"
								  label="Save"
								  class="slds-m-top--medium"
								  variant="brand"
								  onclick="{!c.btnSave}"/>
			</div>
		</form>
	</div>
</aura:component>

JS Controller

({
	doInit : function(component, event, helper) {
		var action = component.get("c.getCustomSettings");
		action.setCallback(this, function(response) {
			var state = response.getState();
			console.log(state);
			if (state === "SUCCESS") {
				var returnVal = response.getReturnValue();
				component.set("v.CustSettings", returnVal);
			}
		});
		$A.enqueueAction(action);
	},
 
	btnSave : function(component, event, helper) {
        var CustSettings = component.get("v.CustSettings");
		var action = component.get("c.saveCustSettings");
        action.setParams({"Cust_setting" : CustSettings});
        action.setCallback(this,function(response){
			var status = response.getState();
            if(status === "SUCCESS"){
				var msg = 'Changes saved!';
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    title	: "Success!",
                    mode	: 'pester',
                    duration: '3000',
                    message	: msg,
                    type	: 'success'
                });
                toastEvent.fire();
			}
		});
		$A.enqueueAction(action);
    }
})
Apex controller
public with sharing class MyCustomSettingsController {
	@AuraEnabled
    public static MyCustomSettings__c getCustomSettings() {
       MyCustomSettings__c query = [SELECT Id, Client_Key__c, Secret_Key__c
                FROM MyCustomSettings__c];
        return query;
    }
    @AuraEnabled
    public static void saveCustSettings(MyCustomSettings__c Cust_setting){
        
        MyCustomSettings__c Custsetting = new MyCustomSettings__c();
        Custsetting = Cust_setting;
        update Custsetting;
    }
}

 

Please help me. What's wrong with my Queueable Class?

public class FolderDisplayInfo implements Queueable, Database.AllowsCallouts {
    public List<Folder__c> fld; 
        public FolderDisplayInfo(List<Folder__c> folderList) {
                fld = folderList;
        }

        public void execute(QueueableContext context) {
            System.debug('Folders: ' + fld);
            Http http = new Http();
            HttpRequest httpReq = new HttpRequest();
            httpReq.setMethod('GET');
            httpReq.setHeader('Content-Type','application/json');
            httpReq.setEndpoint('<my endpoint>');
            HttpResponse res = http.send(httpReq);
            System.debug('Response: ' + res);
            if(res.getstatusCode() == 200 && res.getbody() != null){
                response = (List<cls_Response>)JSON.deserialize(res.getBody(), List<cls_Response>.class);
                System.debug('Body: ' + res.getBody());
            }
            //update folders here...

    }

    public class cls_Response {
        public String folderName {get;set;}
        public String recordID{get;set;}
        public String parentFolder{get;set;}
        public String bucketID{get;set;}
    }
    public List<cls_Response> response {get;set;}
}


Help me to get this response:

"00BO00000ABCD60EFG" : { //Record Id
	   "folders" : [ //Object
		   {
			"name" : "foldertest",
			"sfid" :  "00B0000ABC3ab",
			"parent" : "<FOLDER LOOKUP field>",
			"folderID" : "<BUCKET ID>",
			"RecordID" : "<Record ID>"
				
		   }	
		],
}
I have a File__c Object and Folder__c Object, I have to display the File Mapping from AWS callout in FileMapping__c field using Queueable Class, in this format:
{
   "00BO000001F3w11ABC" : {    //This is the Record ID
                "files" : [    //Object
		   {
			"name" : "File.txt",
			"SFFolderObject" : "<FOLDER LOOKUP>",
			"foldername" : "<FOLDER NAME>",
			"bucketid" : "<BUCKET ID>",
			"SalesforceID" : "<ID OF FILE RECORD>"
                        "Created Date" : "<Date>"
			
		   }
		]
   }
}

Please help. Thanks in advance!
Hi!

Please help me on how to query this. The scenario is:
If any if the child record has true value, then update parent record to true. But if all child record is false, then update parent record to false.
 
List<Campaign__c> campList = new List<Campaign__c>();
if (!parentIds.isEmpty()) {
	for (Campaign__c parentCamp : [SELECT Id, Do_Not_Notify_Subscriber__c FROM Campaign__c WHERE Id IN :parentIds]) {
		Campaign__c childCamp = childMatterMap.get(parentCamp.Id);
		parentCamp.Do_Not_Notify_Subscriber__c = childCamp.Do_Not_Notify_Subscriber__c;
		campList.add(parentCamp);
	}
	if (!campList.isEmpty()) {
		update campList;
	}
}

 
Can somebody help me to change my code using Map to avoid nested loops? I’m still confused with Maps.
public class UpdateParentCampaignHandler {
	public static Boolean isFirstRun = true;
	public static void updateParentCampaign(List<Campaign__c> scope) {
        if (isFirstRun) {
			isFirstRun = false;
			String RecordTypeIdMon = Schema.SObjectType.Campaign__c.getRecordTypeInfosByName().get('Monitoring').getRecordTypeId();
​
			Set<Id> parentIds = new Set<Id>();
			for (Campaign__c c : scope) {
				parentIds.add(c.Id);
			}
​
			Map<Id,Campaign__c> cMap = new Map<Id,Campaign__c>();
			if (!parentIds.isEmpty()) {
				List<Campaign__c> parentCamp = [SELECT Id, Do_Not_Notify_Subscriber__c FROM Campaign__c WHERE Id IN :parentIds];
​
				List<Campaign__c> allCamps = [SELECT Id, Parent_Campaign__c, RecordTypeId, Do_Not_Notify_Subscriber__c FROM Campaign__c WHERE Parent_Campaign__c IN :parentIds AND RecordTypeId =: RecordTypeIdMon];
				for (Campaign__c parentCampaign : parentCamp) {
					for (Campaign__c childCampaign : allCamps) {
						if (childCampaign.Do_Not_Notify_Subscriber__c = True) {
							parentCampaign.Do_Not_Notify_Subscriber__c = True;
							cMap.put(parentCampaign.Id,parentCampaign);
						}
					}
				}
				update cMap.values();
			}
		}
	}
}

 

Please help me, I can't see any reference on how to make test class for it..

public class ProcessController {
    public ProcessController(ApexPages.StandardSetController stdController) {}
    public PageReference runBatch() {
        MyUpdateBatch batch = new MyUpdateBatch ();
        Database.executeBatch(batch);
        
        return new ApexPages.Action('{!List}').invoke();
    }
}

Thanks!

I have created a trigger callout but I am getting this error..

Please help me get through..

Handler:

public class FileDeleteHandler {
    @future(callout=true)
    public void fileDeleteMethod(List<ContentDocument> scope) {
        List<CustomSettings__c> settings =  [SELECT BucketName__c, ClientKey__c, Region__c, SecretKey__c FROM CustomSettings__c LIMIT 1];

        String bucketName = '';
        String region = '';
        String clientKey = '';
        String secretKey = '';

        if(!settings.isEmpty()){
            bucketName = settings[0].BucketName__c;
            region = settings[0].Region__c;
            clientKey = settings[0].ClientKey__c;
            secretKey = settings[0].SecretKey__c;
            if(String.isBlank(bucketName)||String.isBlank(region)||
                String.isBlank(clientKey)||String.isBlank(secretKey)){
                return;
            }
        }
        Set<Id> fileIds = new Set<Id>();
        for (ContentDocument cv : scope) {
            fileIds.add(cv.Id);
        }

        List<Custom_Object__c> coList = [SELECT Id, Name, Path__c, File_ID__c, File_Saved__c FROM Custom_Object__c WHERE File_ID__c =: fileIds];

        if (!coList.isEmpty()) {
            if (coList[0].File_Saved__c== true) {
                //make callout
                //delete file from AWS
                List<ContentVersion> cvs = [SELECT Title, ContentDocumentId, FileExtension, FileType, VersionData FROM ContentVersion WHERE ContentDocumentId IN :fileIds];

                String path = coList[0].Path__c; //Salesforce/ObjectName/RecordId/Filename

                String formattedDateString = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z');
                Blob data = cvs[0].VersionData; // System.ListException: List index out of bounds: 0

                HttpRequest req = new HttpRequest();
                Http http = new Http();

                req.setHeader('Content-Type', cvs[0].FileExtension);
                req.setMethod('DELETE');
                req.setHeader('Host','s3.amazonaws.com');
                req.setEndpoint('https://s3.amazonaws.com'+'/'+bucketName+'/'+path);
                req.setHeader('Date',formattedDateString);
                req.setHeader('Authorization', createAuthHeader('DELETE', cvs[0].FileExtension, path, formattedDateString, bucketName, clientKey, secretKey));
                req.setBodyAsBlob(data);
                req.setHeader('Content-Length', String.valueOf((EncodingUtil.base64Encode(data)).length()));

                try{
                    HTTPResponse res = http.send(req);

                    System.debug('MYDEBUG: ' + cvs[0].Title + ' RESPONSE STRING: ' + res.toString());
                    System.debug('MYDEBUG: ' + cvs[0].Title + ' RESPONSE STATUS: '+res.getStatus());
                    System.debug('MYDEBUG: ' + cvs[0].Title + ' STATUS_CODE:'+res.getStatusCode());

                } catch(System.CalloutException e) {
                    System.debug('AWS Callout Exception on ' + cvs[0].Title + 'ERROR: ' + e.getMessage());
                }
            } else if (coList[0].File_Saved__c== false) {
                 delete coList;
            }
        }
    }

    public string createAuthHeader(String method,String contentType,String filename,String formattedDateString,String bucket,String client,String secret){
        string auth;
        String stringToSign = method+'\n\n'+contentType+'\n'+formattedDateString+'\n/'+bucket+'/'+filename;
        Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof(secret));
        String sig = EncodingUtil.base64Encode(mac);
        auth = 'AWS' + ' ' + client + ':' + sig;
        return auth;
    }
}


Trigger:

trigger DocumentTrigger on ContentDocument (before delete) {
    if (Trigger.isBefore) {
        if (Trigger.isDelete) {
            FileDeleteHandler handler = new FileDeleteHandler();
            handler.fileDeleteMethod(Trigger.old);
        }
    }
}

Hi! I am trying to upload an Atttachments based on the selection and criteria from Lightning Component that will be saved to Custom Setting.

For example, the criteria is Opportunity - Stage - Closed Won, I need to query to get all attachments from Closed Won Opportunity and upload them to AWS.

But I don't know how to do it dynamically, please help me.

User-added image

global class UploadAttachments implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id, Objects__c, Fields__c, Field_Value__c FROM ForUploadCustomSettings__c';
        return Database.getQueryLocator(query);
    }

       global void execute(Database.BatchableContext BC, List<sObject> scope) {
        String formattedDateString = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z');   
        String host = 's3.amazonaws.com';
        String method = 'PUT';
        
        HttpRequest req = new HttpRequest();
        Http http = new Http();
        
        Set<Id> Ids = new Set<Id>();
        for (sObject so : scope) {
            Ids.add(so.Id);
        }
        List<Attachment> att = [SELECT Id, Name, Body, ContentType FROM Attachment WHERE ParentId IN :Ids];
        
        List<AWScredentialsSettings__c> values = [SELECT Id, ClientKey__c, SecretKey__c, BucketName__c FROM AWScredentialsSettings__c LIMIT 1];
        if (!att.isEmpty() && !values.isEmpty()) {
            String bucketname = values[0].BucketName__c;
            String key = values[0].ClientKey__c;
            String secret = values[0].SecretKey__c;
            String attachmentBody = EncodingUtil.base64Encode(att[0].Body);
            String filename = att[0].Name;
            
            req.setMethod(method);
            req.setEndpoint('https://' + host + '/' + bucketname + '/' + filename); // The file should be uploaded to this path in AWS -- ObjectName/Salesforce Id/Secret Files/filename
            req.setHeader('Content-Length', String.valueOf(attachmentBody.length()));
            req.setHeader('Content-Encoding', 'UTF-8');
            req.setHeader('Content-type', att[0].ContentType);
            req.setHeader('Connection', 'keep-alive');
            req.setHeader('Date', formattedDateString);
            req.setHeader('ACL', 'public-read');
            req.setBody(attachmentBody);
            
            String stringToSign = method+'\n\n\n'+ att[0].ContentType + '\n' + formattedDateString +'\n/'+ bucketname +'/' + filename;
            Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof(secret));
            String signed  = EncodingUtil.base64Encode(mac);
            String authHeader = 'AWS' + ' ' + secret + ':' + signed;
            req.setHeader('Authorization',authHeader);
            
            HTTPResponse res = http.send(req);
            System.debug('*Resp:' + String.ValueOF(res.getBody()));
            System.debug('RESPONSE STRING: ' + res.toString());
            System.debug('RESPONSE STATUS: ' + res.getStatus());
            System.debug('STATUS_CODE: ' + res.getStatusCode());
        }
    }
    
    global void finish(Database.BatchableContext BC) {
        
    }
}

I'm doing an upload attachment to AWS, but I'm getting this error -- 'You have uncommitted work pending. Please commit or rollback before calling out'
How do I fix this?

@AuraEnabled
    public static void savePDupcsSettings(ForUploadCustomSettings__c upcsSet, String recId){
        ForUploadCustomSettings__c upcs = new ForUploadCustomSettings__c();
        upcs = upcsSet;
        if (upcs.Objects__c != null) {
			if (recordId != null) {
                upcs.Name = upcs.Objects__c +'-'+ upcs.Fields__c +'-'+ upcs.Value__c;
			    update upcs;
            } else {
                ForUploadCustomSettings__c newVal = new ForUploadCustomSettings__c();
                newVal.Name = upcs.Objects__c +'-'+ upcs.Fields__c +'-'+ upcs.Value__c;
                newVal.Objects__c = upcs.Objects__c;
                newVal.Fields__c = upcs.Fields__c;
                newVal.Value__c = upcs.Value__c;
                insert newVal;
            }
        }
        
        String stage = 'Closed Won';
        ForUploadCustomSettings__c csList = [SELECT Id, Id, Objects__c, Fields__c, Value__c 
                                                              FROM ForUploadCustomSettings__c 
                                                              WHERE Value__c = :stage LIMIT 1];
        if (csList != null) {
            Set<Id> Ids = new Set<Id>();
			for (Opportunity opp : [SELECT Id, Name FROM Opportunity WHERE IsClosed = true AND IsWon = true]) {
				Ids.add(opp.Id);
			}

			String formattedDateString = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z');   
			String host = 's3.amazonaws.com/';
			String method = 'PUT';
			
			HttpRequest req = new HttpRequest();
			Http http = new Http();

			List<Attachment> att = [SELECT Id, Name, Body, ContentType FROM Attachment WHERE ParentId IN :Ids];
			List<AWScredentialsSettings__c> creds = [SELECT Id, ClientKey__c, SecretKey__c, BucketName__c FROM AWScredentialsSettings__c LIMIT 1];
			if (!att.isEmpty() && !creds.isEmpty()) {
				String bucketname = creds[0].BucketName__c;
				String key = creds[0].ClientKey__c;
				String secret = creds[0].SecretKey__c;
				String attachmentBody = EncodingUtil.base64Encode(att[0].Body);
				String filename = att[0].Name;
				
				req.setMethod(method);
				req.setEndpoint('https://' + host + bucketname + '/' + filename); // The file should be uploaded to this path in AWS -- Opportunity/Salesforce Id/Secret Files/filename
				req.setHeader('Content-Length', String.valueOf(attachmentBody.length()));
				req.setHeader('Content-Encoding', 'UTF-8');
				req.setHeader('Content-type', att[0].ContentType);
				req.setHeader('Connection', 'keep-alive');
				req.setHeader('Date', formattedDateString);
				req.setHeader('ACL', 'public-read');
				req.setBody(attachmentBody);
				
				String stringToSign = method+'\n\n\n'+ att[0].ContentType + '\n' + formattedDateString +'\n/'+ bucketname +'/' + filename;
				Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof(secret));
				String signed  = EncodingUtil.base64Encode(mac);
				String authHeader = 'AWS' + ' ' + secret + ':' + signed;
				req.setHeader('Authorization',authHeader);
			}
			
			HTTPResponse res = http.send(req);
			System.debug('*Resp:' + String.ValueOF(res.getBody()));
			System.debug('RESPONSE STRING: ' + res.toString());
			System.debug('RESPONSE STATUS: ' + res.getStatus());
			System.debug('STATUS_CODE: ' + res.getStatusCode());
        }
    }

Help me to code it on APEX, the records should be visible to the user if the current user is the CreatedBy.

public class MyFilesSharingHandler {
	public void shareRecord(List<CustomObject__c> scope) {
		if (Trigger.isInsert) {
			
			List<CustomObject__Share> shareLst = new List<CustomObject__Share>();
			for (CustomObject__c c : scope) {
				CustomObject__Share share = new CustomObject__Share();
				share.AccessLevel = 'Read';
				share.ParentId = c.Id;
				share.UserOrGroupId = c.CreatedById;
				shareLst.add(share);
			}
			if (!shareLst.isEmpty()) {
				insert shareLst;
			}
		}
	}
}

How can I get all Objects except the System Objects in SF?

Here's my code. But I need to revise it to get only the needed Objects.

@AuraEnabled
	public static List<SelectOption> fetchAllObjects(){
        Set<String> listObjs = new Set<String>();
        for(MyCustomSettings__c cs : [Select Id, Objects__c From MyCustomSettings__c]){
            listObjs.add(cs.Objects__c);
        }

		List<SelectOption> objList = new List<SelectOption>();
        Set<String> csObjNames = new Set<String>();
        Map<String, String> mapName = new Map<String, String>();
        Map<String, String> mapLabel = new Map<String, String>();
		for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values()){
            System.debug(objTyp.getDescribe().getLabel());

            if ( objTyp.getDescribe().isCreateable()) {
                csObjNames.add(objTyp.getDescribe().getLabel());
                    mapName.put(objTyp.getDescribe().getLabel(), objTyp.getDescribe().getName());
                    mapLabel.put(objTyp.getDescribe().getName(), objTyp.getDescribe().getLabel());
            }
		}

        List<String> objNamesCast = new List<String>();
        objNamesCast.addAll(csObjNames);
        objNamesCast.sort();

        for(String s : objNamesCast){
            String objTypeName = mapName.get(s);
            String objTypeLabel = mapLabel.get(objTypeName);
            if(!listObjs.contains(objTypeName)) objList.add(new SelectOption(objTypeName,objTypeLabel));
            else objList.add(new SelectOption(objTypeName,objTypeLabel, true));
        }

		return objList;   
	}

Help me on how to code the Test Connection to AWS. Please.

and should I put it on the controller?
User-added image

Help me on how to set the Name based on selected Object (from dropdown) on upsert.

I'm using Custom Settings.

@AuraEnabled
    public static void saveCustomSettings(MyCustomSettings__c cs){
        MyCustomSettings__c cust = new MyCustomSettings__c();
        cust = cs;
        upsert cust;
    }

User-added image

I converted my lightning:combobox into slds combobox to use data attributes, now, dropdown is not showing. Please help me.

And also, how to put the selected item into input textbox?

<aura:attribute name="myObject" type="List"/>
<aura:attribute name="myCustomSettings" type="MyCustomSettings__c[]"/>

<aura:iteration items="{!v.myCustomSettings}" var="obj" indexVar="index">
	<tr class="slds-hint-parent">
		<td role="gridcell" data-label="Object">
			<div class="slds-form-element slds-form-element__control">
				<div class="slds-combobox_container">
					<div aura:id="open" class="slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click" aria-expanded="true" aria-haspopup="listbox" role="combobox">
						<div class="slds-combobox__form-element slds-input-has-icon slds-input-has-icon_right" role="none">
							<input type="text" class="cellField slds-input slds-combobox__input" role="textbox" autocomplete="off" readonly="true"
									aura:id="allObjects"
									placeholder="-Select-"
									data-id="{!'index-' + index + 1}"
									data-value="{!index + 1}"
									value="{!obj.Object__c}"
									onfocus="{!focus}"/>
							<span class="slds-icon_container slds-icon-utility-down slds-input__icon slds-input__icon_right">
								<lightning:icon class="slds-icon slds-icon-text-default slds-icon_xx-small" iconName="utility:down" size="xx-small" variant="brand" />
							</span>
						</div>
						<div aura:id="options" class="slds-dropdown slds-dropdown_length-5 slds-dropdown_fluid" role="listbox">
							<ul class="slds-listbox slds-listbox_vertical" role="presentation">
								<aura:iteration items="{!v.myObject}" var="myLst" indexVar="i">
									<li aura:id="selectObj" role="presentation" class="slds-listbox__item" onclick="{!c.itemSelected}" data-id="{!'index-' + i + 1}" data-value="{!i + 1}">
										<div id="{!i + 1 + '-item'}" aura:id="is-selected" class="slds-media slds-listbox__option slds-listbox__option_plain slds-media_small" role="option">
											<span class="slds-media__figure slds-listbox__option-icon"></span>
											<span class="slds-media__body">
												<span class="slds-truncate" title="{!myLst.label}">{!myLst.label}</span>
											</span>
										</div>
									</li>
								</aura:iteration>
							</ul>
						</div>
					</div>
				</div>
			</div>
		</td>
	<tr>
<aura:iteration/>
 
focus : function (component, event, helper) {
	var open = component.find("open");
	$A.util.toggleClass(open, 'slds-is-open');
},
 
itemSelected : function(component, event, helper) {
        var selectedItem = event.currentTarget;
        var id = selectedItem.dataset.id;
        var elements = component.find('selectObj');
        for (var i = 0; i < elements.length; i++) {
            var val = elements[i].getElement().getAttribute('data-id');
            if(val == id) {
                console.log(val);
                //put the selected item to input textbox
            }
        }
    },
Help me. What's wrong with the code? I'm trying to get All the Fields of Object.
@AuraEnabled
    public static List<SelectOption> getAllObjectFields(String objectName) {
        List<SelectOption> fieldList = new List<SelectOption>();
        Map <String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap();
        for(Schema.SObjectField sfield : fieldMap.values()) {
            if (sfield.getDescribe().isAccessible()) {
                fieldList .add(new SelectOption(sfield.getDescribe().getName(),sfield.getDescribe().getLabel()));
            }
        }
        return fieldList ;
    }

 

Help me to upsert records to Custom Settings (List)

<aura:attribute name="myCustSettings" type="myCustomSettings__c[]"/>
<table class="slds-table slds-table--bordered slds-table--cell-buffer slds-table--striped slds-max-medium-table--stacked-horizontal"
	   role="grid">
	<thead>
		<tr>
			<th class="slds-is-sortable slds-cell-wrap" scope="col">
				Object
			</th>
			<th class="slds-is-sortable slds-cell-wrap" scope="col">
				Field
			</th>
			<th class="slds-is-sortable slds-cell-wrap" scope="col">
				Value
			</th>
			<th class="slds-is-sortable slds-cell-wrap" scope="col"></th>
		</tr>
	</thead>
	<tbody>
		<aura:iteration items="{!v.myCustSettings}" var="obj" indexVar="index">
			<tr class="slds-hint-parent">
				<td role="gridcell" data-label="Object">
					<div data-label="Object">
						<lightning:combobox type="text" aura:id="object"
											name="object"
											placeholder="-Select-"
											value="{!obj.Object__c}"
											options="{!v.objectList}"
											onchange="{!c.handleObjChange}"/>
					</div>
				</td>
				<td role="gridcell" data-label="Field">
					<div data-label="Field">
						<lightning:combobox aura:id="field"
											name="field"
											placeholder="-Select-"
											value="{!obj.Field__c}"
											options="{!v.fieldList}"
											onchange="{!c.handleFldChange}"/>
					</div>
				</td>
				<td role="gridcell" data-label="Value">
					<div data-label="Value">
						<lightning:input type="text" aura:id="value"
										 name="value"
										 placeholder="Type here"
										 placeholder="Type here"
										 value="{!obj.Value__c}"/>
					</div>
				</td>
				<td>
					<a onclick="{!c.removeRow}" data-record="{!index}">
						<lightning:icon iconName="utility:delete" size="small" alternativeText="Delete"/>
						<span class="slds-assistive-text">Delete</span>
					</a>
				</td>
			</tr>
		<!--/aura:iteration-->
	</tbody>
</table>
<div class="slds-grid" style="margin-bottom:15px;margin-top: 30px;text-align:center;">
	<lightning:button aura:id="add"
					  label="+ Add another row"
					  class="slds-m-top--medium"
					  variant="brand"
					  onclick="{!c.btnAdd}"/>
</div>

User-added image

Help me with my Save function, please?

Component

<aura:component controller="MyCustomSettingsController">
	<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
	<aura:attribute name="CustSettings" type="MyCustomSettings__c"/>
	<div class="divform">
		<form>
			<table>
				<tbody>
					<tr>
						<td>
							<span class="slds-text-heading--small">Client Key</span>
							<lightning:input type="text" aura:id="clientKey"
											 name="client"
											 value="{!v.CustSettings.Client_Key__c}"/>
						</td>
						<td>
							<span class="slds-text-heading--small">Secret Key</span>
							<lightning:input type="text" aura:id="secretKey"
											 name="secret"
											 value="{!v.CustSettings.Secret_Key__c}"/>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="slds-grid">
				<lightning:button aura:id="save"
								  label="Save"
								  class="slds-m-top--medium"
								  variant="brand"
								  onclick="{!c.btnSave}"/>
			</div>
		</form>
	</div>
</aura:component>

JS Controller

({
	doInit : function(component, event, helper) {
		var action = component.get("c.getCustomSettings");
		action.setCallback(this, function(response) {
			var state = response.getState();
			console.log(state);
			if (state === "SUCCESS") {
				var returnVal = response.getReturnValue();
				component.set("v.CustSettings", returnVal);
			}
		});
		$A.enqueueAction(action);
	},
 
	btnSave : function(component, event, helper) {
        var CustSettings = component.get("v.CustSettings");
		var action = component.get("c.saveCustSettings");
        action.setParams({"Cust_setting" : CustSettings});
        action.setCallback(this,function(response){
			var status = response.getState();
            if(status === "SUCCESS"){
				var msg = 'Changes saved!';
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    title	: "Success!",
                    mode	: 'pester',
                    duration: '3000',
                    message	: msg,
                    type	: 'success'
                });
                toastEvent.fire();
			}
		});
		$A.enqueueAction(action);
    }
})
Apex controller
public with sharing class MyCustomSettingsController {
	@AuraEnabled
    public static MyCustomSettings__c getCustomSettings() {
       MyCustomSettings__c query = [SELECT Id, Client_Key__c, Secret_Key__c
                FROM MyCustomSettings__c];
        return query;
    }
    @AuraEnabled
    public static void saveCustSettings(MyCustomSettings__c Cust_setting){
        
        MyCustomSettings__c Custsetting = new MyCustomSettings__c();
        Custsetting = Cust_setting;
        update Custsetting;
    }
}

 

Please help me. What's wrong with my Queueable Class?

public class FolderDisplayInfo implements Queueable, Database.AllowsCallouts {
    public List<Folder__c> fld; 
        public FolderDisplayInfo(List<Folder__c> folderList) {
                fld = folderList;
        }

        public void execute(QueueableContext context) {
            System.debug('Folders: ' + fld);
            Http http = new Http();
            HttpRequest httpReq = new HttpRequest();
            httpReq.setMethod('GET');
            httpReq.setHeader('Content-Type','application/json');
            httpReq.setEndpoint('<my endpoint>');
            HttpResponse res = http.send(httpReq);
            System.debug('Response: ' + res);
            if(res.getstatusCode() == 200 && res.getbody() != null){
                response = (List<cls_Response>)JSON.deserialize(res.getBody(), List<cls_Response>.class);
                System.debug('Body: ' + res.getBody());
            }
            //update folders here...

    }

    public class cls_Response {
        public String folderName {get;set;}
        public String recordID{get;set;}
        public String parentFolder{get;set;}
        public String bucketID{get;set;}
    }
    public List<cls_Response> response {get;set;}
}


Help me to get this response:

"00BO00000ABCD60EFG" : { //Record Id
	   "folders" : [ //Object
		   {
			"name" : "foldertest",
			"sfid" :  "00B0000ABC3ab",
			"parent" : "<FOLDER LOOKUP field>",
			"folderID" : "<BUCKET ID>",
			"RecordID" : "<Record ID>"
				
		   }	
		],
}