Salesforce Asked by Sankhadeep Biswas on November 3, 2020
I’m new to lightning and never used carousel component. My requirement is to display different images by querying from object level and upon clicking on the picture it will call another component and pass a value which will be used as an attribute of the 2nd component.Kindly help.. please find below component ..
public class imagecheckcontact{
@AuraEnabled
public static List<contact> getcons(){
return [Select Id,name,sankha__image__c from contact where id in ('00328000014LZcM', '00328000014LZjA')];
}
}
<lightning:carousel >
<aura:iteration items="{!v.conct}" var="con">
<lightning:carouselImage width="500px" height="600px" src = "{!con.sankha__image__c}"
description = "First card description." onclick="{c.navigate}" header = "{!con.name}"
>
</lightning:carouselImage>
</aura:iteration>
</lightning:carousel>
JS
({
doInit : function(component, event, helper) {
var action = component.get("c.getcons");
action.setCallback(this, function(response){
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
var retrunRes = response.getReturnValue();
component.set("v.conct" ,retrunRes );
}
});
$A.enqueueAction(action);
},
navigate:function(component, event, helper) {
var evt = $A.get("e.force:navigateToComponent");
evt.setParams({
componentDef : "c:Helloworld",
componentAttributes: {
contactName : component.get("v.contact.Name")
}
});
evt.fire();
}
})
You can not display images in carousel which are type of Rich text area. You have to break the image URL to required format and pass to src tag in lightning carousel.
src tag in lighting carousal accepts only this format /sfsites/c/servlet/rtaImage?eid=a0B9E000004VP64&feoid=00N9E0000055I7z&refid=0EM9E000000HpxY
find below example how can you break URL to required format from apex send it in this format.
NOte: Even I am trying to capture ID from onclick of image. but no sucess please help me
Seminar_Catalog__c camp = [SELECT Id, Image__c FROM Seminar_Catalog__c where id ='a079E00000ALyU1' LIMIT 1];
System.debug('Rich field:');
System.debug(camp.Image__c);
String firstSubString = camp.Image__c.substringBetween('<img', 'img>');
System.debug('First substring: ' + firstSubString);
String secondSubString = firstSubString.substringBetween('src="', '"');
System.debug('Second substring: ' + secondSubString);
String link = secondSubString.replace('amp;', '');
System.debug('Link: ' + link);
Answered by Rajesh P on November 3, 2020
1 Asked on November 5, 2021 by harshit-verma
1 Asked on November 5, 2021 by pranay-jaiswal
1 Asked on November 5, 2021 by sfdc_beginner
1 Asked on November 5, 2021
1 Asked on November 5, 2021
0 Asked on November 5, 2021 by leonardo-p-macedo
entitlement process salesforcedx salesforcedx cli sfdx plugin versioning
0 Asked on November 5, 2021 by sanket-kumar
0 Asked on November 5, 2021 by szosteczka
1 Asked on November 5, 2021 by ben2pop
1 Asked on November 5, 2021 by will-bowditch
1 Asked on October 4, 2021
2 Asked on October 4, 2021
0 Asked on October 4, 2021
1 Asked on October 4, 2021 by aurlien-laval
2 Asked on October 4, 2021 by sfdcbat
javascript lightning recordeditform lightning web components
1 Asked on October 4, 2021 by sfdc
lightning lightning aura components lightning design system lightning experience
Get help from others!
Recent Answers
© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP