• Sunay - KVP Bus Solns
  • NEWBIE
  • 10 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 22
    Questions
  • 37
    Replies

Anyone knows how to get around this size limit for HTTPResponse for WebCallouts?...it gives me the below error:

 

System.calloutException: maximum size limit exceeded 3000000

 

Any help is appreciated.

 


Hi,

 

I am trying to write the test method for the below class, but I am not able to cross the coverage of 65%. Can anybody help me on this as it is very urgent.

 

Please find the code below of both Apex class and the test class:

 

public class AddLineItems
{

public AddLineItems(ApexPages.StandardSetController controller)
{
op=[Select id,Name from Opportunity where id=:ApexPages.currentPage().getParameters().get('id')];

lineitem1= new App_Account_Opportunity_Link__c();
lineitem2= new App_Account_Opportunity_Link__c();
lineitem3= new App_Account_Opportunity_Link__c();
lineitem4= new App_Account_Opportunity_Link__c();
lineitem5= new App_Account_Opportunity_Link__c();
lineitem6= new App_Account_Opportunity_Link__c();
lineitem7= new App_Account_Opportunity_Link__c();
lineitem8= new App_Account_Opportunity_Link__c();
lineitem9= new App_Account_Opportunity_Link__c();
lineitem10= new App_Account_Opportunity_Link__c();

}

public App_Account_Opportunity_Link__c lineitem1{get;set;}
public App_Account_Opportunity_Link__c lineitem2{get;set;}
public App_Account_Opportunity_Link__c lineitem3{get;set;}
public App_Account_Opportunity_Link__c lineitem4{get;set;}
public App_Account_Opportunity_Link__c lineitem5{get;set;}
public App_Account_Opportunity_Link__c lineitem6{get;set;}
public App_Account_Opportunity_Link__c lineitem7{get;set;}
public App_Account_Opportunity_Link__c lineitem8{get;set;}
public App_Account_Opportunity_Link__c lineitem9{get;set;}
public App_Account_Opportunity_Link__c lineitem10{get;set;}

public Opportunity op{get;set;}



public AddLineItems()
{
}


Public PageReference savedata()
{

if(lineitem1.App_Account__c!= null)
{
lineitem1.Opportunity__c= op.Id;
insert lineitem1;
}

if(lineitem2.App_Account__c!= null)
{
lineitem2.Opportunity__c=op.Id;
insert lineitem2;
}

if(lineitem3.App_Account__c!= null)
{
lineitem3.Opportunity__c=op.Id;
insert lineitem3;
}

if(lineitem4.App_Account__c!= null)
{
lineitem4.Opportunity__c=op.Id;
insert lineitem4;
}

if(lineitem5.App_Account__c!= null)
{
lineitem5.Opportunity__c=op.Id;
insert lineitem5;
}

if(lineitem6.App_Account__c!= null)
{
lineitem6.Opportunity__c=op.Id;
insert lineitem6;
}

if(lineitem7.App_Account__c!= null)
{
lineitem7.Opportunity__c=op.Id;
insert lineitem7;
}

if(lineitem8.App_Account__c!= null)
{
lineitem8.Opportunity__c=op.Id;
insert lineitem8;
}

if(lineitem9.App_Account__c!= null)
{
lineitem9.Opportunity__c=op.Id;
insert lineitem9;
}

if(lineitem10.App_Account__c!= null)
{
lineitem10.Opportunity__c=op.Id;
insert lineitem10;
}



PageReference oppty=new PageReference('/' + op.Id);

oppty.setRedirect(true);

return oppty;
}


}

 

Test Class:

@istest
private class TestMassAddLineItems
{
static testmethod void MassAddLineItems()
{
Id userId =UserInfo.getUserId();

User us =[Select id from User where id=:userId ];

Opportunity o=new Opportunity();
o.Name='Test Opportunity';
o.StageName='Hotel Loading Only';
o.CloseDate=date.Today();
o.Client_Services_Manager__c=us.id;
insert o;


App_Account__c a = new App_Account__c();
a.Name='Test App Account';
insert a;


App_Account_Opportunity_Link__c aaol=new App_Account_Opportunity_Link__c();
aaol.Opportunity__c=o.id;
aaol.App_Account__c=null;
insert aaol;

List<Opportunity> opp = [Select id from Opportunity where id = :o.Id];


ApexPages.StandardSetcontroller sc1 = New ApexPages.StandardSetController(opp);
System.CurrentPageReference().getParameters().put('Id',o.Id);

AddLineItems li1=new AddLineItems();
AddLineItems li=new AddLineItems(sc1);

li.savedata();

aaol.App_Account__c = a.Id;
update aaol;

li.savedata();



}

}

Hi,

 

We are planning to build a functionality where we need to have a report to check the number of times a record is viewed on the Account object. 

 

I need to build a apex code which will capture the number of times a record is opened. Can anybody help or suggest me how can I achieve this. 

 

Would appreciate any help regarding this as it is critical.

 

 

Hi,

 

I am using a trigger to call the future method, but it gives me a error which says "Too many Future calls". There are 100 of records inserted, after which this method is called. Is there any way where I can overcome this error.

 

Please give me some inputs on this.

 

Thanks.

Hi,

 

I am trying to integrate Amazon with Salesforce and I have the XSD's for the Order Report and Inventory, but I am unable to use these XSD's to call the API from Salesforce. I tried converting these XSD's into WSDL files but was unable to do so.

 

If someone has already worked on this, could you please help me on this.

 

Also it will be helpful if somebody has done this kind of integration with sales force earlier and shed some light on the same.

 

Hi,

 

We are trying to integrate amazon with sales force to pull data from sales force to amazon. We are basically trying to pull data such as Order Date, Order Number, Sales Price, Quantity and so on, but while doing this we are not able to identify the XML used to do the same.

 

If somebody can shed some light on the XML need to be used it will be very helpful for us.

 

Kindly do the needful.

 

Regards,
Cloud Forward

Hi,

 

We have a application built of Visual force pages and in every page we have a back button. Here I am trying to achieve the functionality of a "Back button in Browser " using only APEX Code.

 

Can anybody suggest some ideas as to how I can add a method to achieve this or is there any different approach which will help me.

Hi,

 

Does anybody know how to create a HTML Email template using a trigger or Apex class. I have tried creating a EmailTemplate using trigger but it throws an Mixed DML exception.

 

I am not able to figure out the solution for the same. 

 

Kindly give an solution ASAP.

 

 

Hi,

 

We have a managed packaged which has been made as released version and privately listed in the appexchange for the security review. Now we want to add some components and also remove some components from the package, but we are unable to do that. We are not finding the right steps to manage the package.

 

Also we have a patch organization where it allows to edit the existing components but will not allow to add the components. Can anybody let me know how to overcome these difficulties?

 

Regards,

Sunay

Hi,

 

Can anybody help me on writing the test method for the below Apex class:

 

global class scheduler implements Schedulable{
global void execute(SchedulableContext SC) {

List<Survey__c> slist=[Select id ,Email_Template_Id__c,Type_of_Survey__c,Number_of_Days_for_Mail__c from Survey__c ];
List<Visit_Details__c> tlist;
List<Visit_Details__c> tlistupdate= new List<Visit_Details__c>();
List<Booking_Detail__c> blist;
List<Booking_Detail__c> blistupdate= new List<Booking_Detail__c>();

EmailTemplate e;
List< Messaging.SendEmailResult> semr;
String url;
String mail_html;
Integer sendcount=0;
Datetime cdate;
String[] toAddresses = new String[]{} ;
for(integer i=0;i<slist.size();i++)
{ if(sendcount>=10)
break;

try
{
e = [select Id,Name,Subject,body ,htmlvalue from EmailTemplate where Id=:slist[i].Email_Template_Id__c];
if((e.htmlvalue=='')||(e.htmlvalue==null))
mail_html= e.body;
else
mail_html=e.htmlvalue;
}
catch(Exception ee)
{

}



if(slist[i].Type_of_Survey__c=='Post Visit')
{

try
{
cdate =System.now().addDays(-(Integer.valueOf(slist[i].Number_of_Days_for_Mail__c)));
}
catch(Exception err)
{
}
tlist= [Select id ,Survey_Status__c,Check_In_Date__c,Guest_Profile_Email_Id__c,createdDate from Visit_Details__c where Survey_Status__c!=:'sent' AND createddate >: cdate ];
for(integer email=0;email<tlist.size();email++)
{ if(sendcount<10)
sendcount++;
else
break;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

toAddresses.clear();

toAddresses.add(tlist[email].Guest_Profile_Email_Id__c);
mail.setToAddresses(toAddresses );

mail.setSubject(e.Subject);

url='<a href=\"http://idsnext-developer-edition.na12.force.com/TakeSurvey?id='+slist[i].id+'&caId='+tlist[email].id+'\">click here to make your survey</a>';
try
{
mail_html=mail_html.replace('{!Survey__c.URL__c}',url);


}
catch(Exception html)
{
mail_html=' ';
}
mail.setHTMLBody(mail_html );
try
{
semr= Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
catch(Exception toomanymails)
{

}
if(semr[0].isSuccess()==true)
{
tlist[email].Survey_Status__c='Sent';
tlistupdate.add(tlist[email]);
}
else
{
tlist[email].Survey_Status__c='Not Sent';
tlistupdate.add(tlist[email]);
}
url='';
mail_html='';
update tlistupdate;
}
}


if(slist[i].Type_of_Survey__c=='Pre Visit')
{


try
{
cdate =System.now().addDays(-(Integer.valueOf(slist[i].Number_of_Days_for_Mail__c)));
}
catch(Exception err)
{
}
blist= [Select id ,Survey_Status__c,Arrival_Date__c,Contact_Email__c,createdDate from Booking_Detail__c where Survey_Status__c!=:'Sent' AND createddate >: cdate ];
for(integer email=0;email<blist.size();email++)
{ if(sendcount<10)
sendcount++;
else
break;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

toAddresses.clear();

toAddresses.add(blist[email].Contact_Email__c);
mail.setToAddresses(toAddresses );

mail.setSubject(e.Subject);

url='<a href=\"http://idsnext-developer-edition.na12.force.com/TakeSurvey?id='+slist[i].id+'&caId='+blist[email].id+'\">click here to make your survey</a>';
try
{
mail_html=mail_html.replace('{!Survey__c.URL__c}',url);

}
catch(Exception html)
{
mail_html=' ';
}

mail.setHTMLBody(mail_html );
try
{
semr= Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
catch(Exception toomanymails)
{

}
if(semr[0].isSuccess()==true)
{
blist[email].Survey_Status__c='Sent';
blistupdate.add(blist[email]);
}
else
{
blist[email].Survey_Status__c='Not Sent';
blistupdate.add(blist[email]);
}
url='';
mail_html='';
update blistupdate;
}
}
}

}

}

 

I tried so many possible ways...but not able to cover 1% of code. Will be grateful for any help.

 

 

Hi,

 

We have created a managed package, but when we try to add a patch by clicking on "Patch Organizations", we are not able to see the New button. Is there any settings which has to be made for this button to be visible.

 

 

Hi,

 

We have developed a visual force page, but when we change the resolution the form is misaligning and jumping out. hence we need supoort as to how we can handle this auto resizing when the resolution is reduced. We have worked on the 1280X768 resolution.

 

Any help is appreciated.

Hi,

 

We have developed a App and we need to create a work around as mentioned below. Can anybody suggest is this possible and if yes how to go about it:

 

Once a managed package is created and published, the user should be able to enter a unique code given by us before he installs the package. And once the unique code is entered, an API is called which will search our database if the code already exists or not, if yes what is the customer name, date of purchase, license validity and so on.

 

Hence we would like to know whether we can achieve this work around successfully.

 

Hi,

 

Can anyone please help me on writing test class for the below Apex class:

 

public Voucher()
{

voucherId ='';

statusmessage='';

guestId = ApexPages.currentPage().getParameters().get('gId');

rewardId = ApexPages.currentPage().getParameters().get('rwId');

Guest_Profile__c gp = [Select id ,Guest_Name__c, Points_Balance__c from Guest_Profile__c where id=:guestId ];

Reward__c reward = [Select id ,Points__c,Voucher_Images_Html__c from Reward__c where id=:rewardId ];

guestName = gp.Guest_Name__c;

htmlsource=reward.Voucher_Images_Html__c ;

currentPoints = gp.Points_Balance__c;

rewardpoints = reward.Points__c;

}


public Pagereference voucherNumber()
{


Voucher__c voucher = new Voucher__c();

Guest_Profile__c gp = [Select id , Points_Balance__c from Guest_Profile__c where id=:guestId ];

Reward__c reward = [Select id ,Points__c from Reward__c where id=:rewardId ];

currentPoints = gp.Points_Balance__c ;

if((currentPoints -reward.Points__c) < 0)

statusmessage='Please get More Points to Redeem this Reward.';

else

currentPoints = currentPoints -reward.Points__c;

Redemption_History__c redeem = new Redemption_History__c() ;

redeem.Guest_Name__c = gp.id;

redeem.Redeemed_Points__c = reward.Points__c;

redeem.Remaining_Points__c = currentPoints ;

redeem.Reward_Name__c = reward.id;

insert voucher;

redeem.Voucher_No__c = voucher.id;

insert redeem;

voucherId = voucher.id;

return null;

}

 

Kindly do the needful asap.

Hi,

 

Need help on the below trigger for the lines marked in red. I am able to cover 52% of code, but I am facing difficulty for the below lines marked in red. 

 

trigger SurveyGuest on SurveyTaker__c (before insert,before update)
{
for(SurveyTaker__c st:trigger.new)
{

st.Guest_Profile__c=st.hg__c;
try
{ Visit_Details__c vs =[Select Overal_Points__c,Guest_Name__c from Visit_Details__c where id=:st.Transaction_Detail__c];

Survey__c sr =[Select id ,Maximum_Points__c,Points_Required_Minimum__c,Email_Template_Id__c,Email_Address__c, Points_for_Loyalty_programme__c from Survey__c where id=:st.Survey__c];
if(vs.Overal_Points__c==null)
vs.Overal_Points__c=0;
vs.Overal_Points__c = vs.Overal_Points__c+ sr.Points_for_Loyalty_programme__c ;
st.Guest_Profile__c=vs.Guest_Name__c;
if(((st.Points_Earned__c/sr.Maximum_Points__c)*100)<sr.Points_Required_Minimum__c)
{
EmailTemplate e = [select Id,Name,Subject,body ,htmlvalue from EmailTemplate where Id=:sr.Email_Template_Id__c];
List <String> toAddresses =new List <String>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
toAddresses.add(sr.Email_Address__c);
mail.setToAddresses(toAddresses);
if((e.htmlvalue!=null)&&(e.htmlvalue!=''))
mail.setHtmlBody(e.htmlvalue);
else
if((e.body !=null)&&(e.body !=''))
mail.setHtmlBody(e.body );
mail.setSubject(e.Subject);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
update vs;

}
catch(exception e)
{
}
}

}

 

Kindly help ASAP.

Hi,

 

Can anybody help me on the test method for the Apex trigger below. I am finding difficulties while writing test cases for the conditions used:

 

trigger membership_for_loyalty_programme on Transaction_Breakup__c (before insert,before update)
{

Boolean calculate_points=false;

for(Transaction_Breakup__c tbp:trigger.new)
{
List< Loyalty_Program__c> Loyalty_Program_List;

Membership__c Membership_Selected;

Visit_Details__c vis =[Select Property_Wise_Revenue__c from Visit_Details__c where id=:tbp.Transaction_Detail_No__c];

Property_Wise_Revenue__c pwr =[Select id,No_of_Room_Nights__c, Loyalty_Programme_Record_Type__c, No_of_Stays__c,Property__c,Guest_Profiile_Id__c,Property_Name__c, Total_expenditure_against_property__c from Property_Wise_Revenue__c where id=:vis.Property_Wise_Revenue__c ];

Loyalty_Program_List = [select id, Name, Automatically_Assigned__c, Consider_Tax_for_Overall_Expense__c, Upgrade_Memberships_Automatically__c, RecordType.Name, No_of_Stays__c,No_of_Room_Nights__c, Overall_Expense__c, Duration__c from Loyalty_Program__c where Active__c = true ORDER BY Overall_Expense__c, No_of_Room_Nights__c, No_of_Stays__c ];

try
{
if(Loyalty_Program_List.size() > 0 )
{

Loyalty_Program__c Loyalty_Program_Selected=new Loyalty_Program__c(No_of_Room_Nights__c =0,Name='temp',No_of_Stays__c =0,Overall_Expense__c=0) ;

System.debug(Loyalty_Program_Selected);

for(Loyalty_Program__c Loyalty_Program:Loyalty_Program_List)
{

Date minDate =Date.Today()-(Integer.valueof(Loyalty_Program.Duration__c)*30);

AggregateResult groupedResults;

if(Loyalty_Program.Consider_Tax_for_Overall_Expense__c==true)

groupedResults = [SELECT SUM(Total_Amount_Incl_Tax__c) SumExp,SUM(No_of_Room_Nights__c) SumNights from Visit_Details__c where Property_Wise_Revenue__c=:pwr.Id AND Check_In_Date1__c >=:minDate ];

else

groupedResults = [SELECT SUM(Total_Amount_Excl_Tax__c) SumExp,SUM(Room_Nights__c) SumNights from Visit_Details__c where Property_Wise_Revenue__c=:pwr.Id AND Check_In_Date1__c >=:minDate ];

Integer number_of_stays = [SELECT COUNT() from Visit_Details__c where Property_Wise_Revenue__c=:pwr.Id AND Check_In_Date1__c >=:minDate ];

// if(Loyalty_Program.RecordType.Name=='Stay Based Membership')
{

if((number_of_stays >= Loyalty_Program.No_of_Stays__c)&&(Loyalty_Program_Selected.No_of_Stays__c<Loyalty_Program.No_of_Stays__c))
{

Loyalty_Program_Selected = Loyalty_Program ;

}

}

// if(Loyalty_Program.RecordType.Name=='Room Night based Membership')
{
if(((Decimal)groupedResults.get('SumNights') >= Loyalty_Program.No_of_Room_Nights__c)&&(Loyalty_Program_Selected.No_of_Room_Nights__c<Loyalty_Program.No_of_Room_Nights__c) )
{
Loyalty_Program_Selected = Loyalty_Program ;
}

}
// if(Loyalty_Program.RecordType.Name=='Revenue Based Membership')
{

Decimal Overall_Amount=0.0;

if((Loyalty_Program_Selected.Overall_Expense__c<Loyalty_Program.Overall_Expense__c))
{

if(Loyalty_Program.Consider_Tax_for_Overall_Expense__c==true )

Overall_Amount = (Decimal)groupedResults.get('SumExp')+tbp.Amount_Spent__c+tbp.Tax_Amount__c;

else

Overall_Amount = (Decimal)groupedResults.get('SumExp')+tbp.Amount_Spent__c;

if(Overall_Amount>=Loyalty_Program.Overall_Expense__c )
{

Loyalty_Program_Selected = Loyalty_Program ;

}

}

}
}

List< Membership__c> Membership_List =[select id,Active__c,Test__c,Loyalty_Program_Name__c,Loyalty_Program_Name__r.Id from Membership__c where Guest_Name__c =: pwr.Guest_Profiile_Id__c AND Property_Name__c =: pwr.Property__c];

if(Membership_List.size() > 0)
{
calculate_points=true;

Boolean selected =false;

for(Membership__c Membership:Membership_List)
{
if((Membership.Loyalty_Program_Name__r.Id!=Loyalty_Program_Selected.Id)&&(Loyalty_Program_Selected.Name!='temp'))
{
Membership.Active__c = false;


System.debug('BBBB');
}
else
{
Membership.Active__c = true;


System.debug('AAAAAA');

selected = true;


}

update Membership;

Membership_Selected = Membership;
}

if((!selected)&&(Loyalty_Program_Selected.Name!='temp')&&(Loyalty_Program_Selected.Automatically_Assigned__c == true))
{

Membership__c Membership_New =new Membership__c();

Membership_New.Guest_Name__c = pwr.Guest_Profiile_Id__c;

Membership_New.Property_Name__c=pwr.Property__c;

Membership_New.Loyalty_Program_Name__c =Loyalty_Program_Selected.id;

Membership_New.Active__c = true;

insert Membership_New;

Membership_Selected = Membership_New;

}

if((Loyalty_Program_Selected.Name!='temp')&& (Loyalty_Program_Selected.Automatically_Assigned__c == false))
{

Guest_Profile__c gp =[select id,Eligible_Loyalty_Program__c,Loyalty_programme_assigned_property__c from Guest_Profile__c where id =:pwr.Guest_Profiile_Id__c];

gp.Eligible_Loyalty_Program__c =Loyalty_Program_Selected.Name;

gp.Loyalty_programme_assigned_property__c =pwr.Property_Name__c;

update gp;
}

}
else
{

if((Loyalty_Program_Selected.Name!='temp')&& (Loyalty_Program_Selected.Automatically_Assigned__c == true))
{

Membership__c Membership_New =new Membership__c();

Membership_New.Guest_Name__c = pwr.Guest_Profiile_Id__c;

Membership_New.Property_Name__c=pwr.Property__c;

Membership_New.Test__c ='test';

Membership_New.Loyalty_Program_Name__c =Loyalty_Program_Selected.id;

Membership_New.Active__c = true;

insert Membership_New;

calculate_points=true;

Membership_Selected = Membership_New;


}
if((Loyalty_Program_Selected.Name!='temp')&& (Loyalty_Program_Selected.Automatically_Assigned__c == false))
{

calculate_points=false;

Guest_Profile__c gp =[select id,Eligible_Loyalty_Program__c,Loyalty_programme_assigned_property__c from Guest_Profile__c where id =:pwr.Guest_Profiile_Id__c];

gp.Eligible_Loyalty_Program__c =Loyalty_Program_Selected.Name;

gp.Loyalty_programme_assigned_property__c =pwr.Property_Name__c;

update gp;

}
}



Membership__c Membership_Active =[select id,Active__c,Test__c,Loyalty_Program_Name__c,Loyalty_Program_Name__r.Id from Membership__c where Guest_Name__c =: pwr.Guest_Profiile_Id__c AND Property_Name__c =: pwr.Property__c AND Active__c =: true];




if(calculate_points)
{
Point_Conversion__c pc;
try
{

System.debug(Membership_Selected.Loyalty_Program_Name__c);
pc =[Select id, Active__c,Service_Type__c,Split_Beverage__c,Split_by_Service_Type__c,Split_Room_Charges__c,Amount_in_Consideration__c,Point_Calculation_By__c, Calculate_Discounts__c, Calculate_Points__c, Calculate_Points_for_Tax_Amount__c,
Consider_Discount__c, Discount_Consideration__c, Property_Name__c, Revenue_Code__c, Revenue_Type__c, Revenue_Type_Formula__c, X1_point__c, Amount__c, Points__c, Discount_for_Total_Amount__c, Dicount_Percent__c, Applicable_From__c, Beverage_Amount_for_Points__c, Beverage_Discount__c, Beverage_Points__c, Food_Amount_for_Points__c, Food_Discount__c, Food_Points__c, Liquor_Amount_for_Points__c, Liquor_Discount__c, Liquor_Points__c, Other_Amount_for_Points__c, Other_Discount__c, Other_Points__c, Plan_Amount_for_Points__c, Plan_Discount__c, Plan_Points__c, Room_Amount_for_Points__c, Room_Discount__c, Room_Points__c, Soft_Drink_Amount_for_Points__c, Soft_Drink_Discount__c, Soft_Drink_Points__c, Tax_Amount_for_Points__c, Tax_Discount__c, Tax_Points__c, Tobacco_Amount_for_Points__c, Tobacco_Discount__c, Tobacco_Points__c from Point_Conversion__c where Loyalty_Program_Name__c =:Membership_Active .Loyalty_Program_Name__c AND Active__c=:true];





if(pc.Split_by_Service_Type__c ==true)
{


if(pc.Amount_in_Consideration__c =='Bill Amount inc. Tax')
{


if(pc.Calculate_Points_for_Tax_Amount__c==true)
{

if((pc.Service_Type__c.contains('Food'))&&(pc.Calculate_Points__c==true)&&(pc.Food_Amount_for_Points__c!=0) )
{
tbp.Points_for_Food__c =tbp.Points_for_Food__c+((tbp.Amount_for_Food__c+tbp.Tax_for_Food__c)*(pc.Food_Points__c/pc.Food_Amount_for_Points__c)) ;

}


// ------------------------------Beverage-----------------------------

if( (tbp.Service_Type__c.contains('Beverage'))&&(pc.Calculate_Points__c==true)&&(pc.Beverage_Amount_for_Points__c!=0) )
{
tbp.Points_for_Beverage__c =tbp.Points_for_Beverage__c+((tbp.Amount_for_Beverage__c+tbp.Tax_for_Beverage__c)*(pc.Beverage_Points__c/pc.Beverage_Amount_for_Points__c)) ;

}


// ------------------------------Liquor-----------------------------

if( (tbp.Service_Type__c.contains('Liquor'))&&(pc.Calculate_Points__c==true)&&(pc.Liquor_Amount_for_Points__c!=0) )
{
tbp.Points_for_Liquor__c =tbp.Points_for_Liquor__c+((tbp.Amount_for_Liquor__c+tbp.Tax_for_Liquor__c)*(pc.Liquor_Points__c/pc.Liquor_Amount_for_Points__c)) ;

}


// ------------------------------Soft_Drink-----------------------------

if( (tbp.Service_Type__c.contains('Soft Drinks'))&&(pc.Calculate_Points__c==true)&&(pc.Soft_Drink_Amount_for_Points__c!=0) )
{
tbp.Points_for_Soft_Drink__c =tbp.Points_for_Soft_Drink__c+((tbp.Amount_for_Soft_Drink__c+tbp.Tax_for_Soft_Drink__c)*(pc.Soft_Drink_Points__c/pc.Soft_Drink_Amount_for_Points__c)) ;

}


// ------------------------------Tobacco-----------------------------

if( (tbp.Service_Type__c.contains('Tobacco'))&&(pc.Calculate_Points__c==true)&&(pc.Tobacco_Amount_for_Points__c!=0) )
{
tbp.Points_for_Tobacco__c =tbp.Points_for_Tobacco__c+((tbp.Amount_for_Tobacco__c+tbp.Tax_for_Tobacco__c)*(pc.Tobacco_Points__c/pc.Tobacco_Amount_for_Points__c)) ;

}

// ------------------------------Others-----------------------------
if( (tbp.Service_Type__c.contains('Others'))&&(pc.Calculate_Points__c==true)&&(pc.Other_Amount_for_Points__c!=0) )
{
tbp.Points_for_Others__c =tbp.Points_for_Others__c+((tbp.Amount_for_Others__c+tbp.Tax_for_Others__c)*(pc.Other_Points__c/pc.Other_Amount_for_Points__c)) ;
}

// ------------------------------Room-----------------------------
if( (tbp.Service_Type__c.contains('Room'))&&(pc.Calculate_Points__c==true)&&(pc.Room_Amount_for_Points__c!=0) )
{
tbp.Points_for_Room__c =tbp.Points_for_Room__c+((tbp.Amount_for_Room__c )*(pc.Room_Points__c/pc.Room_Amount_for_Points__c)) ;
}

// ------------------------------Plan-----------------------------
if( (tbp.Service_Type__c.contains('Plan'))&&(pc.Calculate_Points__c==true)&&(pc.Plan_Amount_for_Points__c!=0) )
{
tbp.Points_for_Plan__c =tbp.Points_for_Others__c+((tbp.Amount_for_Plan__c )*(pc.Plan_Points__c/pc.Plan_Amount_for_Points__c)) ;
}


}

if(pc.Calculate_Points_for_Tax_Amount__c==false)
{


if((pc.Service_Type__c.contains('Food'))&&(pc.Calculate_Points__c==true)&&(pc.Food_Amount_for_Points__c!=0) )
{
tbp.Points_for_Food__c =tbp.Points_for_Food__c+((tbp.Amount_for_Food__c )*(pc.Food_Points__c/pc.Food_Amount_for_Points__c)) ;

}

// ------------------------------Beverage-----------------------------

if( (tbp.Service_Type__c.contains('Beverage'))&&(pc.Calculate_Points__c==true)&&(pc.Beverage_Amount_for_Points__c!=0) )
{
tbp.Points_for_Beverage__c =tbp.Points_for_Beverage__c+((tbp.Amount_for_Beverage__c )*(pc.Beverage_Points__c/pc.Beverage_Amount_for_Points__c)) ;

}

// ------------------------------Liquor-----------------------------

if( (tbp.Service_Type__c.contains('Liquor'))&&(pc.Calculate_Points__c==true)&&(pc.Liquor_Amount_for_Points__c!=0) )
{
tbp.Points_for_Liquor__c =tbp.Points_for_Liquor__c+((tbp.Amount_for_Liquor__c )*(pc.Liquor_Points__c/pc.Liquor_Amount_for_Points__c)) ;

}


// ------------------------------Soft_Drink-----------------------------

if( (tbp.Service_Type__c.contains('Soft Drinks'))&&(pc.Calculate_Points__c==true)&&(pc.Soft_Drink_Amount_for_Points__c!=0) )
{
tbp.Points_for_Soft_Drink__c =tbp.Points_for_Soft_Drink__c+((tbp.Amount_for_Soft_Drink__c )*(pc.Soft_Drink_Points__c/pc.Soft_Drink_Amount_for_Points__c)) ;

}


// ------------------------------Tobacco-----------------------------

if( (tbp.Service_Type__c.contains('Tobacco'))&&(pc.Calculate_Points__c==true)&&(pc.Tobacco_Amount_for_Points__c!=0) )
{
tbp.Points_for_Tobacco__c =tbp.Points_for_Tobacco__c+((tbp.Amount_for_Tobacco__c )*(pc.Tobacco_Points__c/pc.Tobacco_Amount_for_Points__c)) ;

}

// ------------------------------Room-----------------------------
if( (tbp.Service_Type__c.contains('Room'))&&(pc.Calculate_Points__c==true)&&(pc.Room_Amount_for_Points__c!=0) )
{
tbp.Points_for_Room__c =tbp.Points_for_Room__c+((tbp.Amount_for_Room__c )*(pc.Room_Points__c/pc.Room_Amount_for_Points__c)) ;
}

// ------------------------------Plan-----------------------------
if( (tbp.Service_Type__c.contains('Plan'))&&(pc.Calculate_Points__c==true)&&(pc.Plan_Amount_for_Points__c!=0) )
{
tbp.Points_for_Plan__c =tbp.Points_for_Others__c+((tbp.Amount_for_Plan__c )*(pc.Plan_Points__c/pc.Plan_Amount_for_Points__c)) ;
}


// ------------------------------Tax-----------------------------
if( (pc.Calculate_Points__c==true)&&(pc.Tax_Amount_for_Points__c!=0) )
{
tbp.Points_for_Tax__c =tbp.Points_for_Tax__c+((tbp.Amount_for_Tax__c )*(pc.Tax_Points__c/pc.Tax_Amount_for_Points__c)) ;
}

}


}

}
else
{
if((pc.Amount_in_Consideration__c=='Bill Amount inc. Tax')&&(pc.Calculate_Points__c==true)&&(pc.Amount__c!=0) )
{

tbp.Points_Earned__c =tbp.Points_Earned__c+((tbp.Amount_Spent__c+tbp.Tax_Amount__c)*(pc.Points__c/pc.Amount__c)) ;

}

if((pc.Amount_in_Consideration__c=='Bill Amount exl. Tax')&&(pc.Calculate_Points__c==true)&&(pc.Amount__c!=0) )
{
tbp.Points_Earned__c =tbp.Points_Earned__c+((tbp.Amount_Spent__c)*(pc.Points__c/pc.Amount__c)) ;

}
}

}
catch(Exception e)
{
//tbp.addError(String.valueOf( e.getMessage() ));
}

}

}
}
catch(Exception e)
{
//tbp.addError(e.getMessage()+'123');

}
}
}

Hi,

 

I have a trigger mentioned below for which I am trying to write a Test Method, but finding difficulties, can anybody help me on the same:

 

trigger CalculateMaxPoints on Survey__c (before insert, before update)
{
   for(Survey__c srv:trigger.new)
      {  
         List<Survey_Question__c> sqrlist =[select Points__c,Type__c from   Survey_Question__c where Survey__c =:srv.id ];
         Integer maxpoint=0;
         for(Survey_Question__c sq:sqrlist)
         {     
             if((sq.Type__c!='Free Text')&&(sq.Points__c!=null))
             { 
               
               List<String>  pointList  = sq.Points__c.split('\n');
               if((sq.Type__c =='Single Select--Vertical')||(sq.Type__c =='Single Select--Horizontal')||(sq.Type__c =='Free Text'))
               {    
                  Integer pointsel=0;
                   for(Integer p = 0 ;p < pointList.size();p++ )
                   { 
                     
                     String point = pointList.get(p).trim();
                     if(pointsel < integer.valueof(point))
                     try
                     {
                     pointsel =  integer.valueof(point);
                     }
                     catch(Exception e)
                     {
                     
                     }
                     
                      
                   } 
                  maxpoint = maxpoint + pointsel;  
               }
                
               if(sq.Type__c =='Multi-Select--Vertical')             
                {  
                   String point;
                   for(Integer p = 0 ;p < pointList.size();p++ )
                   {  
                     try
                     {
                     maxpoint = maxpoint+ integer.valueof(pointList.get(p).trim());
                     }
                     catch(Exception e)
                     {
                     } 
                   } 
               } 
               
            }     
      }
      srv.Maximum_points__c = maxpoint;
       
   }
}

Hi,

 

I have a Apex class written as below. I need help on how to write test method for the same:

 

public with sharing class Controller{

  
    
    public ApexPages.StandardController standardContactController;
        
    public Controller(ApexPages.StandardController cntrl) {
        
        standardContactController = cntrl;
      
    }
    public pageReference doSaveAll() 
    {
        
        pageReference p;
         
        try
        {
         Guest_Profile__c gp = (Guest_Profile__c)standardContactController.getRecord();
         
         standardContactController.save();
         
         
         p=new pageReference ( 'https://idsfortune-developer-edition.na12.force.com/apex/My_Profile_Edit?id='+gp.id+'&save=0');
          
        }
        catch(Exception e)
        {
        
        }
        return p;
    }
    
    
     public pageReference doEdit() 
    {
        
        pageReference p;
         
        try
        {
         Guest_Profile__c gp = (Guest_Profile__c)standardContactController.getRecord();
         
         standardContactController.edit();
         
         
         p=new pageReference ( 'https://idsfortune-developer-edition.na12.force.com/apex/My_Profile_Save?id='+gp.id+'');
          
        }
        catch(Exception e)
        {
        
        }
        return p;
    }
}

 

 

Hi,

 

I have enabled the twitter force application in my organization. But when I try to login with the twitter credentials, I am getting the below error:

 

<?xml version="1.0" encoding="UTF-8"?> <errors> <error code="53">Basic authentication is not supported</error> </errors>

 

Kindly help me on the above issue as it is critical and need to be completed soon.

 

 

Hi,

 

I am trying to soft code all the links present in a visual force page by writing the link in the class and calling the class to refer those links. Before doing that I would like to clear some doubts on the same:

 

We have some id's present in the visual force page which is used to link the record types, will the id's affect working of the code when the package is installed in another instance?

Hi,

 

I am trying to write the test method for the below class, but I am not able to cross the coverage of 65%. Can anybody help me on this as it is very urgent.

 

Please find the code below of both Apex class and the test class:

 

public class AddLineItems
{

public AddLineItems(ApexPages.StandardSetController controller)
{
op=[Select id,Name from Opportunity where id=:ApexPages.currentPage().getParameters().get('id')];

lineitem1= new App_Account_Opportunity_Link__c();
lineitem2= new App_Account_Opportunity_Link__c();
lineitem3= new App_Account_Opportunity_Link__c();
lineitem4= new App_Account_Opportunity_Link__c();
lineitem5= new App_Account_Opportunity_Link__c();
lineitem6= new App_Account_Opportunity_Link__c();
lineitem7= new App_Account_Opportunity_Link__c();
lineitem8= new App_Account_Opportunity_Link__c();
lineitem9= new App_Account_Opportunity_Link__c();
lineitem10= new App_Account_Opportunity_Link__c();

}

public App_Account_Opportunity_Link__c lineitem1{get;set;}
public App_Account_Opportunity_Link__c lineitem2{get;set;}
public App_Account_Opportunity_Link__c lineitem3{get;set;}
public App_Account_Opportunity_Link__c lineitem4{get;set;}
public App_Account_Opportunity_Link__c lineitem5{get;set;}
public App_Account_Opportunity_Link__c lineitem6{get;set;}
public App_Account_Opportunity_Link__c lineitem7{get;set;}
public App_Account_Opportunity_Link__c lineitem8{get;set;}
public App_Account_Opportunity_Link__c lineitem9{get;set;}
public App_Account_Opportunity_Link__c lineitem10{get;set;}

public Opportunity op{get;set;}



public AddLineItems()
{
}


Public PageReference savedata()
{

if(lineitem1.App_Account__c!= null)
{
lineitem1.Opportunity__c= op.Id;
insert lineitem1;
}

if(lineitem2.App_Account__c!= null)
{
lineitem2.Opportunity__c=op.Id;
insert lineitem2;
}

if(lineitem3.App_Account__c!= null)
{
lineitem3.Opportunity__c=op.Id;
insert lineitem3;
}

if(lineitem4.App_Account__c!= null)
{
lineitem4.Opportunity__c=op.Id;
insert lineitem4;
}

if(lineitem5.App_Account__c!= null)
{
lineitem5.Opportunity__c=op.Id;
insert lineitem5;
}

if(lineitem6.App_Account__c!= null)
{
lineitem6.Opportunity__c=op.Id;
insert lineitem6;
}

if(lineitem7.App_Account__c!= null)
{
lineitem7.Opportunity__c=op.Id;
insert lineitem7;
}

if(lineitem8.App_Account__c!= null)
{
lineitem8.Opportunity__c=op.Id;
insert lineitem8;
}

if(lineitem9.App_Account__c!= null)
{
lineitem9.Opportunity__c=op.Id;
insert lineitem9;
}

if(lineitem10.App_Account__c!= null)
{
lineitem10.Opportunity__c=op.Id;
insert lineitem10;
}



PageReference oppty=new PageReference('/' + op.Id);

oppty.setRedirect(true);

return oppty;
}


}

 

Test Class:

@istest
private class TestMassAddLineItems
{
static testmethod void MassAddLineItems()
{
Id userId =UserInfo.getUserId();

User us =[Select id from User where id=:userId ];

Opportunity o=new Opportunity();
o.Name='Test Opportunity';
o.StageName='Hotel Loading Only';
o.CloseDate=date.Today();
o.Client_Services_Manager__c=us.id;
insert o;


App_Account__c a = new App_Account__c();
a.Name='Test App Account';
insert a;


App_Account_Opportunity_Link__c aaol=new App_Account_Opportunity_Link__c();
aaol.Opportunity__c=o.id;
aaol.App_Account__c=null;
insert aaol;

List<Opportunity> opp = [Select id from Opportunity where id = :o.Id];


ApexPages.StandardSetcontroller sc1 = New ApexPages.StandardSetController(opp);
System.CurrentPageReference().getParameters().put('Id',o.Id);

AddLineItems li1=new AddLineItems();
AddLineItems li=new AddLineItems(sc1);

li.savedata();

aaol.App_Account__c = a.Id;
update aaol;

li.savedata();



}

}

Hi,

 

We are planning to build a functionality where we need to have a report to check the number of times a record is viewed on the Account object. 

 

I need to build a apex code which will capture the number of times a record is opened. Can anybody help or suggest me how can I achieve this. 

 

Would appreciate any help regarding this as it is critical.

 

 

Hi,

 

I am using a trigger to call the future method, but it gives me a error which says "Too many Future calls". There are 100 of records inserted, after which this method is called. Is there any way where I can overcome this error.

 

Please give me some inputs on this.

 

Thanks.

Hi All,

I am facing a issue when trying to create a signedURL for amazon private file in salesforce.

<Error><Code>SignatureDoesNotMatch</Code>

<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.

</Message>

 

Is there any method for creating 'Time Limited Signed URL'. Please let me know

 

 

Here is my code for creating signature:


        Datetime now = system.now();
        String formattednow = now.formatGmt('yyyy-MM-dd')+'T'+now.formatGmt('HH:mm:ss')+'.'+now.formatGMT('SSS')+'Z';

       
        String canonical = 'AmazonS3'+'ListAllMyBuckets'+formattednow; //"AmazonS3" + OPERATION + Timestamp       
        
        Blob bsig = Crypto.generateMac('HmacSHA1', Blob.valueOf(canonical), Blob.valueOf(secret));       
        
        String signature = EncodingUtil.base64Encode(bsig);

 

Thanks in advance

 

Hi,

 

Does anybody know how to create a HTML Email template using a trigger or Apex class. I have tried creating a EmailTemplate using trigger but it throws an Mixed DML exception.

 

I am not able to figure out the solution for the same. 

 

Kindly give an solution ASAP.

 

 

Hi,

 

We have a managed packaged which has been made as released version and privately listed in the appexchange for the security review. Now we want to add some components and also remove some components from the package, but we are unable to do that. We are not finding the right steps to manage the package.

 

Also we have a patch organization where it allows to edit the existing components but will not allow to add the components. Can anybody let me know how to overcome these difficulties?

 

Regards,

Sunay

Hi,

 

We have created a managed package, but when we try to add a patch by clicking on "Patch Organizations", we are not able to see the New button. Is there any settings which has to be made for this button to be visible.

 

 

Hi,

 

We have developed a App and we need to create a work around as mentioned below. Can anybody suggest is this possible and if yes how to go about it:

 

Once a managed package is created and published, the user should be able to enter a unique code given by us before he installs the package. And once the unique code is entered, an API is called which will search our database if the code already exists or not, if yes what is the customer name, date of purchase, license validity and so on.

 

Hence we would like to know whether we can achieve this work around successfully.

 

Hi,

 

Can anyone please help me on writing test class for the below Apex class:

 

public Voucher()
{

voucherId ='';

statusmessage='';

guestId = ApexPages.currentPage().getParameters().get('gId');

rewardId = ApexPages.currentPage().getParameters().get('rwId');

Guest_Profile__c gp = [Select id ,Guest_Name__c, Points_Balance__c from Guest_Profile__c where id=:guestId ];

Reward__c reward = [Select id ,Points__c,Voucher_Images_Html__c from Reward__c where id=:rewardId ];

guestName = gp.Guest_Name__c;

htmlsource=reward.Voucher_Images_Html__c ;

currentPoints = gp.Points_Balance__c;

rewardpoints = reward.Points__c;

}


public Pagereference voucherNumber()
{


Voucher__c voucher = new Voucher__c();

Guest_Profile__c gp = [Select id , Points_Balance__c from Guest_Profile__c where id=:guestId ];

Reward__c reward = [Select id ,Points__c from Reward__c where id=:rewardId ];

currentPoints = gp.Points_Balance__c ;

if((currentPoints -reward.Points__c) < 0)

statusmessage='Please get More Points to Redeem this Reward.';

else

currentPoints = currentPoints -reward.Points__c;

Redemption_History__c redeem = new Redemption_History__c() ;

redeem.Guest_Name__c = gp.id;

redeem.Redeemed_Points__c = reward.Points__c;

redeem.Remaining_Points__c = currentPoints ;

redeem.Reward_Name__c = reward.id;

insert voucher;

redeem.Voucher_No__c = voucher.id;

insert redeem;

voucherId = voucher.id;

return null;

}

 

Kindly do the needful asap.

Hi,

 

Can anybody help me on the test method for the Apex trigger below. I am finding difficulties while writing test cases for the conditions used:

 

trigger membership_for_loyalty_programme on Transaction_Breakup__c (before insert,before update)
{

Boolean calculate_points=false;

for(Transaction_Breakup__c tbp:trigger.new)
{
List< Loyalty_Program__c> Loyalty_Program_List;

Membership__c Membership_Selected;

Visit_Details__c vis =[Select Property_Wise_Revenue__c from Visit_Details__c where id=:tbp.Transaction_Detail_No__c];

Property_Wise_Revenue__c pwr =[Select id,No_of_Room_Nights__c, Loyalty_Programme_Record_Type__c, No_of_Stays__c,Property__c,Guest_Profiile_Id__c,Property_Name__c, Total_expenditure_against_property__c from Property_Wise_Revenue__c where id=:vis.Property_Wise_Revenue__c ];

Loyalty_Program_List = [select id, Name, Automatically_Assigned__c, Consider_Tax_for_Overall_Expense__c, Upgrade_Memberships_Automatically__c, RecordType.Name, No_of_Stays__c,No_of_Room_Nights__c, Overall_Expense__c, Duration__c from Loyalty_Program__c where Active__c = true ORDER BY Overall_Expense__c, No_of_Room_Nights__c, No_of_Stays__c ];

try
{
if(Loyalty_Program_List.size() > 0 )
{

Loyalty_Program__c Loyalty_Program_Selected=new Loyalty_Program__c(No_of_Room_Nights__c =0,Name='temp',No_of_Stays__c =0,Overall_Expense__c=0) ;

System.debug(Loyalty_Program_Selected);

for(Loyalty_Program__c Loyalty_Program:Loyalty_Program_List)
{

Date minDate =Date.Today()-(Integer.valueof(Loyalty_Program.Duration__c)*30);

AggregateResult groupedResults;

if(Loyalty_Program.Consider_Tax_for_Overall_Expense__c==true)

groupedResults = [SELECT SUM(Total_Amount_Incl_Tax__c) SumExp,SUM(No_of_Room_Nights__c) SumNights from Visit_Details__c where Property_Wise_Revenue__c=:pwr.Id AND Check_In_Date1__c >=:minDate ];

else

groupedResults = [SELECT SUM(Total_Amount_Excl_Tax__c) SumExp,SUM(Room_Nights__c) SumNights from Visit_Details__c where Property_Wise_Revenue__c=:pwr.Id AND Check_In_Date1__c >=:minDate ];

Integer number_of_stays = [SELECT COUNT() from Visit_Details__c where Property_Wise_Revenue__c=:pwr.Id AND Check_In_Date1__c >=:minDate ];

// if(Loyalty_Program.RecordType.Name=='Stay Based Membership')
{

if((number_of_stays >= Loyalty_Program.No_of_Stays__c)&&(Loyalty_Program_Selected.No_of_Stays__c<Loyalty_Program.No_of_Stays__c))
{

Loyalty_Program_Selected = Loyalty_Program ;

}

}

// if(Loyalty_Program.RecordType.Name=='Room Night based Membership')
{
if(((Decimal)groupedResults.get('SumNights') >= Loyalty_Program.No_of_Room_Nights__c)&&(Loyalty_Program_Selected.No_of_Room_Nights__c<Loyalty_Program.No_of_Room_Nights__c) )
{
Loyalty_Program_Selected = Loyalty_Program ;
}

}
// if(Loyalty_Program.RecordType.Name=='Revenue Based Membership')
{

Decimal Overall_Amount=0.0;

if((Loyalty_Program_Selected.Overall_Expense__c<Loyalty_Program.Overall_Expense__c))
{

if(Loyalty_Program.Consider_Tax_for_Overall_Expense__c==true )

Overall_Amount = (Decimal)groupedResults.get('SumExp')+tbp.Amount_Spent__c+tbp.Tax_Amount__c;

else

Overall_Amount = (Decimal)groupedResults.get('SumExp')+tbp.Amount_Spent__c;

if(Overall_Amount>=Loyalty_Program.Overall_Expense__c )
{

Loyalty_Program_Selected = Loyalty_Program ;

}

}

}
}

List< Membership__c> Membership_List =[select id,Active__c,Test__c,Loyalty_Program_Name__c,Loyalty_Program_Name__r.Id from Membership__c where Guest_Name__c =: pwr.Guest_Profiile_Id__c AND Property_Name__c =: pwr.Property__c];

if(Membership_List.size() > 0)
{
calculate_points=true;

Boolean selected =false;

for(Membership__c Membership:Membership_List)
{
if((Membership.Loyalty_Program_Name__r.Id!=Loyalty_Program_Selected.Id)&&(Loyalty_Program_Selected.Name!='temp'))
{
Membership.Active__c = false;


System.debug('BBBB');
}
else
{
Membership.Active__c = true;


System.debug('AAAAAA');

selected = true;


}

update Membership;

Membership_Selected = Membership;
}

if((!selected)&&(Loyalty_Program_Selected.Name!='temp')&&(Loyalty_Program_Selected.Automatically_Assigned__c == true))
{

Membership__c Membership_New =new Membership__c();

Membership_New.Guest_Name__c = pwr.Guest_Profiile_Id__c;

Membership_New.Property_Name__c=pwr.Property__c;

Membership_New.Loyalty_Program_Name__c =Loyalty_Program_Selected.id;

Membership_New.Active__c = true;

insert Membership_New;

Membership_Selected = Membership_New;

}

if((Loyalty_Program_Selected.Name!='temp')&& (Loyalty_Program_Selected.Automatically_Assigned__c == false))
{

Guest_Profile__c gp =[select id,Eligible_Loyalty_Program__c,Loyalty_programme_assigned_property__c from Guest_Profile__c where id =:pwr.Guest_Profiile_Id__c];

gp.Eligible_Loyalty_Program__c =Loyalty_Program_Selected.Name;

gp.Loyalty_programme_assigned_property__c =pwr.Property_Name__c;

update gp;
}

}
else
{

if((Loyalty_Program_Selected.Name!='temp')&& (Loyalty_Program_Selected.Automatically_Assigned__c == true))
{

Membership__c Membership_New =new Membership__c();

Membership_New.Guest_Name__c = pwr.Guest_Profiile_Id__c;

Membership_New.Property_Name__c=pwr.Property__c;

Membership_New.Test__c ='test';

Membership_New.Loyalty_Program_Name__c =Loyalty_Program_Selected.id;

Membership_New.Active__c = true;

insert Membership_New;

calculate_points=true;

Membership_Selected = Membership_New;


}
if((Loyalty_Program_Selected.Name!='temp')&& (Loyalty_Program_Selected.Automatically_Assigned__c == false))
{

calculate_points=false;

Guest_Profile__c gp =[select id,Eligible_Loyalty_Program__c,Loyalty_programme_assigned_property__c from Guest_Profile__c where id =:pwr.Guest_Profiile_Id__c];

gp.Eligible_Loyalty_Program__c =Loyalty_Program_Selected.Name;

gp.Loyalty_programme_assigned_property__c =pwr.Property_Name__c;

update gp;

}
}



Membership__c Membership_Active =[select id,Active__c,Test__c,Loyalty_Program_Name__c,Loyalty_Program_Name__r.Id from Membership__c where Guest_Name__c =: pwr.Guest_Profiile_Id__c AND Property_Name__c =: pwr.Property__c AND Active__c =: true];




if(calculate_points)
{
Point_Conversion__c pc;
try
{

System.debug(Membership_Selected.Loyalty_Program_Name__c);
pc =[Select id, Active__c,Service_Type__c,Split_Beverage__c,Split_by_Service_Type__c,Split_Room_Charges__c,Amount_in_Consideration__c,Point_Calculation_By__c, Calculate_Discounts__c, Calculate_Points__c, Calculate_Points_for_Tax_Amount__c,
Consider_Discount__c, Discount_Consideration__c, Property_Name__c, Revenue_Code__c, Revenue_Type__c, Revenue_Type_Formula__c, X1_point__c, Amount__c, Points__c, Discount_for_Total_Amount__c, Dicount_Percent__c, Applicable_From__c, Beverage_Amount_for_Points__c, Beverage_Discount__c, Beverage_Points__c, Food_Amount_for_Points__c, Food_Discount__c, Food_Points__c, Liquor_Amount_for_Points__c, Liquor_Discount__c, Liquor_Points__c, Other_Amount_for_Points__c, Other_Discount__c, Other_Points__c, Plan_Amount_for_Points__c, Plan_Discount__c, Plan_Points__c, Room_Amount_for_Points__c, Room_Discount__c, Room_Points__c, Soft_Drink_Amount_for_Points__c, Soft_Drink_Discount__c, Soft_Drink_Points__c, Tax_Amount_for_Points__c, Tax_Discount__c, Tax_Points__c, Tobacco_Amount_for_Points__c, Tobacco_Discount__c, Tobacco_Points__c from Point_Conversion__c where Loyalty_Program_Name__c =:Membership_Active .Loyalty_Program_Name__c AND Active__c=:true];





if(pc.Split_by_Service_Type__c ==true)
{


if(pc.Amount_in_Consideration__c =='Bill Amount inc. Tax')
{


if(pc.Calculate_Points_for_Tax_Amount__c==true)
{

if((pc.Service_Type__c.contains('Food'))&&(pc.Calculate_Points__c==true)&&(pc.Food_Amount_for_Points__c!=0) )
{
tbp.Points_for_Food__c =tbp.Points_for_Food__c+((tbp.Amount_for_Food__c+tbp.Tax_for_Food__c)*(pc.Food_Points__c/pc.Food_Amount_for_Points__c)) ;

}


// ------------------------------Beverage-----------------------------

if( (tbp.Service_Type__c.contains('Beverage'))&&(pc.Calculate_Points__c==true)&&(pc.Beverage_Amount_for_Points__c!=0) )
{
tbp.Points_for_Beverage__c =tbp.Points_for_Beverage__c+((tbp.Amount_for_Beverage__c+tbp.Tax_for_Beverage__c)*(pc.Beverage_Points__c/pc.Beverage_Amount_for_Points__c)) ;

}


// ------------------------------Liquor-----------------------------

if( (tbp.Service_Type__c.contains('Liquor'))&&(pc.Calculate_Points__c==true)&&(pc.Liquor_Amount_for_Points__c!=0) )
{
tbp.Points_for_Liquor__c =tbp.Points_for_Liquor__c+((tbp.Amount_for_Liquor__c+tbp.Tax_for_Liquor__c)*(pc.Liquor_Points__c/pc.Liquor_Amount_for_Points__c)) ;

}


// ------------------------------Soft_Drink-----------------------------

if( (tbp.Service_Type__c.contains('Soft Drinks'))&&(pc.Calculate_Points__c==true)&&(pc.Soft_Drink_Amount_for_Points__c!=0) )
{
tbp.Points_for_Soft_Drink__c =tbp.Points_for_Soft_Drink__c+((tbp.Amount_for_Soft_Drink__c+tbp.Tax_for_Soft_Drink__c)*(pc.Soft_Drink_Points__c/pc.Soft_Drink_Amount_for_Points__c)) ;

}


// ------------------------------Tobacco-----------------------------

if( (tbp.Service_Type__c.contains('Tobacco'))&&(pc.Calculate_Points__c==true)&&(pc.Tobacco_Amount_for_Points__c!=0) )
{
tbp.Points_for_Tobacco__c =tbp.Points_for_Tobacco__c+((tbp.Amount_for_Tobacco__c+tbp.Tax_for_Tobacco__c)*(pc.Tobacco_Points__c/pc.Tobacco_Amount_for_Points__c)) ;

}

// ------------------------------Others-----------------------------
if( (tbp.Service_Type__c.contains('Others'))&&(pc.Calculate_Points__c==true)&&(pc.Other_Amount_for_Points__c!=0) )
{
tbp.Points_for_Others__c =tbp.Points_for_Others__c+((tbp.Amount_for_Others__c+tbp.Tax_for_Others__c)*(pc.Other_Points__c/pc.Other_Amount_for_Points__c)) ;
}

// ------------------------------Room-----------------------------
if( (tbp.Service_Type__c.contains('Room'))&&(pc.Calculate_Points__c==true)&&(pc.Room_Amount_for_Points__c!=0) )
{
tbp.Points_for_Room__c =tbp.Points_for_Room__c+((tbp.Amount_for_Room__c )*(pc.Room_Points__c/pc.Room_Amount_for_Points__c)) ;
}

// ------------------------------Plan-----------------------------
if( (tbp.Service_Type__c.contains('Plan'))&&(pc.Calculate_Points__c==true)&&(pc.Plan_Amount_for_Points__c!=0) )
{
tbp.Points_for_Plan__c =tbp.Points_for_Others__c+((tbp.Amount_for_Plan__c )*(pc.Plan_Points__c/pc.Plan_Amount_for_Points__c)) ;
}


}

if(pc.Calculate_Points_for_Tax_Amount__c==false)
{


if((pc.Service_Type__c.contains('Food'))&&(pc.Calculate_Points__c==true)&&(pc.Food_Amount_for_Points__c!=0) )
{
tbp.Points_for_Food__c =tbp.Points_for_Food__c+((tbp.Amount_for_Food__c )*(pc.Food_Points__c/pc.Food_Amount_for_Points__c)) ;

}

// ------------------------------Beverage-----------------------------

if( (tbp.Service_Type__c.contains('Beverage'))&&(pc.Calculate_Points__c==true)&&(pc.Beverage_Amount_for_Points__c!=0) )
{
tbp.Points_for_Beverage__c =tbp.Points_for_Beverage__c+((tbp.Amount_for_Beverage__c )*(pc.Beverage_Points__c/pc.Beverage_Amount_for_Points__c)) ;

}

// ------------------------------Liquor-----------------------------

if( (tbp.Service_Type__c.contains('Liquor'))&&(pc.Calculate_Points__c==true)&&(pc.Liquor_Amount_for_Points__c!=0) )
{
tbp.Points_for_Liquor__c =tbp.Points_for_Liquor__c+((tbp.Amount_for_Liquor__c )*(pc.Liquor_Points__c/pc.Liquor_Amount_for_Points__c)) ;

}


// ------------------------------Soft_Drink-----------------------------

if( (tbp.Service_Type__c.contains('Soft Drinks'))&&(pc.Calculate_Points__c==true)&&(pc.Soft_Drink_Amount_for_Points__c!=0) )
{
tbp.Points_for_Soft_Drink__c =tbp.Points_for_Soft_Drink__c+((tbp.Amount_for_Soft_Drink__c )*(pc.Soft_Drink_Points__c/pc.Soft_Drink_Amount_for_Points__c)) ;

}


// ------------------------------Tobacco-----------------------------

if( (tbp.Service_Type__c.contains('Tobacco'))&&(pc.Calculate_Points__c==true)&&(pc.Tobacco_Amount_for_Points__c!=0) )
{
tbp.Points_for_Tobacco__c =tbp.Points_for_Tobacco__c+((tbp.Amount_for_Tobacco__c )*(pc.Tobacco_Points__c/pc.Tobacco_Amount_for_Points__c)) ;

}

// ------------------------------Room-----------------------------
if( (tbp.Service_Type__c.contains('Room'))&&(pc.Calculate_Points__c==true)&&(pc.Room_Amount_for_Points__c!=0) )
{
tbp.Points_for_Room__c =tbp.Points_for_Room__c+((tbp.Amount_for_Room__c )*(pc.Room_Points__c/pc.Room_Amount_for_Points__c)) ;
}

// ------------------------------Plan-----------------------------
if( (tbp.Service_Type__c.contains('Plan'))&&(pc.Calculate_Points__c==true)&&(pc.Plan_Amount_for_Points__c!=0) )
{
tbp.Points_for_Plan__c =tbp.Points_for_Others__c+((tbp.Amount_for_Plan__c )*(pc.Plan_Points__c/pc.Plan_Amount_for_Points__c)) ;
}


// ------------------------------Tax-----------------------------
if( (pc.Calculate_Points__c==true)&&(pc.Tax_Amount_for_Points__c!=0) )
{
tbp.Points_for_Tax__c =tbp.Points_for_Tax__c+((tbp.Amount_for_Tax__c )*(pc.Tax_Points__c/pc.Tax_Amount_for_Points__c)) ;
}

}


}

}
else
{
if((pc.Amount_in_Consideration__c=='Bill Amount inc. Tax')&&(pc.Calculate_Points__c==true)&&(pc.Amount__c!=0) )
{

tbp.Points_Earned__c =tbp.Points_Earned__c+((tbp.Amount_Spent__c+tbp.Tax_Amount__c)*(pc.Points__c/pc.Amount__c)) ;

}

if((pc.Amount_in_Consideration__c=='Bill Amount exl. Tax')&&(pc.Calculate_Points__c==true)&&(pc.Amount__c!=0) )
{
tbp.Points_Earned__c =tbp.Points_Earned__c+((tbp.Amount_Spent__c)*(pc.Points__c/pc.Amount__c)) ;

}
}

}
catch(Exception e)
{
//tbp.addError(String.valueOf( e.getMessage() ));
}

}

}
}
catch(Exception e)
{
//tbp.addError(e.getMessage()+'123');

}
}
}