MetaData Api With Wrapper class - salesforce

How can I write a wrapper class for copy custom Contact fields to a custom object called Consultact__c?

Related

Wagtail Fields / Data for Every Page?

In wagtail, is there a good way to add the same fields to every page model? I am thinking about things like SEO data fields and search meta information that virtually every page would like to implement. I cannot seem to find a good way to do this using Wagtail.
You can use abstract classes (you then inherit from this base class instead of Wagtail's Page) or mixins (you then inherit from both the mixin and Wagtail's Page) for that.
# Example with Abstract class
class BasePage(wagtail.wagtailcore.models.Page):
seo_image = models.ForeignKey(...)
class Meta:
abstract = True
class MyPage(BasePage):
pass
# Example with mixins
class SEOMixin(django.db.models.Model):
seo_image = models.ForeignKey(...)
class Meta:
abstract = True
class MyPage(SEOMixin, wagtail.wagtailcore.models.Page):
pass
Using abstract classes is probably the simplest, but all your pages will always inherit all the fields defined on the base class.
Using mixins on the other hand is more flexible as you can have multiple mixins (SEOMixin, ThumbnailMixin, etc) and combine them depending on your need.

Reactjs inheritance

I'm very new to React and I'm trying to make a simple application that renders html controls.
I want to have an API that return array of json objects contains properties that determine the type and the value of each control like id, type, value ... etc.
Let's say that I have some controls like Input and Button.
What I'm thinking of is Creating a base class named HtmlControl that extends React.Component and other html controls should extend from the HtmlControl and finally a class for rendering these controls.
How can I be able to render the controls that extends only HtmlControl class ?
That would not be a good choice as react says you should not focus inheritance rather focus on containment or composition.
React has a powerful composition model, and we recommend using composition instead of inheritance to reuse code between components.
and
At Facebook, we use React in thousands of components, and we haven't found any use cases where we would recommend creating component inheritance hierarchies.
Props and composition give you all the flexibility you need to customize a component's look and behavior in an explicit and safe way. Remember that components may accept arbitrary props, including primitive values, React elements, or functions.
Please Visit this link to learn more.
You can create separate classes for each of the components or elements and combine them in one class like this:
import Button from './Button'
import Radio from './Radio'
import TextInput from './TextInput'
class HtmlComponent{
// note: we don't need to extend it from React.Component
// we will some function to render them.
renderTextInput() { <TextInput /> }
renderRadio() { <Radio /> }
}
// you can now use below code:
const hC = new HtmlComponent();
hC.renderTextInput();
Note Again this is not a nice idea to do but you can achieve your goal.

Use dependency in base class without having to pass this dependency from inheriting class [duplicate]

This question already has answers here:
How to extend a component with dependency injection?
(4 answers)
Closed 6 years ago.
In my quest to learn Angular2, i came across the following situation:
1 base class, which uses the angular2/http dependency
1 inheriting class which extends the base class
How can I inject the angular2/http dependency in the base class's constructor, without having to pass http as a parameter when instantiating the inheriting class.
I don't use http in the inheriting class, so I don't want to see it there!
For example
// base class
class CRUDService {
// http is used in this service, so I need to inject it here
constructor(#Inject(Http) http) {}
findAll() {
return this.http.get('http://some.api.com/api/some-model');
}
}
// inheriting class
class ThingService extends CRUDService {
constructor() {
// because we extend the base class, we need to call super()
// this will fail since it expects http as a parameter
// BUT i don't use http in this class, I don't want to inject it here
super();
}
}
Ideally, I would just create a new http instance in the base class and use that like so let http = new Http();, but that obviously doesn't work.
That's not supported. If you want inject something you have to list it in the constructor of the sub-class and if you want to pass it to the super-class you can by using super(someDependency). There is no way around.
That's not an Angular limitation but a language limitation that is quite common among typed classes.

Get a Service context from a normal class

I have three classes:
MyPlugin extends OtherPluginClass extends Service
MyService extends AccesibilityService
LoggerClass implements BaseLoggerClass
MyService starts when the user authorizes it in Accessibility settings. MyPlugin is started and controlled by a different application (tho' I have access to its source code).
The problem is the LoggerClass is coordinated by MyService, however LoggerClass needs the context of MyPlugin to perform some operations.
I've tried to create a static sharedContext variable in MyPlugin and populate it in the onCreate method, but LoggerClass always sees sharedContext as null.
What would be the best way for LoggerClass to access MyPlugin's context?

Components issue on extending custom AppController class

I have a custom structure in my CakePHP app which goes like this:
class AppController extends Controller // default
class ExtendedAppController extends AppController
class ChildController extends ExtendedAppController
The components I declare in ExtendedAppController get erased when I declare components in a ChildController class. I guess I will have this same problem with helpers also. How do I merge the arrays to avoid this?
Cake merges the current controller's variables with only ONE parent class which by default is set in the variable $_mergeParent = 'AppController'; in the core Controller class.
You can override this variable in your ChildController by defining:
class ChildController extends ExtendedAppController {
protected $_mergeParent = 'ExtendedAppController';
}
However, this will ignore all the helpers and components defined in AppController, so copy the components and helpers from your AppController to your ExtendedAppController. This should answer your question I guess as you will be able to use ExtendedAppController's components from your ChildController and other controllers extending AppController will use AppController's components.
It is the way the Controller::_mergeControllerVars() method is written in the core. This is precisely why the book says:
The HtmlHelper, FormHelper, and SessionHelper are available by
default, as is the SessionComponent. But if you choose to define your
own $helpers array in AppController, make sure to include HtmlHelper
and FormHelper if you want them still available by default in your
Controllers.

Resources