• Jameslong
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 13
    Replies

Hi ,

 

I am writing a test class fo rthe follwing integration class and my code covers 90%.

 

But I want to know if this is the right test class or not.

 

CODE:

 

public with sharing class OpportunityUpdateIntegration {

@future (callout=true)

public static void runjob(String username, String password, String jobName, String jobType) {
system.debug('inside ');
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();

req.setEndpoint('https://app.informaticaondemand.com/saas/api/1/runjob?username='+EncodingUtil.urlEncode(username, 'UTF-8')+
'&password='+EncodingUtil.urlEncode(password, 'UTF-8')+
'&jobName='+EncodingUtil.urlEncode(jobName, 'UTF-8')+
'&jobType='+EncodingUtil.urlEncode(jobType, 'UTF-8'));
req.setMethod('POST');

try
{
res = http.send(req);
}
catch(System.CalloutException e)
{
System.debug('Job Error: '+ e);
System.debug(res.toString());
}
}
}

 

TEST CLASS:

@istest
public class OpportunityUpdateIntegration_test{
static TestMethod void OpportunityUpdateIntegration_test(){
//data preparation
//insert opportunity test records
opportunity opy = new opportunity(Name = 'test opp',stagename = 'closed won',closedate=date.parse('1/1/2020'));
insert opy;
//Assert the inserted test record
system.assertequals(opy.name,'test opp');
OpportunityUpdateIntegration oui = new OpportunityUpdateIntegration();
}
}

 

Please comment on the test class if it is correct or not.

 

Thanks

JL

Hi buddies,

 

I have started writing the test class but I am facing error when trying to insert the opportunity line items as below:

 

Please help me out on how to inset opportunity lineitems for the opportunities

 

Compile Error: Invalid field Name for SObject OpportunityLineItem at line 16 column 57


@istest
public class testAnOVIIDClass
{
static TestMethod void testAnOVIIDClass(){
//data preparation
list<opportunitylineitem> olilist=new list<opportunitylineitem>();
list<opportunity> opplist=new list<opportunity>();
list<id> pricebookidlist= new list<ID>();
list<String> productlist=new list<string>();

for(integer i=0;i<2;i++){
opportunity opy = new opportunity(Name = 'test opp' + i);
opplist.add(opy);
}
for(integer i=0;i<2;i++){
opportunitylineitem aol= new opportunitylineitem(Name = 'test opp line item' + i);
olilist.add(aol);
}
}
}

 

Thanks

JL

Hi,

 

I am trying to write a test class for the below web service class....

 

Any help would be highly appreciated as I don't have enough knowledge on writing test classes...

 

CLASS:

 

global class AwebservClass {
public static final list<id> pricebookidlist= new list<ID>();

public static final list<String> productlist=new list<string>();

public static list<opportunitylineitem> olilist=new list<opportunitylineitem>();

global class result{

webservice list<list<oviidresultmap>> ovimapping=new list<list<oviidresultmap>>();

}
global class oviidresultmap{
webservice id Lineitemid;
webservice list<id> oviids= new list<id>();
webservice double LocalMRS;  //number 
webservice double LocalNRS;  //number 
webservice double MRS;    //number 
webservice double NRS;    //number 
webservice id localcurrency; //look up to custom object exchange rates

}
Webservice static result getOpplineitems(id oppid){

oviidresultmap ovii=new oviidresultmap();
map<id, map<id,list<id>>> OVIIds=new Map<id, map<id,list<id>>>();
result res=new result();
Map<id,list<id>> resultsmap=new Map<id,list<id>>();
res.ovimapping.add(getovimappedids(oppid));
system.debug('result'+res);
return res;
}

public static oviidresultmap[] getOVIMappedids(id oppid){
list<oviidresultmap> ress=new list<oviidresultmap>();
map<id,list<id>> p2OlmidMap=new map<id,list<id>>();
map<id,list<list<id>>> OVImap=new map<id,list<list<id>>>();

list<id> testid=new list<id>();
map<id,id> p2Olmidmap1= new map<id,id>();
olilist =[select id,product_family_pr4__c,pricebookentryid,Local_Currency__c,Local_MRS__c,Local_NRS__c,MRC__c,NRC__c from Opportunitylineitem where opportunityid =:oppid];
if(olilist.size()>0){
for(OpportunitylineItem olm:olilist){
pricebookidlist.add(olm.pricebookentryid);
productlist.add(olm.product_family_pr4__c);

}
system.debug('productnames'+productlist);

Map<Id, PricebookEntry> entries = new Map<Id, PricebookEntry>(
[select product2.id from pricebookentry
where id in :pricebookidlist]);

for(OpportunitylineItem ollm:olilist){
oviidresultmap resss=new oviidresultmap();
resss.LocalMRS=ollm.Local_MRS__c;
resss.LocalNRS=ollm.Local_NRS__c;
resss.MRS=ollm.MRC__c;
resss.NRS=ollm.NRC__c;
resss.localcurrency=ollm.Local_Currency__c;
id test=entries.get(ollm.pricebookentryid).product2.id;
resss.oviids.addall(productids(test));
system.debug('finalll'+resss.oviids);
testid.add(ollm.id);
p2OlmidMap1.put(test,ollm.id);
system.debug('oviproduct'+p2OlmidMap1);
resss.Lineitemid=p2OlmidMap1.get(test);

ress.add(resss);
}

system.debug('fff'+ress);

}
return ress;
}
public static list<id> productids(id productid){
list<id> idlist=new list<id>();
for(OVI_value__c ovi:[select id,Product__c from OVI_value__c where Product__c=:productid]){
idlist.add(ovi.id);
system.debug('ss'+idlist);

}
return idlist;
}
}

Hi,

 

I am trying to use a nested map to create mapping between IDs of two objects which are product and its related object AMproducts__c. 

 

The business case is each Product will have multiple AMproducts__c linked to it.(1:n relation).

 

I am trying to use this....

 

map<id,List<id>>

 

where id will be product id and List<id> will be a list of its corresponding AMproducts ids.

 

Please help me with the syntax and how to populate values in the map to create a successful nested map with ids in them.

 

Thanks

JL

Hi ,

 

I am writing a test class fo rthe follwing integration class and my code covers 90%.

 

But I want to know if this is the right test class or not.

 

CODE:

 

public with sharing class OpportunityUpdateIntegration {

@future (callout=true)

public static void runjob(String username, String password, String jobName, String jobType) {
system.debug('inside ');
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();

req.setEndpoint('https://app.informaticaondemand.com/saas/api/1/runjob?username='+EncodingUtil.urlEncode(username, 'UTF-8')+
'&password='+EncodingUtil.urlEncode(password, 'UTF-8')+
'&jobName='+EncodingUtil.urlEncode(jobName, 'UTF-8')+
'&jobType='+EncodingUtil.urlEncode(jobType, 'UTF-8'));
req.setMethod('POST');

try
{
res = http.send(req);
}
catch(System.CalloutException e)
{
System.debug('Job Error: '+ e);
System.debug(res.toString());
}
}
}

 

TEST CLASS:

@istest
public class OpportunityUpdateIntegration_test{
static TestMethod void OpportunityUpdateIntegration_test(){
//data preparation
//insert opportunity test records
opportunity opy = new opportunity(Name = 'test opp',stagename = 'closed won',closedate=date.parse('1/1/2020'));
insert opy;
//Assert the inserted test record
system.assertequals(opy.name,'test opp');
OpportunityUpdateIntegration oui = new OpportunityUpdateIntegration();
}
}

 

Please comment on the test class if it is correct or not.

 

Thanks

JL

Hi buddies,

 

I have started writing the test class but I am facing error when trying to insert the opportunity line items as below:

 

Please help me out on how to inset opportunity lineitems for the opportunities

 

Compile Error: Invalid field Name for SObject OpportunityLineItem at line 16 column 57


@istest
public class testAnOVIIDClass
{
static TestMethod void testAnOVIIDClass(){
//data preparation
list<opportunitylineitem> olilist=new list<opportunitylineitem>();
list<opportunity> opplist=new list<opportunity>();
list<id> pricebookidlist= new list<ID>();
list<String> productlist=new list<string>();

for(integer i=0;i<2;i++){
opportunity opy = new opportunity(Name = 'test opp' + i);
opplist.add(opy);
}
for(integer i=0;i<2;i++){
opportunitylineitem aol= new opportunitylineitem(Name = 'test opp line item' + i);
olilist.add(aol);
}
}
}

 

Thanks

JL

Hi,

 

I am trying to write a test class for the below web service class....

 

Any help would be highly appreciated as I don't have enough knowledge on writing test classes...

 

CLASS:

 

global class AwebservClass {
public static final list<id> pricebookidlist= new list<ID>();

public static final list<String> productlist=new list<string>();

public static list<opportunitylineitem> olilist=new list<opportunitylineitem>();

global class result{

webservice list<list<oviidresultmap>> ovimapping=new list<list<oviidresultmap>>();

}
global class oviidresultmap{
webservice id Lineitemid;
webservice list<id> oviids= new list<id>();
webservice double LocalMRS;  //number 
webservice double LocalNRS;  //number 
webservice double MRS;    //number 
webservice double NRS;    //number 
webservice id localcurrency; //look up to custom object exchange rates

}
Webservice static result getOpplineitems(id oppid){

oviidresultmap ovii=new oviidresultmap();
map<id, map<id,list<id>>> OVIIds=new Map<id, map<id,list<id>>>();
result res=new result();
Map<id,list<id>> resultsmap=new Map<id,list<id>>();
res.ovimapping.add(getovimappedids(oppid));
system.debug('result'+res);
return res;
}

public static oviidresultmap[] getOVIMappedids(id oppid){
list<oviidresultmap> ress=new list<oviidresultmap>();
map<id,list<id>> p2OlmidMap=new map<id,list<id>>();
map<id,list<list<id>>> OVImap=new map<id,list<list<id>>>();

list<id> testid=new list<id>();
map<id,id> p2Olmidmap1= new map<id,id>();
olilist =[select id,product_family_pr4__c,pricebookentryid,Local_Currency__c,Local_MRS__c,Local_NRS__c,MRC__c,NRC__c from Opportunitylineitem where opportunityid =:oppid];
if(olilist.size()>0){
for(OpportunitylineItem olm:olilist){
pricebookidlist.add(olm.pricebookentryid);
productlist.add(olm.product_family_pr4__c);

}
system.debug('productnames'+productlist);

Map<Id, PricebookEntry> entries = new Map<Id, PricebookEntry>(
[select product2.id from pricebookentry
where id in :pricebookidlist]);

for(OpportunitylineItem ollm:olilist){
oviidresultmap resss=new oviidresultmap();
resss.LocalMRS=ollm.Local_MRS__c;
resss.LocalNRS=ollm.Local_NRS__c;
resss.MRS=ollm.MRC__c;
resss.NRS=ollm.NRC__c;
resss.localcurrency=ollm.Local_Currency__c;
id test=entries.get(ollm.pricebookentryid).product2.id;
resss.oviids.addall(productids(test));
system.debug('finalll'+resss.oviids);
testid.add(ollm.id);
p2OlmidMap1.put(test,ollm.id);
system.debug('oviproduct'+p2OlmidMap1);
resss.Lineitemid=p2OlmidMap1.get(test);

ress.add(resss);
}

system.debug('fff'+ress);

}
return ress;
}
public static list<id> productids(id productid){
list<id> idlist=new list<id>();
for(OVI_value__c ovi:[select id,Product__c from OVI_value__c where Product__c=:productid]){
idlist.add(ovi.id);
system.debug('ss'+idlist);

}
return idlist;
}
}

Hi,

 

I am trying to use a nested map to create mapping between IDs of two objects which are product and its related object AMproducts__c. 

 

The business case is each Product will have multiple AMproducts__c linked to it.(1:n relation).

 

I am trying to use this....

 

map<id,List<id>>

 

where id will be product id and List<id> will be a list of its corresponding AMproducts ids.

 

Please help me with the syntax and how to populate values in the map to create a successful nested map with ids in them.

 

Thanks

JL