• SFD Salesforce
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 9
    Replies

Hi all,

 

actually  i  tried to write the test case it shows an error is too many soql queries 101 .pls help me the given solution.

 

my test case and code:

 

global class Products implements Messaging.InboundEmailHandler {
private String parse(String toParse) {
DOM.Document doc = new DOM.Document();
try {
doc.load(toParse);
DOM.XMLNode root = doc.getRootElement();
return walkThrough(root);

} catch (System.XMLException e) { // invalid XML
return e.getMessage();
}
}
private String walkThrough(DOM.XMLNode node) {
String result = '\n';
if (node.getNodeType() == DOM.XMLNodeType.COMMENT) {
return 'Comment (' + node.getText() + ')';
}
if (node.getNodeType() == DOM.XMLNodeType.TEXT) {
return 'Text (' + node.getText() + ')';
}
if (node.getNodeType() == DOM.XMLNodeType.ELEMENT) {
result += 'Element: ' + node.getName();
if (node.getText().trim() != '') {
result += ', text=' + node.getText().trim();
}
if (node.getAttributeCount() > 0) {
for (Integer i = 0; i< node.getAttributeCount(); i++ ) {
result += ', attribute #' + i + ':' + node.getAttributeKeyAt(i) + '=' + node.getAttributeValue(node.getAttributeKeyAt(i), node.getAttributeKeyNsAt(i));
}
}
for (Dom.XMLNode child: node.getChildElements()) {
result += walkThrough(child);
}
return result;
}
return ''; //should never reach here
}

global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

String myPlainText = '';
String subjectDetail = '';
String fromEmailId ='';
String myEmailIdBodyText = '';
String myStoreName= '';
String myDate ='';

String requestName='';
String limitDate='';
String client='';
String category='';
String title='';
String setbarcode='';
String commonbarcode='';
Integer reqQty=0;
String comment='';
String itemdescription='';
String itembarcode='';
String onesetcount='';
String mustcnt='';
String workPlainText = '';
String caption='';
String newline='\n';
String parseResult='';
String currentdata ='';

// read only XML Workorder portions
caption= '<WorkOrder>';
myPlainText = email.plainTextBody.substring(email.plainTextBody.indexOf(caption));
caption= '</WorkOrder>';
myPlainText = myPlainText.subString(0,myPlainText.indexOf(caption)+caption.length());


parseResult=parse(myPlainText);

caption= 'WHWorkOrder';
currentdata = parseResult.substring(parseResult.indexOf(caption));

 

// Add the email plain text into the local variable
// try {
caption= 'WHWorkOrder';
while (currentdata.indexOf(caption)!=-1) {

caption= 'RequestType';
myPlainText = currentdata.substring(currentdata.indexOf(caption));
caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
requestName = myPlainText.subString(0,myPlainText.indexOf(newline));

caption= 'TermDate';
myPlainText = currentdata.substring(currentdata.indexOf(caption));
caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
limitDate = myPlainText.subString(0,myPlainText.indexOf(newline));

caption= 'Client';
myPlainText = currentdata.substring(currentdata.indexOf(caption));
caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
client = myPlainText.subString(0,myPlainText.indexOf(newline));


caption= 'ItemType';
myPlainText = currentdata.substring(currentdata.indexOf(caption));
caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
category = myPlainText.subString(0,myPlainText.indexOf(newline));

caption= 'Title';
myPlainText = currentdata.substring(currentdata.indexOf(caption));
caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
title = myPlainText.subString(0,myPlainText.indexOf(newline));

caption= 'SetBarCode';
myPlainText = currentdata.substring(currentdata.indexOf(caption));
caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
setbarcode = myPlainText.subString(0,myPlainText.indexOf(newline));

caption= 'CommonBarCode';
myPlainText = currentdata.substring(currentdata.indexOf(caption));
caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
commonbarcode = myPlainText.subString(0,myPlainText.indexOf(newline));

caption= 'RequestedQuantity';
myPlainText = currentdata.substring(currentdata.indexOf(caption));
caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
reqQty = integer.valueOf(myPlainText.subString(0,myPlainText.indexOf(newline)));

caption= 'Comment';
myPlainText = currentdata.substring(currentdata.indexOf(caption));
caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
comment = myPlainText.subString(0,myPlainText.indexOf(newline));

List<WHSummary__c> whsummary =[select id from WHSummary__c where Name =:requestName];
if (whsummary.size()==0) {

if(whsummary.size()>0)
{
// instance of workorder
WHWorkOrder__c workorder=new WHWorkOrder__c();

// set field values
workorder.RequestType__c = whsummary[0].id;
workorder.termdate__c = date.parse(limitDate);
workorder.Title__c=title;
workorder.requestedquantity__c=reqQty;
workorder.Client__c = client;
Schema.DescribeFieldResult F = WHWorkOrder__c.itemtype__c.getDescribe();
List<Schema.PicklistEntry> P = F.getPicklistValues();
Boolean found=false;
for( Schema.PicklistEntry ff : P)
{
String tmp=ff.getValue();
if (tmp.equals(category)==true) {
workorder.itemtype__c = category;
found=true;
}
}
if (found==false) {

workorder.setbarcode__c=setbarcode;
workorder.commonbarcode__c=commonbarcode;
workorder.comment__c = comment;

// insert work order
insert workorder;

caption= 'WODetail';

workPlainText = currentdata.substring(currentdata.indexOf(caption));

caption= 'WHWorkOrder';
if (workPlainText.indexOf(caption)!=-1) {
workPlainText = workPlainText.substring(0,workPlainText.indexOf(caption));
currentdata = currentdata.subString(caption.length());
currentdata = currentdata.substring(currentdata.indexOf(caption));

} else {
currentdata = '';
}

caption= 'WODetail';
while (workPlainText.indexOf(caption)!=-1) {

caption= 'ArticleName';
myPlainText = workPlainText.substring(workPlainText.indexOf(caption));
caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
itemdescription = myPlainText.subString(0,myPlainText.indexOf(newline));

caption= 'ArticleBarCode';
myPlainText = workPlainText.substring(workPlainText.indexOf(caption));
caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
itembarcode = myPlainText.subString(0,myPlainText.indexOf(newline));

caption= 'Quantity';
myPlainText = workPlainText.substring(workPlainText.indexOf(caption));
caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
onesetcount = myPlainText.subString(0,myPlainText.indexOf(newline));

caption= 'QuantityRequired';
myPlainText = workPlainText.substring(workPlainText.indexOf(caption));

caption= 'text=';
myPlainText = myPlainText.substring(myPlainText.indexOf(caption));
myPlainText = myPlainText.subString(caption.length());
workPlainText = myPlainText;
if (myPlainText.indexOf(newline)!=-1) {
mustcnt = myPlainText.subString(0,myPlainText.indexOf(newline));
} else {
mustcnt = myPlainText;

}
caption= 'WODetail';

// instance of workorder
WODetail__c wodetail=new WODetail__c();
// set field values
wodetail.requestid__c = workorder.id;
wodetail.Name = itemdescription;
wodetail.quantity__c = integer.valueOf(onesetcount);
wodetail.articlebarcode__c = itembarcode;
wodetail.quantitymust__c = integer.valueOf(mustcnt);

// insert work order detail
insert wodetail;
if (workPlainText.length()==0) {
break;
}
// caption= 'ArticleName';
// throw new BooksSetOrderException('Parse result。 確認してください。 [' + workPlainText+ ']');

}
}
if (currentdata.length()==0) {
break;
}

// } catch (System.StringException e)
// {

// myPlainText = email.plainTextBody;
// System.debug('Error in email Processing: ' + e);
// }


// Set the result to true, no need to send an email back to the user
// with an error message
result.success = true;
// Return the result for the Force.com Email Service
return result;
}



//Test Case above Class


static testmethod void TestCase()
{
// Create a new email and envelope object
Messaging.InboundEmail email = new Messaging.InboundEmail();
Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

// Set up your data if you need to

// Create the email body
// String requestName='sdsd';
// List<WHSummary__c> m2=[select id from WHSummary__c where Name =:requestName];

WHSummary__c ws=new WHSummary__c();
ws.Name ='pradeep';
// m2.add(ws);
insert ws;
//m2.add(ws);
// insert m2
// set field values
WHWorkOrder__c workorder1=new WHWorkOrder__c();
workorder1.RequestType__c = '2434';
workorder1.termdate__c = date.parse('2/10/2012');
workorder1.Title__c='rakutenlogi';
// workorder1.requestedquantity__c=decimal.parse('10');
workorder1.Client__c = 'Rakuten';
insert workorder1;

// m2.add(workorder1);
// insert m2;
email.fromAddress ='pradeepkumarperla@rediffmail.com';
String contactEmail = 'bookssetorder@44rehu4s7x9jkrpnnw5xkjp68.1hmyfea0.1.apex.salesforce.com';

email.subject ='Test';
email.plainTextBody = '<WorkOrder>\n <WHWorkOrder>\n <RequestType>セット組み</RequestType>\n <TermDate>2012/10/29</TermDate>\n <Client>テスト商品</Client>\n <ItemType>GAME</ItemType>\n <Title>テスト商品</Title>\n <SetBarCode>2100010099204</SetBarCode> \n <CommonBarCode>10001045411694</CommonBarCode> \n <RequestedQuantity>20</RequestedQuantity>\n <Comment>23日着の新譜ですので、確保お願いします。</Comment>\n </WHWorkOrder>\n <WODetail>\n <ArticleName>テスト5</ArticleName>\n <ArticleBarCode>4988602160835</ArticleBarCode>\n <Quantity>3</Quantity>\n <QuantityRequired>10</QuantityRequired>\n </WODetail>\n</WorkOrder>';
// String requestName='';

// List<WHSummary__c > m2=new List<WHSummary__c>();
// WHSummary__c ws=new WHSummary__c();
// ws.Name ='pradeep';
//m2.add(ws);
// insert m2;
Products edr = new Products();

Test.startTest();

Messaging.InboundEmailResult result = edr.handleInboundEmail(email, env);


Test.stopTest();


}
}

 

cheers

Pradeep.P

Hi All,

 

My requirement ,  how  to update the cases tab of  the field values update  for my chatter display in salesforce by using salesforce chatter. ple guidance the given requirement  with following steps

 

 

cheers

 

Pradeep P

Hi All,

 

How to install the Project /Issue Management in saleforce. by using appexchange .can any body help another way to install

the project /Issue Management .wht purpose and wht usage.

 

 

cheers

 

Pradeep.p

Hi all,

 

can help me test case of  my trigger .

 

This is trigger code,

 

 

global class Monthly{

public static void ValAdd()//Set<Id> InquiryId
{

List<Inquiry__c> Inquiry= [SELECT KPIInquiryContent__c,KPIInquiryContent__r.Account__c,CommodityName__c,ModifyDate__c,Status__c from Inquiry__c ];
{
Inquiry__c Fr= Inquiry[0];
Date startDate=fr.ModifyDate__c.toStartOfMonth();
Date endDate=fr.ModifyDate__c.toStartOfMonth().addMonths(1);

LIST<AggregateResult> countmonth=[SELECT count(KPIInquiryContent__c) coun from Inquiry__c where KPIInquiryContent__r.Account__c=:fr.KPIInquiryContent__r.Account__c and ModifyDate__c >= :startDate AND ModifyDate__c < :endDate and PayoffObject__c=:'○' and Status__c IN('対応中' ,'対応完了')];
//LIST<AggregateResult> calmonth=[Select CALENDAR_MONTH(WorkDate__c), count(ImportCount__c) icount from WorkResultsMonth__c where Account_Name__c=:acname GROUP BY CALENDAR_MONTH(WorkDate__c)];
LIST<AggregateResult> calmonth=[Select count(ImportCount__c) icount from WorkResultsMonth__c where WorkDate__c >= :startDate and WorkDate__c < :endDate and Account_Name__c=:fr.KPIInquiryContent__r.Account__c];

List<KPIAccident__c> acc= [SELECT Date__c,MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c where Account_Name__c=:fr.KPIInquiryContent__r.Account__c and Date__c >= :startDate and Date__c < :endDate]; //
if(!acc.isEmpty() )
{

KPIAccident__c accupdate = acc[0];
Integer totalcountmonth=Integer.Valueof(countmonth[0].get('coun'));

accupdate.MonthlyGeneratedCount__c=totalcountmonth;

Integer totalmonthwork= Integer.Valueof(calmonth[0].get('icount'));
accupdate.MonthlyPPM__c=((totalmonthwork/totalcountmonth)*1000000);
update accupdate;
}else
{
KPIAccident__c kpi = new KPIAccident__c();
List<KPIAccident__c> ToUpdate = new List<KPIAccident__c>();
kpi.Date__c=fr.ModifyDate__c;
kpi.Account__c=fr.KPIInquiryContent__r.Account__c;
kpi.itemname__c= fr.CommodityName__c;

Integer totalcountmonths=Integer.Valueof(countmonth[0].get('coun'));
kpi.MonthlyGeneratedCount__c=totalcountmonths;
Integer totalmonthworks= Integer.Valueof(calmonth[0].get('icount'));

kpi.MonthlyPPM__c=((totalmonthworks/totalcountmonths)*1000000);
ToUpdate.add(kpi);
insert ToUpdate;

}
}
}}

 

 

 

 

my test case code is:

 

static testMethod void testAMethod1()
{
Test.startTest();
Account a2 = new Account();
a2.name='pradeep';
insert a2;
Inquiry__c f1=new Inquiry__c(CommodityName__c='pradeep',ModifyDate__c=date.parse('03/09/2012'),Status__c ='good');
insert f1;
List<KPIAccident__c> ac2=[SELECT Date__c,MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c];

if(ac2.isEmpty())
{

KPIAccident__c m5=ac2[0];
m5.MonthlyGeneratedCount__c= 129;
m5.MonthlyPPM__c=2563;
//m5.Date__c=f1.ModifyDate__c;
insert m5;
}
else
{
List<KPIAccident__c> listEt = new List<KPIAccident__c>();
KPIAccident__c d1=new KPIAccident__c ();
d1.MonthlyGeneratedCount__c=145;
d1.MonthlyPPM__c=2569;
listEt.add(d1);
try
{
insert listEt;
}
catch(Exception e){}
Test.stopTest();

}
}
82 }

 

my trigger is:

 

trigger AddValue_to_Accident on Inquiry__c (after insert,after update)

{

Monthly.ValAdd();
}

 

 

 

 

 

The above red mark not coverage of my test case of trigger. The tese case was written but it should be coverage 61%.The red mark data not covered.  pls help me my test case of trigger..

 

 

If my  test case in build of trigger. it should be covered in 65% but an error is

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, FBR_AddValue_to_Accident: execution of AfterInsert caused by: System.ListException: List index out of bounds: 0 Class.FBR_InquiryMonthly.ValAdd: line 38, column 1 Trigger.FBR_AddValue_to_Accident: line 5, column 1: []. 

 

can any help me  test case of trigger and solution of error.

 

Cheers

Pradeep Kumar.p

 

 

 

Hi All,

 

can any body the test case error of  trigger .

This is my Test case of trigger:

 

 

global class InquiryMonthly{

public static void ValAdd()//Set<Id> InquiryId
{

List<Inquiry__c> Inquiry= [SELECT KPIInquiryContent__c,CommodityName__c,ModifyDate__c,Status__c from Inquiry__c ];
{
Inquiry__c g1= Inquiry[0];
Date startDate=g1.ModifyDate__c.toStartOfMonth();
Date endDate=g1.ModifyDate__c.toStartOfMonth().addMonths(1);

LIST<AggregateResult> countmonth=[SELECT count(KPIInquiryContent__c) coun from Inquiry__c];

LIST<AggregateResult> calmonth=[Select count(ImportCount__c) icount from WorkResultsMonth__c where WorkDate__c >= :startDate and WorkDate__c < :endDate];

List<KPIAccident__c> acc= [SELECT Date__c,MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c ];
if(!acc.isEmpty() )
{

KPIAccident__c accupdate = acc[0];
Integer totalcountmonth=Integer.Valueof(countmonth[0].get('coun'));

accupdate.MonthlyGeneratedCount__c=totalcountmonth;

Integer totalmonthwork= Integer.Valueof(calmonth[0].get('icount'));
accupdate.MonthlyPPM__c=((totalmonthwork/totalcountmonth)*1000000);
update accupdate;
}else
{
KPIAccident__c kpi = new KPIAccident__c();
List<KPIAccident__c> ToUpdate = new List<KPIAccident__c>();
kpi.Date__cg1.ModifyDate__c;
// kpi.Account__c=g1.KPIInquiryContent__r.Account__c;
kpi.itemname__c= g1.CommodityName__c;

Integer totalcountmonths=Integer.Valueof(countmonth[0].get('coun'));
kpi.MonthlyGeneratedCount__c=totalcountmonths;
Integer totalmonthworks= Integer.Valueof(calmonth[0].get('icount'));

kpi.MonthlyPPM__c=((totalmonthworks/totalcountmonths)*1000000);
ToUpdate.add(kpi);
insert ToUpdate;

}
}
}
static testMethod void testAMethod1()
{
Test.startTest();
Account a2 = new Account();
a2.name='rakuten12';
insert a2;
Inquiry__c f1=new Inquiry__c(CommodityName__c='pradeep',ModifyDate__c=date.parse('03/09/2012'),Status__c ='good');
insert f1;
List<KPIAccident__c> ac2=[SELECT Date__c,MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c];

if(ac2.isEmpty())
{

KPIAccident__c m5=ac2[0];
m5.MonthlyGeneratedCount__c= 129;
m5.MonthlyPPM__c=2563;
//m5.Date__c=f1.ModifyDate__c;
insert m5;
}
else
{
List<KPIAccident__c> listEt = new List<KPIAccident__c>();
KPIAccident__c d1=new KPIAccident__c ();
d1.MonthlyGeneratedCount__c=145;
d1.MonthlyPPM__c=2569;
listEt.add(d1);
try
{
insert listEt;
}
catch(Exception e){}
Test.stopTest();

}
}
}

 

Now  i work both trigger and test case in build the trigger class. But the coverage 65% ,it becomes an error is

 

 

BR_InquiryMonthly.testAMethod1209.0System.DmlException:挿入が失敗しました。行0の最初の例外。最初のエラー:CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY、FBR_AddValue_to_Accident:によって引き起こさAfterInsertの実行:System.ListException:境界の外にリストのインデックス:0 Class.FBR_InquiryMonthly.ValAdd:行38、列1 Trigger.FBR_AddValue_to_Accident:行5、列1 :[]Class.FBR_InquiryMonthly.testAMethod1:行54、列1

 

 

pls  help me my trigger test case  error. and the   should be  covered 75% the above code.

 

cheers

Pradeep

Hi,

 

This My trigger class,

 

global class FBR_ApexScheduleMonthClass Implements Schedulable
{
global void execute(SchedulableContext sc)
{
ValAdd();
}
public static void ValAdd()//Set<Id> InquiryId
{

List<FBR_Inquiry__c> Inquiry= [SELECT KPIInquiryContent__c,CommodityName__c,ModifyDate__c,Status__c from FBR_Inquiry__c ];
{
FBR_Inquiry__c FBR= Inquiry[0];
Date startDate=FBR.ModifyDate__c.toStartOfMonth();
Date endDate=FBR.ModifyDate__c.toStartOfMonth().addMonths(1);

LIST<AggregateResult> countmonth=[SELECT count(KPIInquiryContent__c) coun from FBR_Inquiry__c where ModifyDate__c >= :startDate AND ModifyDate__c < :endDate and PayoffObject__c=:'○' and Status__c IN('対応中' ,'対応完了')];
//LIST<AggregateResult> calmonth=[Select CALENDAR_MONTH(WorkDate__c), count(ImportCount__c) icount from WorkResultsMonth__c where Account_Name__c=:acname GROUP BY CALENDAR_MONTH(WorkDate__c)];
LIST<AggregateResult> calmonth=[Select count(ImportCount__c) icount from WorkResultsMonth__c where WorkDate__c >= :startDate and WorkDate__c < :endDate ];

List<KPIAccident__c> acc= [SELECT MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c ];
if(!acc.isEmpty() )
{

KPIAccident__c accupdate = acc[0];
Integer totalcountmonth=Integer.Valueof(countmonth[0].get('coun'));

accupdate.MonthlyGeneratedCount__c=totalcountmonth;

Integer totalmonthwork= Integer.Valueof(calmonth[0].get('icount'));
accupdate.MonthlyPPM__c=(totalmonthwork/totalcountmonth*1000000);
update accupdate;
}else
{
KPIAccident__c kpi = new KPIAccident__c();
List<KPIAccident__c> ToUpdate = new List<KPIAccident__c>();
// kpi.Date__c=FBR.ModifyDate__c;
//kpi.Account__c=FBR.KPIInquiryContent__r.Account__c;
// kpi.itemname__c= FBR.CommodityName__c;

Integer totalcountmonths=Integer.Valueof(countmonth[0].get('coun'));
kpi.MonthlyGeneratedCount__c=totalcountmonths;
Integer totalmonthworks= Integer.Valueof(calmonth[0].get('icount'));

kpi.MonthlyPPM__c=(totalmonthworks/totalcountmonths*1000000);
ToUpdate.add(kpi);
insert ToUpdate;

}
}
} }

 

 

test case of trigger monthly

 

 

mytest case

 

 

@isTest(SeeAllData=true)
public class FBR_InquiryMonthlyTest
{


public static testMethod void testAMethod1(){
//FBR_ApexScheduleMonthClass f1=new FBR_ApexScheduleMonthClass ();
try
{
Test.startTest();

FBR_ApexScheduleMonthClass.ValAdd();

 

WorkResultsMonth__c f2=new WorkResultsMonth__c ();
f2.name='Test';
//2.ImportCount=15;

f2.ImportCount__c=100;
insert f2;

LIST<FBR_Inquiry__c> cc=new List<FBR_Inquiry__c>();
Date startDate=date.parse('9/09/2012');
Date endDate=date.parse('19/09/2012');

FBR_Inquiry__c m1=new FBR_Inquiry__c();
m1.CommodityName__c='rakuten123';
m1.ModifyDate__c=date.parse('07/09/2012');
m1.KPIInquiryContent__c='one';
cc.add(m1);
insert cc;
List<KPIAccident__c > ss=new List<KPIAccident__c >();
integer dTotalForAll = 12;
integer TotalCounts=251;


KPIAccident__c m2= new KPIAccident__c();
m2.Name='rakuten123' ;

Integer totalcountmonth=dTotalForAll;
m2.MonthlyGeneratedCount__c=totalcountmonth;
Integer totalmonthwork=TotalCounts;
m2.MonthlyPPM__c=(totalmonthwork/totalcountmonth*1000000);

insert ss;


KPIAccident__c kpi = new KPIAccident__c();

// kpi.Date__c=FBR.ModifyDate__c;
//kpi.Account__c=FBR.KPIInquiryContent__r.Account__c;
// kpi.itemname__c= FBR.CommodityName__c;

Integer totalcountmonths=dTotalForAll;
kpi.MonthlyGeneratedCount__c=m2.MonthlyGeneratedCount__c;
Integer totalmonthworks= TotalCounts;

kpi.MonthlyPPM__c=m2.MonthlyPPM__c;

insert kpi;

}
catch(Exception e){}
Test.stopTest();
}


}

 

The above Red mark is not Covering the my Test case.Now i covered test 57%. can any one help me the else condition of the test case.

 

cheers

Pradeep kumar.p

 

global class Monthly{
 
    public  static void ValAdd()//Set<Id> InquiryId
  {  
  
List<Inquiry__c> Inquiry= [SELECT KPIInquiryContent__c,KPIInquiryContent__r.Account__c,CommodityName__c,ModifyDate__c,Status__c from Inquiry__c  ];
{
Inquiry__c Fr= Inquiry[0];
Date startDate=fr.ModifyDate__c.toStartOfMonth();
Date endDate=fr.ModifyDate__c.toStartOfMonth().addMonths(1);
 
LIST<AggregateResult> countmonth=[SELECT count(KPIInquiryContent__c) coun from Inquiry__c where KPIInquiryContent__r.Account__c=:fr.KPIInquiryContent__r.Account__c and ModifyDate__c >= :startDate AND ModifyDate__c < :endDate and PayoffObject__c=:'○' and Status__c IN('対応中' ,'対応完了')];
 //LIST<AggregateResult> calmonth=[Select CALENDAR_MONTH(WorkDate__c), count(ImportCount__c) icount from WorkResultsMonth__c where Account_Name__c=:acname GROUP BY CALENDAR_MONTH(WorkDate__c)];
LIST<AggregateResult> calmonth=[Select count(ImportCount__c) icount from WorkResultsMonth__c where WorkDate__c >= :startDate and WorkDate__c < :endDate and Account_Name__c=:fr.KPIInquiryContent__r.Account__c];
 
List<KPIAccident__c> acc= [SELECT Date__c,MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c where  Account_Name__c=:fr.KPIInquiryContent__r.Account__c and Date__c >= :startDate and Date__c < :endDate]; //     
if(!acc.isEmpty() )
      {
          
          KPIAccident__c accupdate = acc[0];         
          Integer totalcountmonth=Integer.Valueof(countmonth[0].get('coun')); 
          
          accupdate.MonthlyGeneratedCount__c=totalcountmonth;   
         
          Integer totalmonthwork= Integer.Valueof(calmonth[0].get('icount'));
          accupdate.MonthlyPPM__c=((totalmonthwork/totalcountmonth)*1000000);
          update accupdate;
      }else 
      {
         KPIAccident__c kpi = new KPIAccident__c();
         List<KPIAccident__c> ToUpdate = new List<KPIAccident__c>(); 
         kpi.Date__c=fr.ModifyDate__c;         
          kpi.Account__c=fr.KPIInquiryContent__r.Account__c;         
         kpi.itemname__c= fr.CommodityName__c;     
         
         Integer totalcountmonths=Integer.Valueof(countmonth[0].get('coun'));
         kpi.MonthlyGeneratedCount__c=totalcountmonths; 
         Integer totalmonthworks= Integer.Valueof(calmonth[0].get('icount'));
                    
         kpi.MonthlyPPM__c=((totalmonthworks/totalcountmonths)*1000000);
         ToUpdate.add(kpi);
         insert ToUpdate;
 
}
 }}
Pls help me apex scheduler class create  depending upon above code .
cheers
Pradeep

 

 

 

Hi  SFDL,

 

my code: 
 
public class login
{
public String currentUserProf { get; set; }
public String profilename { get; set; }
String name='System Administrator';

public String isAdmin()


{
return null;
}
String profileId= UserInfo.getProfileId();
boolean isAdmin=false;
Profile currentUserProf= [select name from Profile where id =:profileId limit 1];

if(currentUserProf==NULL)
{
isAdmin=false;
else
isAdmin=true;
if(currentUserProf.name.equalsIgnoreCase('System Administrator'))
System.debug('System Administrator');
else
if(currentUserProf.name.equalsIgnoreCase('RSL gold partner user'))
System.debug('RSL gold partner user');
else
if(currentUserProf.name.equalsIgnoreCase('RSL gold partner manager user'))
{
System.debug'(RSL gold partner manager user');


}
 }
}
my vf page:
 
<apex:page controller="login">
<apex:outputLabel value="U R Admin" rendered="{isAdmin()}"/>
<apex:outputLabel value="U RませAdmin" rendered="{NOTIsAdmin()}"/> </頂点:ページ>

 

 

.How to write the  parameter  passing in this method of apex class (like IsProfile(String profilename))..it displays profile User name details like ('System Adminstrator of debug console)  .By using if else condition.

 

 

Thanks

Pradeep

 

can i help with csv file uploading encoding format this file
NameDate__cUnit__cImportCount__cAccount_Name__c
プラディープ8/7/2012プラディープ13プラディープ
高価な8/7/2012高価な11高価な 
ディネッシュ7/8/2012ディネッシュ12ディネッシュ
フェリックス8/1/2012フェリックス8フェリックス
      

 

 

Actually my code same as this web site :http://www.forcetree.com/2010/08/read-and-insert-records-from-csv-file.html. when i uploaded this file: 
BLOB is not a valid UTF-8 string

Error is in expression '{!ReadFile}' in component <apex:page> in page fbr_fileuploader.
Because i have japenese  words in  csv file.
 
NameDate__cUnit__cImportCount__cAccount_Name__c
プラディープ8/7/2012プラディープ13プラディープ
高価な8/7/2012高価な11高価な 
ディネッシュ7/8/2012ディネッシュ12ディネッシュ
フェリックス8/1/2012フェリックス8フェリックス
      

 

 

Actually my code same as this web site :http://www.forcetree.com/2010/08/read-and-insert-records-from-csv-file.html. when i uploaded this file: 
BLOB is not a valid UTF-8 string

Error is in expression '{!ReadFile}' in component <apex:page> in page fbr_fileuploader.
Because i have japenese  words in  csv file.
 

public with sharing class Pagings{

public String pb { get; set; }
Public Integer noOfRecords{get; set;}
Public Integer size{get;set;}
public string sortingstring{get;set;}
public string sortingcolumn{get;set;}
public string errormsg{get;set;}
public string queryString = 'Select Name, Type from Account order by Name' ;

public String sortDirection
{
get;
set;
}

public integer getpage{
get{
integer i;

if(math.mod(noOfRecords,size)==0)
{
i=noOfRecords/size;
}else
{
i=noOfRecords/size+1;
}
return i;
}

set;}


public ApexPages.StandardSetController setCon {
get{
if(setCon == null){
size =10;
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);

noOfRecords = setCon.getResultSize();
if(noOfRecords ==0)
{
errormsg='No records to display';
}
else{
errormsg='';
}


}
return setCon;
}set;
}

public pageReference getquery()
{

if(sortingstring=='others')
{
queryString = 'Select Name, Type from Account where Name not like \''+sortingstring+'%\' order by Name';
}else if(sortingstring=='all' || sortingstring==null)
{
queryString = 'Select Name, Type from Account order by Name';
}else {
queryString = 'Select Name, Type from Account where Name like \''+sortingstring+'%\' order by Name';
}

if(sortingcolumn=='Name' || sortingcolumn=='Type')
{
sortDirection=sortDirection=='ASC' ? 'DESC' : 'ASC';
string sortFullExp = sortingcolumn + ' ' + sortDirection;
if(sortingstring!='all' && sortingstring!=null)
{
queryString = 'Select Name, Type from Account where Name like \''+sortingstring+'%\' order by ' + sortFullExp ;
}else
{
queryString = 'Select Name, Type from Account order by ' + sortFullExp ;
}

}
setCon = null;
getAccounts();
setCon.setPageNumber(1);
return null;

}


Public List<Account> getAccounts(){
List<Account> accList = new List<Account>();
for(Account a : (List<Account>)setCon.getRecords())
accList.add(a);
return accList;
}

public pageReference refresh() {

//Vary in displaying records according to the selected size
if( size ==10)
{try{
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size); }
catch(Exception e) {}
}
if( size ==25)
{
try{
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);}
catch(Exception e) {}} }
if( size ==50)
{try{
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size); }
catch(Exception e) {}
}
if( size ==100)
{try{
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size); }
catch(Exception e) {}
}if(size ==200)
{
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);
}
return null;

}

}

 

Can i  have test case for the above pagination class.

Hi All,

 

My requirement ,  how  to update the cases tab of  the field values update  for my chatter display in salesforce by using salesforce chatter. ple guidance the given requirement  with following steps

 

 

cheers

 

Pradeep P

Hi All,

 

How to install the Project /Issue Management in saleforce. by using appexchange .can any body help another way to install

the project /Issue Management .wht purpose and wht usage.

 

 

cheers

 

Pradeep.p

Hi all,

 

can help me test case of  my trigger .

 

This is trigger code,

 

 

global class Monthly{

public static void ValAdd()//Set<Id> InquiryId
{

List<Inquiry__c> Inquiry= [SELECT KPIInquiryContent__c,KPIInquiryContent__r.Account__c,CommodityName__c,ModifyDate__c,Status__c from Inquiry__c ];
{
Inquiry__c Fr= Inquiry[0];
Date startDate=fr.ModifyDate__c.toStartOfMonth();
Date endDate=fr.ModifyDate__c.toStartOfMonth().addMonths(1);

LIST<AggregateResult> countmonth=[SELECT count(KPIInquiryContent__c) coun from Inquiry__c where KPIInquiryContent__r.Account__c=:fr.KPIInquiryContent__r.Account__c and ModifyDate__c >= :startDate AND ModifyDate__c < :endDate and PayoffObject__c=:'○' and Status__c IN('対応中' ,'対応完了')];
//LIST<AggregateResult> calmonth=[Select CALENDAR_MONTH(WorkDate__c), count(ImportCount__c) icount from WorkResultsMonth__c where Account_Name__c=:acname GROUP BY CALENDAR_MONTH(WorkDate__c)];
LIST<AggregateResult> calmonth=[Select count(ImportCount__c) icount from WorkResultsMonth__c where WorkDate__c >= :startDate and WorkDate__c < :endDate and Account_Name__c=:fr.KPIInquiryContent__r.Account__c];

List<KPIAccident__c> acc= [SELECT Date__c,MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c where Account_Name__c=:fr.KPIInquiryContent__r.Account__c and Date__c >= :startDate and Date__c < :endDate]; //
if(!acc.isEmpty() )
{

KPIAccident__c accupdate = acc[0];
Integer totalcountmonth=Integer.Valueof(countmonth[0].get('coun'));

accupdate.MonthlyGeneratedCount__c=totalcountmonth;

Integer totalmonthwork= Integer.Valueof(calmonth[0].get('icount'));
accupdate.MonthlyPPM__c=((totalmonthwork/totalcountmonth)*1000000);
update accupdate;
}else
{
KPIAccident__c kpi = new KPIAccident__c();
List<KPIAccident__c> ToUpdate = new List<KPIAccident__c>();
kpi.Date__c=fr.ModifyDate__c;
kpi.Account__c=fr.KPIInquiryContent__r.Account__c;
kpi.itemname__c= fr.CommodityName__c;

Integer totalcountmonths=Integer.Valueof(countmonth[0].get('coun'));
kpi.MonthlyGeneratedCount__c=totalcountmonths;
Integer totalmonthworks= Integer.Valueof(calmonth[0].get('icount'));

kpi.MonthlyPPM__c=((totalmonthworks/totalcountmonths)*1000000);
ToUpdate.add(kpi);
insert ToUpdate;

}
}
}}

 

 

 

 

my test case code is:

 

static testMethod void testAMethod1()
{
Test.startTest();
Account a2 = new Account();
a2.name='pradeep';
insert a2;
Inquiry__c f1=new Inquiry__c(CommodityName__c='pradeep',ModifyDate__c=date.parse('03/09/2012'),Status__c ='good');
insert f1;
List<KPIAccident__c> ac2=[SELECT Date__c,MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c];

if(ac2.isEmpty())
{

KPIAccident__c m5=ac2[0];
m5.MonthlyGeneratedCount__c= 129;
m5.MonthlyPPM__c=2563;
//m5.Date__c=f1.ModifyDate__c;
insert m5;
}
else
{
List<KPIAccident__c> listEt = new List<KPIAccident__c>();
KPIAccident__c d1=new KPIAccident__c ();
d1.MonthlyGeneratedCount__c=145;
d1.MonthlyPPM__c=2569;
listEt.add(d1);
try
{
insert listEt;
}
catch(Exception e){}
Test.stopTest();

}
}
82 }

 

my trigger is:

 

trigger AddValue_to_Accident on Inquiry__c (after insert,after update)

{

Monthly.ValAdd();
}

 

 

 

 

 

The above red mark not coverage of my test case of trigger. The tese case was written but it should be coverage 61%.The red mark data not covered.  pls help me my test case of trigger..

 

 

If my  test case in build of trigger. it should be covered in 65% but an error is

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, FBR_AddValue_to_Accident: execution of AfterInsert caused by: System.ListException: List index out of bounds: 0 Class.FBR_InquiryMonthly.ValAdd: line 38, column 1 Trigger.FBR_AddValue_to_Accident: line 5, column 1: []. 

 

can any help me  test case of trigger and solution of error.

 

Cheers

Pradeep Kumar.p

 

 

 

Hi,

 

This My trigger class,

 

global class FBR_ApexScheduleMonthClass Implements Schedulable
{
global void execute(SchedulableContext sc)
{
ValAdd();
}
public static void ValAdd()//Set<Id> InquiryId
{

List<FBR_Inquiry__c> Inquiry= [SELECT KPIInquiryContent__c,CommodityName__c,ModifyDate__c,Status__c from FBR_Inquiry__c ];
{
FBR_Inquiry__c FBR= Inquiry[0];
Date startDate=FBR.ModifyDate__c.toStartOfMonth();
Date endDate=FBR.ModifyDate__c.toStartOfMonth().addMonths(1);

LIST<AggregateResult> countmonth=[SELECT count(KPIInquiryContent__c) coun from FBR_Inquiry__c where ModifyDate__c >= :startDate AND ModifyDate__c < :endDate and PayoffObject__c=:'○' and Status__c IN('対応中' ,'対応完了')];
//LIST<AggregateResult> calmonth=[Select CALENDAR_MONTH(WorkDate__c), count(ImportCount__c) icount from WorkResultsMonth__c where Account_Name__c=:acname GROUP BY CALENDAR_MONTH(WorkDate__c)];
LIST<AggregateResult> calmonth=[Select count(ImportCount__c) icount from WorkResultsMonth__c where WorkDate__c >= :startDate and WorkDate__c < :endDate ];

List<KPIAccident__c> acc= [SELECT MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c ];
if(!acc.isEmpty() )
{

KPIAccident__c accupdate = acc[0];
Integer totalcountmonth=Integer.Valueof(countmonth[0].get('coun'));

accupdate.MonthlyGeneratedCount__c=totalcountmonth;

Integer totalmonthwork= Integer.Valueof(calmonth[0].get('icount'));
accupdate.MonthlyPPM__c=(totalmonthwork/totalcountmonth*1000000);
update accupdate;
}else
{
KPIAccident__c kpi = new KPIAccident__c();
List<KPIAccident__c> ToUpdate = new List<KPIAccident__c>();
// kpi.Date__c=FBR.ModifyDate__c;
//kpi.Account__c=FBR.KPIInquiryContent__r.Account__c;
// kpi.itemname__c= FBR.CommodityName__c;

Integer totalcountmonths=Integer.Valueof(countmonth[0].get('coun'));
kpi.MonthlyGeneratedCount__c=totalcountmonths;
Integer totalmonthworks= Integer.Valueof(calmonth[0].get('icount'));

kpi.MonthlyPPM__c=(totalmonthworks/totalcountmonths*1000000);
ToUpdate.add(kpi);
insert ToUpdate;

}
}
} }

 

 

test case of trigger monthly

 

 

mytest case

 

 

@isTest(SeeAllData=true)
public class FBR_InquiryMonthlyTest
{


public static testMethod void testAMethod1(){
//FBR_ApexScheduleMonthClass f1=new FBR_ApexScheduleMonthClass ();
try
{
Test.startTest();

FBR_ApexScheduleMonthClass.ValAdd();

 

WorkResultsMonth__c f2=new WorkResultsMonth__c ();
f2.name='Test';
//2.ImportCount=15;

f2.ImportCount__c=100;
insert f2;

LIST<FBR_Inquiry__c> cc=new List<FBR_Inquiry__c>();
Date startDate=date.parse('9/09/2012');
Date endDate=date.parse('19/09/2012');

FBR_Inquiry__c m1=new FBR_Inquiry__c();
m1.CommodityName__c='rakuten123';
m1.ModifyDate__c=date.parse('07/09/2012');
m1.KPIInquiryContent__c='one';
cc.add(m1);
insert cc;
List<KPIAccident__c > ss=new List<KPIAccident__c >();
integer dTotalForAll = 12;
integer TotalCounts=251;


KPIAccident__c m2= new KPIAccident__c();
m2.Name='rakuten123' ;

Integer totalcountmonth=dTotalForAll;
m2.MonthlyGeneratedCount__c=totalcountmonth;
Integer totalmonthwork=TotalCounts;
m2.MonthlyPPM__c=(totalmonthwork/totalcountmonth*1000000);

insert ss;


KPIAccident__c kpi = new KPIAccident__c();

// kpi.Date__c=FBR.ModifyDate__c;
//kpi.Account__c=FBR.KPIInquiryContent__r.Account__c;
// kpi.itemname__c= FBR.CommodityName__c;

Integer totalcountmonths=dTotalForAll;
kpi.MonthlyGeneratedCount__c=m2.MonthlyGeneratedCount__c;
Integer totalmonthworks= TotalCounts;

kpi.MonthlyPPM__c=m2.MonthlyPPM__c;

insert kpi;

}
catch(Exception e){}
Test.stopTest();
}


}

 

The above Red mark is not Covering the my Test case.Now i covered test 57%. can any one help me the else condition of the test case.

 

cheers

Pradeep kumar.p

 

global class Monthly{
 
    public  static void ValAdd()//Set<Id> InquiryId
  {  
  
List<Inquiry__c> Inquiry= [SELECT KPIInquiryContent__c,KPIInquiryContent__r.Account__c,CommodityName__c,ModifyDate__c,Status__c from Inquiry__c  ];
{
Inquiry__c Fr= Inquiry[0];
Date startDate=fr.ModifyDate__c.toStartOfMonth();
Date endDate=fr.ModifyDate__c.toStartOfMonth().addMonths(1);
 
LIST<AggregateResult> countmonth=[SELECT count(KPIInquiryContent__c) coun from Inquiry__c where KPIInquiryContent__r.Account__c=:fr.KPIInquiryContent__r.Account__c and ModifyDate__c >= :startDate AND ModifyDate__c < :endDate and PayoffObject__c=:'○' and Status__c IN('対応中' ,'対応完了')];
 //LIST<AggregateResult> calmonth=[Select CALENDAR_MONTH(WorkDate__c), count(ImportCount__c) icount from WorkResultsMonth__c where Account_Name__c=:acname GROUP BY CALENDAR_MONTH(WorkDate__c)];
LIST<AggregateResult> calmonth=[Select count(ImportCount__c) icount from WorkResultsMonth__c where WorkDate__c >= :startDate and WorkDate__c < :endDate and Account_Name__c=:fr.KPIInquiryContent__r.Account__c];
 
List<KPIAccident__c> acc= [SELECT Date__c,MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c where  Account_Name__c=:fr.KPIInquiryContent__r.Account__c and Date__c >= :startDate and Date__c < :endDate]; //     
if(!acc.isEmpty() )
      {
          
          KPIAccident__c accupdate = acc[0];         
          Integer totalcountmonth=Integer.Valueof(countmonth[0].get('coun')); 
          
          accupdate.MonthlyGeneratedCount__c=totalcountmonth;   
         
          Integer totalmonthwork= Integer.Valueof(calmonth[0].get('icount'));
          accupdate.MonthlyPPM__c=((totalmonthwork/totalcountmonth)*1000000);
          update accupdate;
      }else 
      {
         KPIAccident__c kpi = new KPIAccident__c();
         List<KPIAccident__c> ToUpdate = new List<KPIAccident__c>(); 
         kpi.Date__c=fr.ModifyDate__c;         
          kpi.Account__c=fr.KPIInquiryContent__r.Account__c;         
         kpi.itemname__c= fr.CommodityName__c;     
         
         Integer totalcountmonths=Integer.Valueof(countmonth[0].get('coun'));
         kpi.MonthlyGeneratedCount__c=totalcountmonths; 
         Integer totalmonthworks= Integer.Valueof(calmonth[0].get('icount'));
                    
         kpi.MonthlyPPM__c=((totalmonthworks/totalcountmonths)*1000000);
         ToUpdate.add(kpi);
         insert ToUpdate;
 
}
 }}
Pls help me apex scheduler class create  depending upon above code .
cheers
Pradeep