How to reference a custom metadata in Aura component? - salesforce

I have an Aura component that calls an external CSS thru <ltng:require> tags. I need to save the URLs in a custom metadata or maybe custom label in Salesforce rather than hardcoded URLs in the .cmp
Snippet of .CMP
<ltng:require scripts="{!join(',',
'https://simpleui-test-au.vixverify.com/df/javascripts/greenidConfig.js',
'https://simpleui-test-au.vixverify.com/df/javascripts/greenidui.min.js')}"
afterScriptsLoaded="{! c.onLoadScript }"/>
<ltng:require styles="https://simpleui-test-au.vixverify.com/df/assets/stylesheets/greenid-mobile.css"/> ```

H newbiedev,
You can access the value of a Custom Label in your Aura Component markup by using the following syntax inside an expression: (https://developer.salesforce.com/docs/atlas.en-us.232.0.lightning.meta/lightning/labels_value_provider_platform.htm)
$Label.c.labelName
So you could use it in your require tag as follows once the Custom Labels are created:
<ltng:require scripts="{!join(',',
$Label.c.MyLabel1,
$Label.c.MyLabel2)}"
afterScriptsLoaded="{! c.onLoadScript }"/>
<ltng:require styles="{!$Label.c.MyLabel3}"/> ```

Related

how to use same component in multiple place with some logic in angularjs

Well I have a directive/component/controller i.e <app-form></app-form> I am using this html page into multiple place but I want to to remove some specific field from different in place component how can I do in angularjs
In reactjs we can do like this <app-form disableField></app-form> and if disabledField then disable particular field other wise nothing to do
Again for better understanding for example we have one form having name, email and dob same form is using multiple place but at one place we are not interesting to display dob how can we disable or remove from specific place ?
please guide
You have to use bindings in your component declaration. something on the lines of:
angular.module('app').component('appForm', {
controller: 'AppFormCtrl',
templateUrl: 'app-form.html',
bindings: {
disableField: "<", // use '<' to generate input on the component
}
});
then in your app-form.html you can access the input var using the $ctrl object:
<form>
<input ng-if="$ctrl.disableField == true" type="text"/>
</form>
And the you can pass whatever value you want in the scope of your root view:
<div>
<!-- displays the form input according to the passed property's value -->
<app-form disable-field="isFieldEnabled"></app-form>
<!-- displays the form input -->
<app-form disable-field="true"></app-form>
<!-- does NOT display the form input -->
<app-form disable-field="false"></app-form>
<!-- does NOT display the form input, as disableField is evaluated an NULL in the component instance -->
<app-form></app-form>
</div>
isFieldEnabled is the property in your root controller $scope that will control the enabling / disabling of the input field in your component, but you can simply pass true or false if no logic is used.
You can attach whatever property you want, it doesn't have to be a boolean (but in this case I think it makes sense).
Also, notice that when defining the binded property 'disableField' in the Javascript environment, we use camelCase. The same property will be defined in the view / html environment using kebab-case.
You can also check the following answer to see how to generate output from the component instances:
Angular.js, how to pass value from one component to any other

Salesforce apex:inputField

I am new to salesforce and Apex . In apex:input field i have use html-maxlength it is working fine but in IE11 it is showing message on submit button .
Please suggest how can i find thi css Class or how can i change it style
<apex:inputField id="phonePrimary" value="{!primaryContact.Phone_Number__c}" onKeyDown="isNumberOnlyForPrimary(event);" onKeyUp="formatPrimaryPhoneNumber(event);" styleClass="form-control phonePrimary" html-maxlength="10" />
Why do u use the max-length attribute? An apex:inputField represents the same "attributes" like the corpesponding salesforce field. So when your field in your object is e.g. Text(10) than you automatically can store only up to 10 chars.

Angular Schema Form HTML Attributes?

I've been looking over the Angular Schema Form documentation to be able to apply attributes to the elements generated at: https://github.com/Textalk/angular-schema-form/blob/development/docs/index.md
Have been looking up and down and have found nothing. I see through defining the schema that you can define custom HTML classes:
htmlClass: "street foobar", // CSS Class(es) to be added to the container div
fieldHtmlClass: "street" // CSS Class(es) to be added to field input (or similar)
labelHtmlClass: "street" // CSS Class(es) to be added to the label of the field (or similar)
But, haven't been able to find where I can apply attributes like the data attribute or an attribute specific to the element itself. Any resources in regards to this type of basic functionality you'd expect from form generation?
Any ideas?
Thanks!
I do not think this is possible to do purely through json schema definitions, you would have to extend Schema Form and provide your own HTML template with your custom attributes. I've had this problem myself and have had to do the very same.
I'm sure you've seen this but here's the docs on extending:
https://github.com/json-schema-form/angular-schema-form/blob/master/docs/extending.md

Salesforce : Adding Component to Standard Page Layout

I have created a component which is related to display standard state and country picklists on custom objects.
I am having trouble to add that component to standard VF page.
Is there a way I can add a component to the VF page?
<apex:page standardController="Account">
This is my <i>page</i>. <br/>
<c:myComponent/>
</apex:page>
Replace <c:myComponent/> with <YourNameSpace:myComponent/> if component is defined in different namespace. See Docs

Add a custom link/button to a visualforce page?

I have a custom link on the opportunity object which points to an external site. Is it possible to add this custom link to a visualforce page?
The solution I came up with was to copy the url salesforce creates for this custom link, and paste it in the page. It looks something like this:
my custom link
This works fine, however, it won't work once it's in a managed package installed on other servers because the lid param will be different (the custom link id). Is there a solution for this?
Have you thought about putting the URL of the link in a field on the opportunity object and then creating an output link on your VF page?
Paul
Look under $Action. Buttons and links are available via that global variable. For example $Action.Opportunity.CustomLink
To build off the answer from danieljimenez, the $Action global variable provides access to the button/link objects. From there you need to use the URLFOR function to get it into a usable form. Then you can either put it into the action param of a command button, or use it as you'd like anywhere else in your markup.
<apex:commandButton action="{!URLFOR($Action.My_Obj__c.My_custom_link)}" value="My custom button"/>
or
My link
create New Contact (Salesforce button target _blank)
<apex:commandLink target="_blank"
styleClass="btn"
style="text-decoration:none;padding:4px;"
action="{!URLFOR($Action.Contact.NewContact)}"
value="Create New Contact" />

Resources