Saleforce Test Classes for CPQ API Models - salesforce

I'm a bit new to creating Salesforce apex. I'm looking to implement Saleforce CPQ API. Do we need to create test classes for the CPQ API Models?
Link: https://developer.salesforce.com/docs/atlas.en-us.cpq_dev_api.meta/cpq_dev_api/cpq_api_models.htm
Sample api model code:
public class QuoteModel {
public SBQQ__Quote__c record;
public QuoteLineModel[] lineItems;
public QuoteLineGroupModel[] lineItemGroups;
public Integer nextKey;
public Boolean applyAdditionalDiscountLast;
public Boolean applyPartnerDiscountFirst;
public Boolean channelDiscountsOffList;
public Decimal customerTotal;
public Decimal netTotal;
public Decimal netNonSegmentTotal;
}

The class shown in this question contains no executable lines of code, only variable declarations. Classes of this kind cannot be tested and have no code coverage requirements. Test classes will become required only when executable code is added to the class.

Related

Building an aspect with the same annotation can be on the class or the method and can be both

I'm creating a custom Metric Aspect so that I don't have to do METRIC.aboutTo("save", "order") in the code. My organization uses custom metric libraries.
So, I want to create a custom metric annotation and aspect to do this for me.
I'm looking to be able to add the annotation #PostgressMetric to both the class and the method. It would look something like this:
#Retention(RetentionPolicy.RUNTIME)
#Target({ElementType.TYPE, ElementType.METHOD})
public #interface PostgressMetric {
String value() default "";
String table() default "";
}
If the metric is on the class, then I want to use those values as "defaults". So you could have something like this:
#Repository
#PostgressMetric(table = "order")
public class OrderRepository {
#PostgressMetric("save")
public void save(Order order) {
}
}
This is also a valid setup:
#Repository
public class OrderRepository {
#PostgressMetric(table="order", value="save")
public void save(Order order) {
}
}
and of course this is also a valid setup:
#Repository
#PostgressMetric(table="order", value="save")
public class OrderRepository {
public void save(Order order) {
}
}
Now, in my aspect I want to get the annotation from the class, then get the annotation from the method. If the class has the annotation then get the table and value and use those as default values. If the method has the annotation then if the values aren't blank, use them to override the default values specified in the class annotation.
Is there a standard way to get the two annotations, or is it just a brute force get the class values and then get the method values and override them?

how to get range class of objectProperty by its domain class in owlapi?

In my project, I'd like to get all the range class related to the given class by an restricted(somevaluefrom or allvalues from) objectproperties. I can get the restricted subclassofAxioms expressions including the given class, but how can I get the range class in these expressions? In other word, how can I get all the related classes to the given class excluding inherited subclass.
For example:
public static void printSubClassOfAxioms(OWLOntology ontology,OWLReasoner reasoner,OWLClass owlClass){
for(OWLSubClassOfAxiom ax:ontology.getSubClassAxiomsForSubClass(owlClass)){
OWLClassExpression expression=ax.getSuperClass();
System.out.println(ax);
System.out.println(expression);
}
}
The results are:
SubClassOf(<#FourCheesesTopping> <#CheeseTopping>)
SubClassOf(<#FourCheesesTopping> ObjectSomeValuesFrom(<#hasSpiciness> <#Mild>))
SubClassOf(<#FourCheesesTopping> ObjectAllValuesFrom(<#hasCountryOfOrigin> #Country>))
How can I just get the range classes #Country and #Mild
Thank you for your attention!
Write an OWLObjectVisitor and override the visit(OWL... Type) for the restrictions you're interested in. At that point,
type.getFiller()
will yield the class you're after.
Examples are in the documentation: https://github.com/owlcs/owlapi/wiki/Documentation
public class RestrictionVisitor extends OWLClassExpressionVisitor {
#Override
public void visit(#Nonnull OWLObjectSomeValuesFrom ce) {
// This method gets called when a class expression is an existential
// (someValuesFrom) restriction and it asks us to visit it
}
}

Use of Wrapper class for deserialization in callout?

I found the following use of a wrapper class, and was wondering if it is a good practice or whether its just duplication of code for no reason.
//Class:
public class SomeClass{
public Integer someInt;
public String someString;
}
//Callout Class:
public class CalloutClass{
public SomeClass someMethod(){
//...code to do a callout to an api
SomeClass someClassObj = (SomeClass)JSON.Deserialize(APIResponse.getBody(), SomeClass.class);
return someClassObj;
}
}
//Controller:
public class SomeController {
public SomeController(){
someClassObj = calloutClassObj.someMethod();
SomeWrapper wrapperObj = new SomeWrapper();
for(SomeClass iterObj : someClassObj){
wrapperObj.someWrapperInt = iterObj.someInt;
wrapperObj.someWrapperString = iterObj.someString;
}
}
public class someWrapper{
public Integer someWrapperInt{get;set;}
public String someWrapperString{get;set;}
}
}
The wrapper class "someWrapper" could be eliminated if we just use getters and setters ({get;set;}) in "SomeClass."
Could anyone explain if there could be a reason for following this procedure?
Thanks,
James
My assumption (because, code in controller is extra pseudo) is
SomeClass is a business entity, purpose of which is to store/work with business data. By work I mean using it's values to display it (using wrapper in controller), to calculate smth in other entities or build reports... Such kind of object should be as lightweight as possible. You usually iterate through them. You don't need any methods in such kind of objects. Exception is constructor with parameter(s). You might want to have SomeObject__c as parameter or someWrapper.
someWrapper is a entity to display business entity. As for wrapper classes in controllers. Imagine, that when you display entity on edit page and enter a value for someWrapperInt property, you want to update someWrapperString property (or you can just put validation there, for example, checking if it is really Integer). Usually, as for business entity, you don't want such kind of functionality. But when user create or edit it, you may want smth like this.

how to access made objects from the service

I have a WCF service and a WPF application in my solution.
The application contains objects I made (customer, products etc), my windows and my business logic.
I need to retrieve a list of customers using the service but the service doesn't know what is a customer.
I CAN put all of my objects in both projects or reference one project from the other but that doesn't seem like the right way.
Any idea what should I do here?
Use data contract in your service like.
[DataContract]
public class Customer
{
[DataMember]
public int CustomerID{ get; set; } }
[DataMember]
public string CustomerName{ get; set; }
}
public interface ICustomerService
{
[OperationContract]
List<Customer> GetAllCustomer();
}
public Class CustomerService:ICustomerService
{
List<Customer> GetAllCustomer()
{
// write your own code to fill List<Customer> ans return it
}
}
Thanks
Ck Nitin (TinTin)
When will add the service reference of WCF or add the .dll in which WCF service is define in case if you are calling the WCF service from code using ServiceHost class, you can create the object for this customer class and you can easily use it.
Thanks
Ck Nitin (TinTin)

Alternative to Using an Entity as a Parameter to an Invoke Method in WCF RIA Services

Howdy, ya'll! First question on StackOverflow! :-)
So here's the scenario: We're working on a web app with Silverlight 4 and using WCF RIA Services 1.0 SP1 Beta for the web service. I have my entities in the Entity Framework Designer, but I'm using a slightly-modified ADO.NET C# POCO Entity Generator template to generate the classes.
What I'd like to do is have a method inside a Domain Service with the following signature:
[EnableClientAccess]
public class ResultService : DomainService
{
[Invoke]
public SerializableResult CalculateResult(EntityOne e1, EntityTwo e2);
}
I am returning both EntityOne and EntityTwo to the client through queries in other services, like so:
[EnableClientAccess]
public class EntityOneService : DomainService
{
public IQueryable<EntityOne> GetEntityOnes();
}
[EnableClientAccess]
public class EntityOneService : DomainService
{
public IQueryable<EntityTwo> GetEntityTwos();
}
Those classes are successfully being generated in the Silverlight project. The SerializableResult does not have a key.
When I try to compile, I get the following error: "Operation named 'CalculateResult' does not conform to the required signature. Parameter types must be an entity or complex type, a collection of complex types, or one of the predefined serializable types."
In my research, the most helpful information I found were in the comments of this post by Jeff Handley.
Of note, Peter asked in a comment:
I get an 'does not conform to the required signature ...' compile error if my complex object has an [Key] Attribute. When I remove this attribute I can use the object as parameter for an Invoke operation.
Jeff's response:
This is by design. Complex objects cannot have Key properties. If you have a Key the class gets treated as an Entity.
So it sounds as if any further efforts to try to get my method to work will be futile. However, I was wondering if anyone else has come across this problem, and what they did to solve it.
Thanks very much!
I have the following and it works for me.
namespace BusinessApplication2.Web
{
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
[EnableClientAccess()]
public class DomainService1 : DomainService
{
public IQueryable<EntityOne> GetEntityOnes()
{
return null;
}
public IQueryable<EntityTwo> GetEntityTwos()
{
return null;
}
[Invoke]
public SerializableResult GetSerializableResult(EntityOne one, EntityTwo two)
{
return new SerializableResult() { Result = "It woooooorrrked!" };
}
}
public class EntityOne
{
[Key]
public int Id { get; set; }
}
public class EntityTwo
{
[Key]
public int Id { get; set; }
}
public class SerializableResult
{
public string Result { get; set; }
}
}
Many thanks to Mr. Jeff Handley and Mr. Dinesh Kulkarni for the answer (through Twitter).
In order for an Entity to be used as a parameter in an invoke method, that Entity must be exposed through a query method existing within the same DomainService. The intention for this restriction is that
"Each domain service needs to be able to stand on its own."
By adding two dummy Query methods (see Jeff's answer for an example), I was able to compile my code.

Resources