• deepakM
  • NEWBIE
  • 100 Points
  • Member since 2012

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

hi everyone

 

i need to cover the below lines but unable to do that.

 

The code is as follows:

Webservice static string Submit(string oppId)
{

 

string message = '';
boolean flag = true;

 

Flight_Request__c[] tf = [SELECT id,Customer_Approved_Itinerary__c,Opportunity__c FROM Flight_Request__c WHERE Opportunity__c = :oppId and Customer_Approved_Itinerary__c = true ];
if (tf.size() != 1)
{
message += 'Flight Request must contain only one record with Customer Approved Itinerary true \n';
flag = false;
}

 

}

 

 

My Test class method

 

static testMethod void myUnitTest() {

string message = '';
boolean flag = true;

 

Flight_Request__c fr = new Flight_Request__c();
fr.Budget__c = '23';
fr.Publish_Fare__c = '35';
fr.Flight_Itinerary_Name__c ='Test';
fr.Opportunity__c = opp.Id;
fr.From__c = opp.Origin_City__c;
fr.To__c = opp.Destination_City__c;
fr.Outbound_del__c = opp.Departure_Date__c;
fr.Pax_del__c = opp.Number_of_Passengers__c;
fr.Region_del__c = opp.Destination_Zone__c;
fr.Inbound_del__c = opp.Return_Date__c;
fr.Outbound_Flexibility__c = opp.Flexibility_From__c;
fr.Inbound_Flexibility__c = opp.Flexibility_To__c;
fr.Email_To__c ='anil@swiftsetup.com';
fr.Email_Content__c= 'Test';
fr.Subject__c ='subject test';
fr.Customer_Approved_Itinerary__c = true;
fr.Flight_Info__c = 'Test';
fr.Searcher_New__c ='Anil D';
fr.Email_Cc__c ='dm@we.com';
fr.Email_Bcc__c ='anil@we.com';
insert fr;

 

 

}

 

but it not coverd the above red lines.

 

please guide me.

 

Thanks

  • September 28, 2012
  • Like
  • 0

Hi everyone,

 

I have one sys admin login and other is enduser login.suppose if sysadmin changes the opportunity stage to "completed" thn the enduser unable to change the stage, that i did using validation rule but i need that if the opportunity stage is "completed" the enduser unable to edit the opportunity data mean other fields too. i did it using the validatin rule that is stage is completed and user is not other thn sys admin thn we can not edit the opportunity ,as opp consist of various related list(many obj related to opp) so i did again  same for these objects also.

 

i need to knw is there any other way too handle this thing in salesforce. so if the opp stage is completed then the enduser unable to change the opp data as well as its related list too.

 

 

Thanks

 

 

  • September 26, 2012
  • Like
  • 0

hi everyone

 

From last fews days i am trying to deploy a class with good test coverge but i unable to achieve that.

 

pleas help me to get the best code coverage as i tried to fix all the point in test case but even though i fail to do so.

 

 

My apex class is shown below and red lines are not coverd.

 

public class FFPage {

FF__c FF;
public List<Opportunity> listOpp;
public String Id {get; set;}
public Opportunity Opp {get; set;}
public String Msg {get; set;}
public boolean chkConfirm {get;set;}
public boolean chkAcct {get;set;}
public static boolean isApexTest = false;
//boolean flag = false;
public FFPage(ApexPages.StandardController stdController)
{
FF = (FF__c)stdController.getRecord();
Id = FF.Opportunity__c;

}

public PageReference Save()
{
chkConfirm = false;
chkAcct = false;
Msg = Apexpages.currentPage().getParameters().get('one');
System.debug('*************Msg************ : ' + Msg );


try
{

if(FF.Id == null)
{
string obj = main(FF.Opportunity__c,FF.Id,FF.FFGuid__c,FF.Account_Number__c,FF.Account_Type__c,FF.Last_Name__c,FF.Miles__c,FF.Password__c,'add',Msg );
// if(obj.contains('success'))
System.debug('*************RailMsgobj*********'+obj);
if(obj.contains('success')|| obj=='success')
{
System.debug('*************Railsobj*********'+obj);
string[] parts = obj.split(',');
if(parts.size()>1)
{
FF.FFGuid__c = parts[1];
}
System.debug('*************Guid*********'+FF.FFGuid__c);
insert FF;
System.debug('insert');
// ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, parts[0]));
PageReference pr = new PageReference('https://c.cs9.visual.force.com/apex/FFPage?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
pr.setRedirect(true);
pr.getParameters().put('paramName', 'Saved Successfully');
return pr;

}
else
{
System.debug('notinsert');
// obj == 'Not enough miles in account';
//chkConfirm = true;
if(obj.contains('Not enough miles in account')|| obj=='Not enough miles in account')
{
chkConfirm = true;
}
else if(obj.contains('Account does not exist')|| obj=='Account does not exist')
{
System.debug('*************AccountNot*********'+obj);
chkAcct = true;
}
else
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING,obj));
}


}

}
else
{
string userID;
userID = userinfo.getProfileId();
userID = userID.substring(0,15);
System.debug('*************LoginuserID *********'+userID );
Decimal miles;
if(userID != '00ed0000000vQrA')
{

Opportunity opp = [SELECT id, StageName FROM Opportunity WHERE Id = :FF.Opportunity__c];

if(opp .StageName == 'Completed')
{
FF__c ffobj = [SELECT id, Miles__c FROM FF__c WHERE Id = :FF.id];
if(ffobj != null)
{
if(ffobj.Miles__c != null)
{
miles = ffobj .Miles__c;
}
}
}
else
{
miles = FF.Miles__c;

}

}
else
{
miles = FF.Miles__c;

}
System.debug('*************NewMiles*********'+miles );

string obj = main(FF.Opportunity__c,FF.Id,FF.FFGuid__c,FF.Account_Number__c,FF.Account_Type__c,FF.Last_Name__c,miles,FF.Password__c,'update',Msg);
if(obj.contains('success')|| obj=='success')
{
string[] parts = obj.split(',');
if(parts.size()>1)
{
FF.FFGuid__c = parts[1];
}
System.debug('*************Guidupdate*********'+FF.FFGuid__c);
try
{
update FF;
System.debug('update');
//ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, obj));
PageReference pr = new PageReference('https://c.cs9.visual.force.com/apex/FFPage?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
pr.setRedirect(true);
pr.getParameters().put('paramName', 'Updated Successfully');
return pr;

}
catch(Exception e)
{
string expmsg = e.getMessage();
System.debug(expmsg);
if(expmsg.contains('FIELD_CUSTOM_VALIDATION_EXCEPTION, Opportunity is closed,You cannot edit the MIles.'))
{

System.debug('DmlException');
// ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Opportunity is closed,You cannot edit the MIles'));
PageReference pr = new PageReference('https://c.cs9.visual.force.com/apex/FFPage?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
pr.setRedirect(true);
pr.getParameters().put('paramName', 'Opportunity is closed,You cannot edit the MIles');
return pr;
}
}

}
else
{
System.debug('notupdate');
if(obj.contains('Not enough miles in account')|| obj=='Not enough miles in account')
{
chkConfirm = true;
}
else if(obj.contains('Account does not exist')|| obj=='Account does not exist')
{
chkAcct = true;
}
else
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, obj));
}
//PageReference pr = new PageReference('https://c.na14.visual.force.com/apex/FFPage?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
// pr.setRedirect(true);
// pr.getParameters().put('paramName', obj);
// return pr;
}



}



}

catch(DmlException ex)
{

}
return null;
}
public String main(String opid,String ffid,String guid,String actnu,String acttype,String lastn,Decimal miles,String pwd,String action,String Chkmiles)
{

SalesForceUrl__c sf = SalesForceUrl__c.getValues('AMUrl');
SalesForceUrl__c sf2 = SalesForceUrl__c.getValues('IsSandBox');
// Do a whole bunch of stuff

// Build the http request
HttpRequest req = new HttpRequest();
Http h = new Http();

if( sf != null && sf2!= null)
{
req.setEndpoint(sf.SettingValue__c+'/salesforce/test?oppid='+ opid+'&ffid='+ffid+'&guid='+guid +'&acctnu='+actnu +'&accttype='+acttype+'&lastname='+lastn+'&miles='+miles+'&pwd='+pwd+'&actionType='+action+'&IsSandbox='+sf2.SettingValue__c+'&Chkmiles='+Msg);

}
req.setMethod('GET');

// Invoke web service call
String result = '';
if (!isApexTest){
// Make a real callout since we are not running a test
HttpResponse res = h.send(req);
result = res.getBody();
System.debug('Result=' +result);
System.debug('STATUS:'+res.getStatus());
} else {
// A test is running
result = 'success';
}

// Do whole bunch of stuff

return result;
}


// Wrapper method for "main" that we will call in the Test Class
public String mainForTest(){
isApexTest = true;
DateTime dT = System.now();
Decimal i = 1.2;
return main('006d0000007jfwO','a00d000000560NZ','a00d000000560NZ','11','AA','aa',i,'asd','add','true');
}
public PageReference Cancel()
{

PageReference pr = new PageReference('/' + Id);
pr.setRedirect(true);
return pr;
}
}

 

 

 

 

MY Test Class is 

 

 

 

@isTest
private class FFPageTestCase {

static testMethod void myUnitTest() {
FF__c FF;
List<Opportunity> listOpp;
List<FF__c> listFF;
String Id;
String result;
String webresult;
String webresultu;

string obj = '';
List<String> parts;


Opportunity opp = new Opportunity();
opp.Name = 'Test Opp';
opp.StageName = 'Ticketing';
opp.p1_First_Name__c ='A';
opp.p1_Last_Name__c ='D';
opp.p1_Gender__c = 'S';
opp.p1_First_Name__c ='S';
opp.p1_Last_Name__c ='A';
opp.p1_Gender__c = 'D';
opp.DOB_Main_Passenger__c = System.now().date();
opp.Number_of_Passengers__c = 4;
opp.CloseDate = System.now().date();
opp.Departure_Date__c = System.now().date();
opp.Origin_City__c = 'DEL';
opp.Destination_City__c= 'MUI';
opp.Return_Date__c = System.now().date();
opp.Override_Itinerary_Builder__c = true;
opp.Complete_Itinerary_Information__c ='test';
opp.Approved__c ='Test1';
opp.AmMessage__c ='success';
insert opp;

FF = new FF__c();
FF.Account_Number__c ='1234456';
FF.Account_Type__c = 'ANA';
FF.DOB__c = system.today();
FF.Opportunity__c = opp.Id;
FF.Last_Name__c = 'Dutt';
FF.Miles__c = 1.2;
FF.Password__c= 'asd';
FF.Mileage_Cost__c = 0.0210;
FF.FFGuid__c ='hhhhdofhff';
webresult = 'success';
obj = 'Success,785765876';
parts = obj.split(',');
if(parts.size()>1)
{
FF.FFGuid__c = parts[1];
}

insert FF;
opp.StageName = 'FF Account Assigned';
update opp;


webresultu = 'success';
update FF;


try
{
ApexPages.StandardController sc = new ApexPages.StandardController(FF);
FFPage sc1 = new FFPage(sc);


String retVal = sc1.mainForTest();
// Add asserts for validation
String expectedResult = 'success';
System.assertEquals(retVal, expectedResult);
sc1.Save();


FF__c FF2 = new FF__c();
FF2.Account_Number__c ='1234456';
FF2.Account_Type__c = 'ANA';
FF2.DOB__c = system.today();
FF2.Opportunity__c = opp.Id;
FF2.Last_Name__c = 'Dutt';
FF2.Miles__c = 1.2;
FF2.Password__c= 'asd';
FF2.Mileage_Cost__c = 0.0210;
FF.FFGuid__c ='hhhhdofhff';
webresult = 'success';
insert FF2;

SalesForceUrl__c sf = new SalesForceUrl__c();
sf.Name ='AMUrl';
sf.SettingValue__c ='test';
insert sf;
SalesForceUrl__c sf2 = new SalesForceUrl__c();
sf2.Name ='IsSandBox';
sf2.SettingValue__c ='true';
insert sf2;
sc1.Cancel();
}

catch(System.CalloutException e)
{
webresult = e.getMessage();
}
System.assertEquals(webresult,'success');

}
}

 

 

 

 

Please help me to get rid of this.

 

thanks

 

 

  • September 21, 2012
  • Like
  • 0

Hi 

 

i have one command button "save" which return the apex message after the operation. i need to check for the particular message return.i.e

suppose below is my save button

 

<apex:pageMessages id="pmsg"/>

  <apex:commandButton value="Save"   action="{!Save}" />

 

which return the apex message. i need that if the message is" not enough value exist"

thn i need the confirmation box 

"are u sure want to create act thn click the ok "

 

if it click ok thn it redirect the action save again with the parameters as i did

 

<apex:actionFunction name="CallApexMethod" action="{!Save}">
<apex:param name="key" value="val"/>
</apex:actionFunction>

 

 

My Logic:

<apex:form id="form" >
<apex:pageBlock title="FF Info" id="pb">

<apex:pageMessages id="pmsg"/>

 <apex:commandButton value="Save"  onclick="CallApexMethod1();" oncomplete="Redirect();" />


 <apex:actionFunction name="CallApexMethod1" action="{!Save}"/>
<apex:actionFunction name="CallApexMethod" action="{!Save}">
<apex:param name="key" value="val"/>
</apex:actionFunction>

 

<script>


function Test()
{
alert("1");
CallApexMethod1();


}
function Redirect()
{
alert("2");

var msgval= document.getElementById("{!$Component.form.pb.pmsg}").innerText;
alert(msgval);
if(msgval =='Not enough miles in account')
{
if (confirm('There are not enough miles in that account. Are you sure you want to continue?'))
{
alert("3");
CallApexMethod() ;
}
}
alert("4");
}


</script>

 

</apex:form>

</apex:page>

 

 

But it not work. also the message is not compare.

 

 

In Nutshell :I have one button save on click it and it hit the http and i gt msg which i  print in  apex message. suppose i gt mesage "not enough"  thn i not save the data. but now i need that if  this msg comes a confrimation box will display if it click ok it saves othervwse not

 

please guid me if you get anything.

 

thanks

 

  • September 13, 2012
  • Like
  • 0

HI everyone.

 

i need to know how we can send a parameters to apex method .as my button like below

 

   <apex:commandButton action="{!save}" onclick="return confirm('are you sure?');" value="TSave" /> 

 

As when we hit the ok ,we need to send a parameter to the save action .

 

 

Please help me.

 

Thanks.

  • September 13, 2012
  • Like
  • 0

HI community.

 

I have one vf page related to custom object ff having Opportunity as a Master-Detail(Opportunity).

in vf page i have one inputtag as below

    <apex:inputField label="Opportunity" value="{!FF__c.Opportunity__c}"  />

 

during create ,textbox is open for opportunity abd during edit the readonly field,so in this cas i need it to a click able and redirect to opportunity page.
 
As i have one action in controller which work perfectly but i need it in opportunity case in edit mode.
 
 
Thanks
  • September 06, 2012
  • Like
  • 0

hi every one

 

i have two user.

1. admin

2. test

 

if the stage is completed then the user test unable to change the opportunity stage if the stage is "completed" only admin can change it.

For that i created the validation rule but it not work

 

AND ( 
ISPICKVAL(StageName, "Completed") 
, $User.ProfileId != "056560000666")

}

 

here this is admin prfofile id 056560000666.

 

But it not work.

 

please guide me.

 

thanks

  • September 05, 2012
  • Like
  • 0

HI everyone.

 

i have two custom objects named:

Airline,

Eticket.

In both the  custom object i used one picklist in each but having same values as like:

 

1. Object: Airline

Picklist name :Airline_name 

 

2. Object: Eticket

Picklist name:Airline_name 

 

 

I need that to be manage in one place, that if i change there it will depict in both the cases.

 

Please guide how can i get this common functionality work for both the custom objects.

 

 

Thanks

 

 

  • September 03, 2012
  • Like
  • 0

hi every one.

 

I need 100% code coverage for the class ,i tried to make a test class but it not covered 100%  just 70%

 

Below is my class as well as test class as under:

 

My Class

 

public class WebServiceSalesforceFeed{
@future (callout =true)
public static void HttpResult(String oppID) {
SalesForceUrl__c sf = SalesForceUrl__c.getValues('AMUrl'); // custom setting objects.
SalesForceUrl__c sf2 = SalesForceUrl__c.getValues('IsSandBox');
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
if(sf !=null && sf2!=null)

{
req.setEndpoint(sf.SettingValue__c+'/salesforce/SalesForceFeed?oppid='+oppID+'&IsSanbox='+sf2.SettingValue__c);
}

req.setMethod('GET');

try
{
res = http.send(req);
string result = res.getBody();
System.debug('STATUS:'+res.getStatus());
System.debug('STATUS_CODE:'+res.getStatusCode());

}
catch(System.CalloutException e)
{
System.debug('Callout error: '+ e);
System.debug(res.toString());
}

}

// run WebServiceCallout.testMe(); from Execute Anonymous to test
public static testMethod void testMe() {
WebServiceSalesforceFeed.HttpResult('006d0000006enVK');
}

}

 

 

The Test class

 

@isTest
private class WebServiceSalesFeedTest {

static testMethod void myUnitTest() {

Opportunity opp = new Opportunity();
opp.Name = 'Test Opp';
opp.StageName = 'To Be Searched';
opp.p1_First_Name__c ='A';
opp.p1_Last_Name__c ='D';
opp.p1_Gender__c = 'S';
opp.p1_First_Name__c ='S';
opp.p1_Last_Name__c ='A';
opp.p1_Gender__c = 'D';
opp.DOB_Main_Passenger__c = System.now().date();
opp.Number_of_Passengers__c = 4;
opp.CloseDate = System.now().date();
opp.Departure_Date__c = System.now().date();
opp.Origin_City__c = 'DEL';
opp.Destination_City__c= 'MUI';
opp.Return_Date__c = System.now().date();
opp.AmMessage__c ='testttt';

insert opp;

SalesForceUrl__c sf = new SalesForceUrl__c();
sf.Name ='AMUrl';
sf.SettingValue__c ='test';
insert sf;
SalesForceUrl__c sf2 = new SalesForceUrl__c();
sf2.Name ='IsSandBox';
sf2.SettingValue__c ='test';
insert sf2;

WebServiceSalesforceFeed obj = new WebServiceSalesforceFeed();
WebServiceSalesforceFeed.HttpResult(opp.Id);
WebServiceSalesforceFeed.testMe();
}
}

 

 

As this is custom setting object

 

 SalesForceUrl__c sf = new SalesForceUrl__c(); 

having SettingValue__c is custom fieild.

and two values Name = "amurl" and "SettingValue" having some value

 two values Name = "amurl" and "IsSandBox" having some value

,As i used this  in above code as shown in green line above.

 

 

Please guide me how can i achieve 100% for this class as it was about 80 % covered before i added green lines but i need this.

 

 

Thanks

 

 

 

 

Hi every one .

 

 i am getting the error  "System.NullPointerException:Attempt to de-reference a null object" while runing a test case.

 

The below is my Class: i am getting error in red line below:

 

public class FFtestPage {

FFtest__c FF;
public List<Opportunity> listOpp;
public String Id {get; set;}
public Opportunity Opp {get; set;}
public String Msg {get; set;}
public static boolean isApexTest = false;
//boolean flag = false;
public FFtestPage(ApexPages.StandardController stdController)
{
FF = (FFtest__c)stdController.getRecord();
Id = FF.Opportunity__c;

}

public PageReference Save()
{

try
{
if(FF.Id == null)
{
string obj = main(FF.Opportunity__c,FF.Id,FF.FFGuid__c,FF.Account_Number__c,FF.Account_Type__c,FF.Last_Name__c,FF.Miles__c,FF.Password__c,'add');
// if(obj.contains('success'))
if(obj.contains('success')|| obj=='success')
{
System.debug('*************Railsobj*********'+obj);
string[] parts = obj.split(',');
if(parts.size()>1)
{
FF.FFGuid__c = parts[1];
}
System.debug('*************Guid*********'+FF.FFGuid__c);
insert FF;
System.debug('insert');
// ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, parts[0]));
PageReference pr = new PageReference('https://c.cs9.visual.force.com/apex/FFTestPAge?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
pr.setRedirect(true);
pr.getParameters().put('paramName', 'Saved Successfully');
return pr;

}
else
{
System.debug('notinsert');
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, obj));
// PageReference pr = new PageReference('https://c.na14.visual.force.com/apex/FFPage?retURL='+Id);
//pr.setRedirect(true);
// pr.getParameters().put('paramName', obj);
// return pr;

}

}
else
{
string obj = main(FF.Opportunity__c,FF.Id,FF.FFGuid__c,FF.Account_Number__c,FF.Account_Type__c,FF.Last_Name__c,FF.Miles__c,FF.Password__c,'update');
if(obj.contains('success')|| obj=='success')
{
string[] parts = obj.split(',');
if(parts.size()>1)
{
FF.FFGuid__c = parts[1];
}
System.debug('*************Guidupdate*********'+FF.FFGuid__c);
update FF;
System.debug('update');
//ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, obj));
PageReference pr = new PageReference('https://c.na14.visual.force.com/apex/FFTestPAge?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
pr.setRedirect(true);
pr.getParameters().put('paramName', 'Updated Successfully');
return pr;
}
else
{
System.debug('notupdate');
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, obj));
//PageReference pr = new PageReference('https://c.na14.visual.force.com/apex/FFPage?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
// pr.setRedirect(true);
// pr.getParameters().put('paramName', obj);
// return pr;
}

}

}

catch(DmlException ex)
{

}
return null;
}
public String main(String opid,String ffid,String guid,String actnu,String acttype,String lastn,Decimal miles,String pwd,String action)
{

SalesForceUrl__c sf = SalesForceUrl__c.getValues('AMUrl');
SalesForceUrl__c sf2 = SalesForceUrl__c.getValues('IsSandBox');
// Do a whole bunch of stuff

// Build the http request
HttpRequest req = new HttpRequest();
Http h = new Http();
if(sf != null && sf2 != null)
{
req.setEndpoint(sf.SettingValue__c+'/Abc/test?oppid='+ opid+'&ffid='+ffid+'&guid='+guid +'&acctnu='+actnu +'&accttype='+acttype+'&lastname='+lastn+'&miles='+miles+'&pwd='+pwd+'&actionType='+action+'&IsSandbox='+sf2.SettingValue__c);
}
req.setMethod('GET');

// Invoke web service call
String result = '';
if (!isApexTest){
// Make a real callout since we are not running a test
HttpResponse res = h.send(req);
result = res.getBody();
System.debug('Result=' +result);
System.debug('STATUS:'+res.getStatus());
} else {
// A test is running
result = 'success';
}

// Do whole bunch of stuff

return result;
}


// Wrapper method for "main" that we will call in the Test Class
public String mainForTest(){
isApexTest = true;
DateTime dT = System.now();
Decimal i = 1.2;
return main('006d0000007jfwO','a00d000000560NZ','a00d000000560NZ','11','AA','aa',i,'asd','add');
}
public PageReference Cancel()
{

PageReference pr = new PageReference('/' + Id);
pr.setRedirect(true);
return pr;
}
}

 

 

My test Class is:

 

@isTest
private class FFtestPagetestcase {

static testMethod void myUnitTest() {
FFtest__c FF;
List<Opportunity> listOpp;
List<FFtest__c> listFF;
String Id;
String result;
String webresult;
String webresultu;

string obj = '';
List<String> parts;


Opportunity opp = new Opportunity();
opp.Name = 'Test Opp';
opp.StageName = 'Ticketing';
opp.p1_First_Name__c ='A';
opp.p1_Last_Name__c ='D';
opp.p1_Gender__c = 'S';
opp.p1_First_Name__c ='S';
opp.p1_Last_Name__c ='A';
opp.p1_Gender__c = 'D';
opp.DOB_Main_Passenger__c = System.now().date();
opp.Number_of_Passengers__c = 4;
opp.CloseDate = System.now().date();
opp.Departure_Date__c = System.now().date();
opp.Origin_City__c = 'DEL';
opp.Destination_City__c= 'MUI';
opp.Return_Date__c = System.now().date();
opp.Override_Itinerary_Builder__c = true;
opp.Complete_Itinerary_Information__c ='test';
opp.Approved__c ='Test1';
opp.AmMessage__c ='success';
insert opp;

FF = new FFtest__c();
FF.Account_Number__c ='1234456';
FF.Account_Type__c = 'ANA';
FF.DOB__c = system.today();
FF.Opportunity__c = opp.Id;
FF.Last_Name__c = 'Dutt';
FF.Miles__c = 1.2;
FF.Password__c= 'asd';
FF.FFGuid__c ='hhhhdofhff';
webresult = 'success';
obj = 'Success,785765876';
parts = obj.split(',');
if(parts.size()>1)
{
FF.FFGuid__c = parts[1];
}

insert FF;
opp.StageName = 'FF Account Assigned';
update opp;


webresultu = 'success';
update FF;

try
{
ApexPages.StandardController sc = new ApexPages.StandardController(FF);
FFtestPage sc1 = new FFtestPage(sc);


String retVal = sc1.mainForTest();
// Add asserts for validation
String expectedResult = 'success';
System.assertEquals(retVal, expectedResult);
sc1.Save();


FFtest__c FF2 = new FFtest__c();
FF2.Account_Number__c ='1234456';
FF2.Account_Type__c = 'ANA';
FF2.DOB__c = system.today();
FF2.Opportunity__c = opp.Id;
FF2.Last_Name__c = 'Dutt';
FF2.Miles__c = 1.2;
FF2.Password__c= 'asd';
FF.FFGuid__c ='hhhhdofhff';
webresult = 'success';
insert FF2;
SalesForceUrl__c sf = SalesForceUrl__c.getValues('AMUrl');
sf.Name='AMUrl';

insert sf;
SalesForceUrl__c sf2 = SalesForceUrl__c.getValues('IsSandBox');
sf2.Name='IsSandBox';

insert sf2;
sc1.Cancel();
}

catch(System.CalloutException e)
{
webresult = e.getMessage();
}
System.assertEquals(webresult,'success');

}
}

 

 

please guide me where i am going wrong.

 

 

thanks

HI everyone

 

i have one validation rule like below

 

MONTH(CloseDate) < MONTH(TODAY())

 

it works fine but i need it to fire only for a new opportunities not for old.

 

for that purose i did this

 

AND( 
Id =='0', 
MONTH(CloseDate) < MONTH(TODAY()) 

)

 

but it not work .

 

please guide me what can i do to achieve this.

 

 

Thanks.

 

I've been using databasedotcom to configure static data on my test sandboxes, and it's been working fine until recently.

 
What I've discovered is that if I refresh a sandbox now, the refreshed sandbox will reject databasedotcom with an "invalid password" error.
 
But the gem and program continue to work fine before refresh
 
Anyone else notice this?
 
 
thanks

hi every one 

 

i have one feild "closeddate__c".i need that Close Date not  to be earlier than current month.for that i used this 

CloseDate < TODAY()

 

but it dont allow the current mth also.As todaty is 8/29/2012 it not allow the   8/28/2012.

 

 

Please help me .

 

thanks

 

 

hi everyone.

 

Recently we are using the sandbox account and got error regarding external webrequest.like opportunity id is going blank. as it working fine in our production,but in sandbox envrionement when we request the webrequest and send the arguments, it goes null and cause error.

 

i didnt get wht it happen as it work fine in production,same object,call same httprequest request but parameters going  are null.

 

 

please help me .

 

 

thanks 

hi every one

 

i have one custom button on opportunity layout .i need to hide them from particular user.i have that user id.

 

how can i achieve this.

 

 

thanks.

HI every one

 

Few time ago i came to know about the sandbox.As what we do now just code in eclipse and push the data in production which creates very difficulty for us.as when in know about the sanbox that we can code in sandbox check the code ,test the code then deploy it in production , for that i created the sandbox account in salesforce which is i think is free but we need to access full functionality of the sandbox ,how can we do that .

 

please give me some sort of information so that i help me to get rid of the difficulty that comes during coding and developing.

 

 

thanks

 

 

 

hi everyone

 

 i have one field in opportunity named closed date(close__date)

and one related list payinfo (related to opportunity)

 

so if opp closed date is greater thn the system date then if user edit the tax field and amount feild of payinfo the validation fire and keep the user not to edit these fields.

 

Opportunity field = closed__date.

payinfo fields taxe__c,amount__c.

 

 

please help me.

 

thanks

hi every one.

 

i have one strange issue related to visualforce page in custom object. i post the similar kind of qus in my earlier post but this is littile different..

 

what happen is i created an visualforce page with standard controller opportunity and drag this page layout of opportunity it wroks fine.but if i did it for my custom object created new vf page with custom standard controller and drag it in on my custom page layout but this time i unable ot access or getting this page in custom object as well as no space.but when i override the button with this custom obj vf page then i get that vf page.

 

 

i am not getting what happening.if you have any clue,please help me.

 

thanks

hi 

 

i have Visualforce page embaded in page layout realted to custom object. but it not display there. then i override the edit button with that vf page it work fine.

 but when i put it in the pagelayout it not work. i also checked the permission under profile to confirm the permission access of the vf page and the system admin have the permission there. 

 

so i dont knw wht i cn't access the vf in the page layout.

 

 

thanks

 

 
Hi every one 
 
i have one page layout where all the fields are readonly but when system admin login ,these fields are in editable mode as they are in readonly set in page layout .thn i came to know that 
 
 under mangeuser--> profile-->System Permissions ther is one option "Edit Read Only Fields" which is chked ..if it is unchked thn sys admin will not edit th readonly fields but when i click in the edit on system permission the"Edit read only" it is in disable form...
 
 
u have any idea how to make them editable thr
 
 
thanks
 
 

hi everyone

 

i need to cover the below lines but unable to do that.

 

The code is as follows:

Webservice static string Submit(string oppId)
{

 

string message = '';
boolean flag = true;

 

Flight_Request__c[] tf = [SELECT id,Customer_Approved_Itinerary__c,Opportunity__c FROM Flight_Request__c WHERE Opportunity__c = :oppId and Customer_Approved_Itinerary__c = true ];
if (tf.size() != 1)
{
message += 'Flight Request must contain only one record with Customer Approved Itinerary true \n';
flag = false;
}

 

}

 

 

My Test class method

 

static testMethod void myUnitTest() {

string message = '';
boolean flag = true;

 

Flight_Request__c fr = new Flight_Request__c();
fr.Budget__c = '23';
fr.Publish_Fare__c = '35';
fr.Flight_Itinerary_Name__c ='Test';
fr.Opportunity__c = opp.Id;
fr.From__c = opp.Origin_City__c;
fr.To__c = opp.Destination_City__c;
fr.Outbound_del__c = opp.Departure_Date__c;
fr.Pax_del__c = opp.Number_of_Passengers__c;
fr.Region_del__c = opp.Destination_Zone__c;
fr.Inbound_del__c = opp.Return_Date__c;
fr.Outbound_Flexibility__c = opp.Flexibility_From__c;
fr.Inbound_Flexibility__c = opp.Flexibility_To__c;
fr.Email_To__c ='anil@swiftsetup.com';
fr.Email_Content__c= 'Test';
fr.Subject__c ='subject test';
fr.Customer_Approved_Itinerary__c = true;
fr.Flight_Info__c = 'Test';
fr.Searcher_New__c ='Anil D';
fr.Email_Cc__c ='dm@we.com';
fr.Email_Bcc__c ='anil@we.com';
insert fr;

 

 

}

 

but it not coverd the above red lines.

 

please guide me.

 

Thanks

  • September 28, 2012
  • Like
  • 0

Hi everyone,

 

I have one sys admin login and other is enduser login.suppose if sysadmin changes the opportunity stage to "completed" thn the enduser unable to change the stage, that i did using validation rule but i need that if the opportunity stage is "completed" the enduser unable to edit the opportunity data mean other fields too. i did it using the validatin rule that is stage is completed and user is not other thn sys admin thn we can not edit the opportunity ,as opp consist of various related list(many obj related to opp) so i did again  same for these objects also.

 

i need to knw is there any other way too handle this thing in salesforce. so if the opp stage is completed then the enduser unable to change the opp data as well as its related list too.

 

 

Thanks

 

 

  • September 26, 2012
  • Like
  • 0

hi everyone

 

From last fews days i am trying to deploy a class with good test coverge but i unable to achieve that.

 

pleas help me to get the best code coverage as i tried to fix all the point in test case but even though i fail to do so.

 

 

My apex class is shown below and red lines are not coverd.

 

public class FFPage {

FF__c FF;
public List<Opportunity> listOpp;
public String Id {get; set;}
public Opportunity Opp {get; set;}
public String Msg {get; set;}
public boolean chkConfirm {get;set;}
public boolean chkAcct {get;set;}
public static boolean isApexTest = false;
//boolean flag = false;
public FFPage(ApexPages.StandardController stdController)
{
FF = (FF__c)stdController.getRecord();
Id = FF.Opportunity__c;

}

public PageReference Save()
{
chkConfirm = false;
chkAcct = false;
Msg = Apexpages.currentPage().getParameters().get('one');
System.debug('*************Msg************ : ' + Msg );


try
{

if(FF.Id == null)
{
string obj = main(FF.Opportunity__c,FF.Id,FF.FFGuid__c,FF.Account_Number__c,FF.Account_Type__c,FF.Last_Name__c,FF.Miles__c,FF.Password__c,'add',Msg );
// if(obj.contains('success'))
System.debug('*************RailMsgobj*********'+obj);
if(obj.contains('success')|| obj=='success')
{
System.debug('*************Railsobj*********'+obj);
string[] parts = obj.split(',');
if(parts.size()>1)
{
FF.FFGuid__c = parts[1];
}
System.debug('*************Guid*********'+FF.FFGuid__c);
insert FF;
System.debug('insert');
// ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, parts[0]));
PageReference pr = new PageReference('https://c.cs9.visual.force.com/apex/FFPage?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
pr.setRedirect(true);
pr.getParameters().put('paramName', 'Saved Successfully');
return pr;

}
else
{
System.debug('notinsert');
// obj == 'Not enough miles in account';
//chkConfirm = true;
if(obj.contains('Not enough miles in account')|| obj=='Not enough miles in account')
{
chkConfirm = true;
}
else if(obj.contains('Account does not exist')|| obj=='Account does not exist')
{
System.debug('*************AccountNot*********'+obj);
chkAcct = true;
}
else
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING,obj));
}


}

}
else
{
string userID;
userID = userinfo.getProfileId();
userID = userID.substring(0,15);
System.debug('*************LoginuserID *********'+userID );
Decimal miles;
if(userID != '00ed0000000vQrA')
{

Opportunity opp = [SELECT id, StageName FROM Opportunity WHERE Id = :FF.Opportunity__c];

if(opp .StageName == 'Completed')
{
FF__c ffobj = [SELECT id, Miles__c FROM FF__c WHERE Id = :FF.id];
if(ffobj != null)
{
if(ffobj.Miles__c != null)
{
miles = ffobj .Miles__c;
}
}
}
else
{
miles = FF.Miles__c;

}

}
else
{
miles = FF.Miles__c;

}
System.debug('*************NewMiles*********'+miles );

string obj = main(FF.Opportunity__c,FF.Id,FF.FFGuid__c,FF.Account_Number__c,FF.Account_Type__c,FF.Last_Name__c,miles,FF.Password__c,'update',Msg);
if(obj.contains('success')|| obj=='success')
{
string[] parts = obj.split(',');
if(parts.size()>1)
{
FF.FFGuid__c = parts[1];
}
System.debug('*************Guidupdate*********'+FF.FFGuid__c);
try
{
update FF;
System.debug('update');
//ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, obj));
PageReference pr = new PageReference('https://c.cs9.visual.force.com/apex/FFPage?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
pr.setRedirect(true);
pr.getParameters().put('paramName', 'Updated Successfully');
return pr;

}
catch(Exception e)
{
string expmsg = e.getMessage();
System.debug(expmsg);
if(expmsg.contains('FIELD_CUSTOM_VALIDATION_EXCEPTION, Opportunity is closed,You cannot edit the MIles.'))
{

System.debug('DmlException');
// ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Opportunity is closed,You cannot edit the MIles'));
PageReference pr = new PageReference('https://c.cs9.visual.force.com/apex/FFPage?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
pr.setRedirect(true);
pr.getParameters().put('paramName', 'Opportunity is closed,You cannot edit the MIles');
return pr;
}
}

}
else
{
System.debug('notupdate');
if(obj.contains('Not enough miles in account')|| obj=='Not enough miles in account')
{
chkConfirm = true;
}
else if(obj.contains('Account does not exist')|| obj=='Account does not exist')
{
chkAcct = true;
}
else
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, obj));
}
//PageReference pr = new PageReference('https://c.na14.visual.force.com/apex/FFPage?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
// pr.setRedirect(true);
// pr.getParameters().put('paramName', obj);
// return pr;
}



}



}

catch(DmlException ex)
{

}
return null;
}
public String main(String opid,String ffid,String guid,String actnu,String acttype,String lastn,Decimal miles,String pwd,String action,String Chkmiles)
{

SalesForceUrl__c sf = SalesForceUrl__c.getValues('AMUrl');
SalesForceUrl__c sf2 = SalesForceUrl__c.getValues('IsSandBox');
// Do a whole bunch of stuff

// Build the http request
HttpRequest req = new HttpRequest();
Http h = new Http();

if( sf != null && sf2!= null)
{
req.setEndpoint(sf.SettingValue__c+'/salesforce/test?oppid='+ opid+'&ffid='+ffid+'&guid='+guid +'&acctnu='+actnu +'&accttype='+acttype+'&lastname='+lastn+'&miles='+miles+'&pwd='+pwd+'&actionType='+action+'&IsSandbox='+sf2.SettingValue__c+'&Chkmiles='+Msg);

}
req.setMethod('GET');

// Invoke web service call
String result = '';
if (!isApexTest){
// Make a real callout since we are not running a test
HttpResponse res = h.send(req);
result = res.getBody();
System.debug('Result=' +result);
System.debug('STATUS:'+res.getStatus());
} else {
// A test is running
result = 'success';
}

// Do whole bunch of stuff

return result;
}


// Wrapper method for "main" that we will call in the Test Class
public String mainForTest(){
isApexTest = true;
DateTime dT = System.now();
Decimal i = 1.2;
return main('006d0000007jfwO','a00d000000560NZ','a00d000000560NZ','11','AA','aa',i,'asd','add','true');
}
public PageReference Cancel()
{

PageReference pr = new PageReference('/' + Id);
pr.setRedirect(true);
return pr;
}
}

 

 

 

 

MY Test Class is 

 

 

 

@isTest
private class FFPageTestCase {

static testMethod void myUnitTest() {
FF__c FF;
List<Opportunity> listOpp;
List<FF__c> listFF;
String Id;
String result;
String webresult;
String webresultu;

string obj = '';
List<String> parts;


Opportunity opp = new Opportunity();
opp.Name = 'Test Opp';
opp.StageName = 'Ticketing';
opp.p1_First_Name__c ='A';
opp.p1_Last_Name__c ='D';
opp.p1_Gender__c = 'S';
opp.p1_First_Name__c ='S';
opp.p1_Last_Name__c ='A';
opp.p1_Gender__c = 'D';
opp.DOB_Main_Passenger__c = System.now().date();
opp.Number_of_Passengers__c = 4;
opp.CloseDate = System.now().date();
opp.Departure_Date__c = System.now().date();
opp.Origin_City__c = 'DEL';
opp.Destination_City__c= 'MUI';
opp.Return_Date__c = System.now().date();
opp.Override_Itinerary_Builder__c = true;
opp.Complete_Itinerary_Information__c ='test';
opp.Approved__c ='Test1';
opp.AmMessage__c ='success';
insert opp;

FF = new FF__c();
FF.Account_Number__c ='1234456';
FF.Account_Type__c = 'ANA';
FF.DOB__c = system.today();
FF.Opportunity__c = opp.Id;
FF.Last_Name__c = 'Dutt';
FF.Miles__c = 1.2;
FF.Password__c= 'asd';
FF.Mileage_Cost__c = 0.0210;
FF.FFGuid__c ='hhhhdofhff';
webresult = 'success';
obj = 'Success,785765876';
parts = obj.split(',');
if(parts.size()>1)
{
FF.FFGuid__c = parts[1];
}

insert FF;
opp.StageName = 'FF Account Assigned';
update opp;


webresultu = 'success';
update FF;


try
{
ApexPages.StandardController sc = new ApexPages.StandardController(FF);
FFPage sc1 = new FFPage(sc);


String retVal = sc1.mainForTest();
// Add asserts for validation
String expectedResult = 'success';
System.assertEquals(retVal, expectedResult);
sc1.Save();


FF__c FF2 = new FF__c();
FF2.Account_Number__c ='1234456';
FF2.Account_Type__c = 'ANA';
FF2.DOB__c = system.today();
FF2.Opportunity__c = opp.Id;
FF2.Last_Name__c = 'Dutt';
FF2.Miles__c = 1.2;
FF2.Password__c= 'asd';
FF2.Mileage_Cost__c = 0.0210;
FF.FFGuid__c ='hhhhdofhff';
webresult = 'success';
insert FF2;

SalesForceUrl__c sf = new SalesForceUrl__c();
sf.Name ='AMUrl';
sf.SettingValue__c ='test';
insert sf;
SalesForceUrl__c sf2 = new SalesForceUrl__c();
sf2.Name ='IsSandBox';
sf2.SettingValue__c ='true';
insert sf2;
sc1.Cancel();
}

catch(System.CalloutException e)
{
webresult = e.getMessage();
}
System.assertEquals(webresult,'success');

}
}

 

 

 

 

Please help me to get rid of this.

 

thanks

 

 

  • September 21, 2012
  • Like
  • 0

HI everyone.

 

i need to know how we can send a parameters to apex method .as my button like below

 

   <apex:commandButton action="{!save}" onclick="return confirm('are you sure?');" value="TSave" /> 

 

As when we hit the ok ,we need to send a parameter to the save action .

 

 

Please help me.

 

Thanks.

  • September 13, 2012
  • Like
  • 0

HI community.

 

I have one vf page related to custom object ff having Opportunity as a Master-Detail(Opportunity).

in vf page i have one inputtag as below

    <apex:inputField label="Opportunity" value="{!FF__c.Opportunity__c}"  />

 

during create ,textbox is open for opportunity abd during edit the readonly field,so in this cas i need it to a click able and redirect to opportunity page.
 
As i have one action in controller which work perfectly but i need it in opportunity case in edit mode.
 
 
Thanks
  • September 06, 2012
  • Like
  • 0

hi every one

 

i have two user.

1. admin

2. test

 

if the stage is completed then the user test unable to change the opportunity stage if the stage is "completed" only admin can change it.

For that i created the validation rule but it not work

 

AND ( 
ISPICKVAL(StageName, "Completed") 
, $User.ProfileId != "056560000666")

}

 

here this is admin prfofile id 056560000666.

 

But it not work.

 

please guide me.

 

thanks

  • September 05, 2012
  • Like
  • 0

HI everyone.

 

i have two custom objects named:

Airline,

Eticket.

In both the  custom object i used one picklist in each but having same values as like:

 

1. Object: Airline

Picklist name :Airline_name 

 

2. Object: Eticket

Picklist name:Airline_name 

 

 

I need that to be manage in one place, that if i change there it will depict in both the cases.

 

Please guide how can i get this common functionality work for both the custom objects.

 

 

Thanks

 

 

  • September 03, 2012
  • Like
  • 0

hi every one.

 

I need 100% code coverage for the class ,i tried to make a test class but it not covered 100%  just 70%

 

Below is my class as well as test class as under:

 

My Class

 

public class WebServiceSalesforceFeed{
@future (callout =true)
public static void HttpResult(String oppID) {
SalesForceUrl__c sf = SalesForceUrl__c.getValues('AMUrl'); // custom setting objects.
SalesForceUrl__c sf2 = SalesForceUrl__c.getValues('IsSandBox');
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
if(sf !=null && sf2!=null)

{
req.setEndpoint(sf.SettingValue__c+'/salesforce/SalesForceFeed?oppid='+oppID+'&IsSanbox='+sf2.SettingValue__c);
}

req.setMethod('GET');

try
{
res = http.send(req);
string result = res.getBody();
System.debug('STATUS:'+res.getStatus());
System.debug('STATUS_CODE:'+res.getStatusCode());

}
catch(System.CalloutException e)
{
System.debug('Callout error: '+ e);
System.debug(res.toString());
}

}

// run WebServiceCallout.testMe(); from Execute Anonymous to test
public static testMethod void testMe() {
WebServiceSalesforceFeed.HttpResult('006d0000006enVK');
}

}

 

 

The Test class

 

@isTest
private class WebServiceSalesFeedTest {

static testMethod void myUnitTest() {

Opportunity opp = new Opportunity();
opp.Name = 'Test Opp';
opp.StageName = 'To Be Searched';
opp.p1_First_Name__c ='A';
opp.p1_Last_Name__c ='D';
opp.p1_Gender__c = 'S';
opp.p1_First_Name__c ='S';
opp.p1_Last_Name__c ='A';
opp.p1_Gender__c = 'D';
opp.DOB_Main_Passenger__c = System.now().date();
opp.Number_of_Passengers__c = 4;
opp.CloseDate = System.now().date();
opp.Departure_Date__c = System.now().date();
opp.Origin_City__c = 'DEL';
opp.Destination_City__c= 'MUI';
opp.Return_Date__c = System.now().date();
opp.AmMessage__c ='testttt';

insert opp;

SalesForceUrl__c sf = new SalesForceUrl__c();
sf.Name ='AMUrl';
sf.SettingValue__c ='test';
insert sf;
SalesForceUrl__c sf2 = new SalesForceUrl__c();
sf2.Name ='IsSandBox';
sf2.SettingValue__c ='test';
insert sf2;

WebServiceSalesforceFeed obj = new WebServiceSalesforceFeed();
WebServiceSalesforceFeed.HttpResult(opp.Id);
WebServiceSalesforceFeed.testMe();
}
}

 

 

As this is custom setting object

 

 SalesForceUrl__c sf = new SalesForceUrl__c(); 

having SettingValue__c is custom fieild.

and two values Name = "amurl" and "SettingValue" having some value

 two values Name = "amurl" and "IsSandBox" having some value

,As i used this  in above code as shown in green line above.

 

 

Please guide me how can i achieve 100% for this class as it was about 80 % covered before i added green lines but i need this.

 

 

Thanks

 

 

 

 

Hi every one .

 

 i am getting the error  "System.NullPointerException:Attempt to de-reference a null object" while runing a test case.

 

The below is my Class: i am getting error in red line below:

 

public class FFtestPage {

FFtest__c FF;
public List<Opportunity> listOpp;
public String Id {get; set;}
public Opportunity Opp {get; set;}
public String Msg {get; set;}
public static boolean isApexTest = false;
//boolean flag = false;
public FFtestPage(ApexPages.StandardController stdController)
{
FF = (FFtest__c)stdController.getRecord();
Id = FF.Opportunity__c;

}

public PageReference Save()
{

try
{
if(FF.Id == null)
{
string obj = main(FF.Opportunity__c,FF.Id,FF.FFGuid__c,FF.Account_Number__c,FF.Account_Type__c,FF.Last_Name__c,FF.Miles__c,FF.Password__c,'add');
// if(obj.contains('success'))
if(obj.contains('success')|| obj=='success')
{
System.debug('*************Railsobj*********'+obj);
string[] parts = obj.split(',');
if(parts.size()>1)
{
FF.FFGuid__c = parts[1];
}
System.debug('*************Guid*********'+FF.FFGuid__c);
insert FF;
System.debug('insert');
// ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, parts[0]));
PageReference pr = new PageReference('https://c.cs9.visual.force.com/apex/FFTestPAge?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
pr.setRedirect(true);
pr.getParameters().put('paramName', 'Saved Successfully');
return pr;

}
else
{
System.debug('notinsert');
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, obj));
// PageReference pr = new PageReference('https://c.na14.visual.force.com/apex/FFPage?retURL='+Id);
//pr.setRedirect(true);
// pr.getParameters().put('paramName', obj);
// return pr;

}

}
else
{
string obj = main(FF.Opportunity__c,FF.Id,FF.FFGuid__c,FF.Account_Number__c,FF.Account_Type__c,FF.Last_Name__c,FF.Miles__c,FF.Password__c,'update');
if(obj.contains('success')|| obj=='success')
{
string[] parts = obj.split(',');
if(parts.size()>1)
{
FF.FFGuid__c = parts[1];
}
System.debug('*************Guidupdate*********'+FF.FFGuid__c);
update FF;
System.debug('update');
//ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, obj));
PageReference pr = new PageReference('https://c.na14.visual.force.com/apex/FFTestPAge?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
pr.setRedirect(true);
pr.getParameters().put('paramName', 'Updated Successfully');
return pr;
}
else
{
System.debug('notupdate');
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, obj));
//PageReference pr = new PageReference('https://c.na14.visual.force.com/apex/FFPage?id='+FF.Id+'&retURL='+Id+'&sfdc.override=1');
// pr.setRedirect(true);
// pr.getParameters().put('paramName', obj);
// return pr;
}

}

}

catch(DmlException ex)
{

}
return null;
}
public String main(String opid,String ffid,String guid,String actnu,String acttype,String lastn,Decimal miles,String pwd,String action)
{

SalesForceUrl__c sf = SalesForceUrl__c.getValues('AMUrl');
SalesForceUrl__c sf2 = SalesForceUrl__c.getValues('IsSandBox');
// Do a whole bunch of stuff

// Build the http request
HttpRequest req = new HttpRequest();
Http h = new Http();
if(sf != null && sf2 != null)
{
req.setEndpoint(sf.SettingValue__c+'/Abc/test?oppid='+ opid+'&ffid='+ffid+'&guid='+guid +'&acctnu='+actnu +'&accttype='+acttype+'&lastname='+lastn+'&miles='+miles+'&pwd='+pwd+'&actionType='+action+'&IsSandbox='+sf2.SettingValue__c);
}
req.setMethod('GET');

// Invoke web service call
String result = '';
if (!isApexTest){
// Make a real callout since we are not running a test
HttpResponse res = h.send(req);
result = res.getBody();
System.debug('Result=' +result);
System.debug('STATUS:'+res.getStatus());
} else {
// A test is running
result = 'success';
}

// Do whole bunch of stuff

return result;
}


// Wrapper method for "main" that we will call in the Test Class
public String mainForTest(){
isApexTest = true;
DateTime dT = System.now();
Decimal i = 1.2;
return main('006d0000007jfwO','a00d000000560NZ','a00d000000560NZ','11','AA','aa',i,'asd','add');
}
public PageReference Cancel()
{

PageReference pr = new PageReference('/' + Id);
pr.setRedirect(true);
return pr;
}
}

 

 

My test Class is:

 

@isTest
private class FFtestPagetestcase {

static testMethod void myUnitTest() {
FFtest__c FF;
List<Opportunity> listOpp;
List<FFtest__c> listFF;
String Id;
String result;
String webresult;
String webresultu;

string obj = '';
List<String> parts;


Opportunity opp = new Opportunity();
opp.Name = 'Test Opp';
opp.StageName = 'Ticketing';
opp.p1_First_Name__c ='A';
opp.p1_Last_Name__c ='D';
opp.p1_Gender__c = 'S';
opp.p1_First_Name__c ='S';
opp.p1_Last_Name__c ='A';
opp.p1_Gender__c = 'D';
opp.DOB_Main_Passenger__c = System.now().date();
opp.Number_of_Passengers__c = 4;
opp.CloseDate = System.now().date();
opp.Departure_Date__c = System.now().date();
opp.Origin_City__c = 'DEL';
opp.Destination_City__c= 'MUI';
opp.Return_Date__c = System.now().date();
opp.Override_Itinerary_Builder__c = true;
opp.Complete_Itinerary_Information__c ='test';
opp.Approved__c ='Test1';
opp.AmMessage__c ='success';
insert opp;

FF = new FFtest__c();
FF.Account_Number__c ='1234456';
FF.Account_Type__c = 'ANA';
FF.DOB__c = system.today();
FF.Opportunity__c = opp.Id;
FF.Last_Name__c = 'Dutt';
FF.Miles__c = 1.2;
FF.Password__c= 'asd';
FF.FFGuid__c ='hhhhdofhff';
webresult = 'success';
obj = 'Success,785765876';
parts = obj.split(',');
if(parts.size()>1)
{
FF.FFGuid__c = parts[1];
}

insert FF;
opp.StageName = 'FF Account Assigned';
update opp;


webresultu = 'success';
update FF;

try
{
ApexPages.StandardController sc = new ApexPages.StandardController(FF);
FFtestPage sc1 = new FFtestPage(sc);


String retVal = sc1.mainForTest();
// Add asserts for validation
String expectedResult = 'success';
System.assertEquals(retVal, expectedResult);
sc1.Save();


FFtest__c FF2 = new FFtest__c();
FF2.Account_Number__c ='1234456';
FF2.Account_Type__c = 'ANA';
FF2.DOB__c = system.today();
FF2.Opportunity__c = opp.Id;
FF2.Last_Name__c = 'Dutt';
FF2.Miles__c = 1.2;
FF2.Password__c= 'asd';
FF.FFGuid__c ='hhhhdofhff';
webresult = 'success';
insert FF2;
SalesForceUrl__c sf = SalesForceUrl__c.getValues('AMUrl');
sf.Name='AMUrl';

insert sf;
SalesForceUrl__c sf2 = SalesForceUrl__c.getValues('IsSandBox');
sf2.Name='IsSandBox';

insert sf2;
sc1.Cancel();
}

catch(System.CalloutException e)
{
webresult = e.getMessage();
}
System.assertEquals(webresult,'success');

}
}

 

 

please guide me where i am going wrong.

 

 

thanks

HI everyone

 

i have one validation rule like below

 

MONTH(CloseDate) < MONTH(TODAY())

 

it works fine but i need it to fire only for a new opportunities not for old.

 

for that purose i did this

 

AND( 
Id =='0', 
MONTH(CloseDate) < MONTH(TODAY()) 

)

 

but it not work .

 

please guide me what can i do to achieve this.

 

 

Thanks.