AnswerBun.com

lightning:carousel error

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 ..

apex

public class imagecheckcontact{

@AuraEnabled 
public static List<contact> getcons(){
    return [Select Id,name,sankha__image__c from contact where id in ('00328000014LZcM', '00328000014LZjA')];
}

}

component

<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();
    }

})

One Answer

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

Add your own answers!

Related Questions

How to get data from dataevents using REST API

1  Asked on January 28, 2021 by user87438

   

Scroll down is not working report

1  Asked on January 26, 2021 by dearbrother

   

Wave Analytics — containerId/versionId of a dataset

2  Asked on January 26, 2021 by sitansu-pradhan

 

Connected App packaging

0  Asked on January 25, 2021 by user85767

 

AMPSCRIPT: Hide HTML Form after clicking on Submit Button

1  Asked on January 25, 2021 by valarie-simmons

     

Field update before or after creation of an issue

0  Asked on January 23, 2021 by hermann-our

     

How to check multiple occurrences in the child records?

1  Asked on January 21, 2021 by mauforsalesforce

       

Live Agent Credit Card Question – Two Part

1  Asked on January 21, 2021 by stephanie-dorman

 

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP