- Team Works
- NEWBIE
- 160 Points
- Member since 2013
- Salesforce Technical Analyst/Developer
- Cloud9Force Ltd, UK
-
ChatterFeed
-
3Best Answers
-
2Likes Received
-
0Likes Given
-
31Questions
-
99Replies
Help: Trigger not Working
Hi,
This is my first post on the board and am hoping someone can help!
I created a trigger to populate a custom Task field (Opportunity_Close_Date__c) with the Opportunity Close Date.
Below please find my trigger and the test class I wrote.
The problem is that I'm getting 100% code coverage but the test is failing (Error Message: System.AssertException: Assertion Failed).
Any ideas or help would be greatly appreciated!!
Thanks!
Here's the trigger:
trigger OppCloseDate on Opportunity (after insert, after update) { Set<Id> oppIds = new Set<Id>(); Set<Id> taskIds = new Set<Id>();{ for(Task t:[select Id, WhatID from Task]){ String wId = t.WhatId; if(wId!=null && wId.startsWith('006')){ taskids.add(t.WhatId); for(Opportunity to:[select Id from Opportunity where Id in :taskIds]){ oppIds.add(to.ID); } Set<Id> oppstoupdate = new Set<Id>(); for(Integer i=0;i<trigger.new.size();i++){ if(oppIds.contains(trigger.new[i].Id)){ oppstoupdate.add(Trigger.new[i].id); if(oppstoupdate.size() > 0){ List<Opportunity> oList = [select Id, CloseDate from Opportunity where Id in :oppstoupdate]; List<Task> taskstoupdate = new List<Task>();{ for(Task tsk : [select Id, Opportunity_Close_Date__c from Task where WhatId in :oppstoupdate]){ tsk.Opportunity_Close_Date__c = oList[0].CloseDate; taskstoupdate.add(tsk); } } if(!taskstoupdate.isEmpty()){ update taskstoupdate; } } } } } } } }
And here's the test class:
@isTest private class Test_OppCloseDate { public static testMethod void myUnitTest(){ List<Opportunity> opp1 = new List<Opportunity>{ new Opportunity( Name = 'Test Opp1', StageName = 'Closed Won', Type = 'New Business', CloseDate = Date.today()+7, Demo_ID__c = NULL, LicenseType__c = 'Enterprise')}; insert opp1; List<Opportunity> opp2 = new List<Opportunity>{ new Opportunity( Name = 'Test Opp2', StageName = 'Closed Won', Type = 'New Business', CloseDate = Date.today()+2, LicenseType__c = 'Enterprise')}; insert opp2; List<Task> tsk1 = new List<Task>{ new Task( WhatId = opp1[0].id, Subject = 'Task 2', Status = 'Not Started', Priority = 'Normal', Type = 'Demonstration - In Person')}; insert tsk1; List<Task> tsk2 = new List<Task>{ new Task( WhatId = NULL, Subject = 'Task 2', Status = 'Not Started', Priority = 'Normal', Type = 'Demonstration - Web/Phone')}; insert tsk2; List<Opportunity> oppstoupdate1 = New List<Opportunity>{ [select id from Opportunity where id in :opp1]}; for(Opportunity oOP:oppstoupdate1) oOP.CloseDate = Date.today(); Update oppstoupdate1; List<Task> taskstoupdate2 = New List<Task>{ [select id from task where id in :tsk2]}; for(task tOK:taskstoupdate2) tOK.WhatId = opp2[0].id; Update taskstoupdate2; Task [] tasks1 = [select ID, Opportunity_Close_Date__c from Task where ID in :tsk1]; System.assert(tasks1[0].Opportunity_Close_Date__c == (opp1[0].CloseDate)); Task [] tasks2 = [select ID, Opportunity_Close_Date__c from Task where ID in :tsk2]; System.assert(tasks2[0].Opportunity_Close_Date__c == (opp2[0].CloseDate)); } }
-
- Season1224
- August 26, 2013
- Like
- 0
- Continue reading or reply
Need some SOQL help with aggregate, will give kudos
First problem, when I enter the "Having" statement in soql the Force.com Explorer freezes up.
Second problem, When I run it without the "Having" and with a formula field other than ProductId__c this query runs successfully but not as desired.
When I use other formula fields to summorize by like Product_Name__c which is another formula field this query runs just fine but again without the having and the product id it doesn't work as desired.
This is the formula fields definition: PricebookEntry.Product2Id - on the OpportunityLineItem object.
Below is the query with a id hard coded for testing purposes in the Force.com Explorer.
select ProductId__c ,sum(Quantity) Quantity From OpportunityLineItem Where (Classification__c = 'Software' or Classification__c = 'Professional Services' or Classification__c = 'Bundle (SW w/ HW)') and Case_Id__c = '5007000000LcHVP' Group By ProductId__c Having sum(Quantity) > 1
I will give kudos to anyone that has an idea as to where I've gone wrong.
Thank you,
Steve Laycock
-
- RelaxItsJustCode
- August 26, 2013
- Like
- 0
- Continue reading or reply
Campaign Trigger update
Hello everyone,
I created a trigger on Campaign Member and the purpose is to update the fields of the campaign member from the Lead it is associated with.
I am not able to figure out why the code is not updating the campaign member record even though it is hitting the code:
Following is my trigger:
trigger CampaignMemberAfter on CampaignMember(after insert, after update, after delete)
{
List<CampaignMember> camMembers = trigger.IsInsert || trigger.IsUpdate ? trigger.new : trigger.old;
if(trigger.isUpdate)
{
CampaignMemberClass.UpdateCampaignMember(camMembers);
}
}
Following is my class:
public class CampaignMemberClass
{
public static void UpdateCampaignMember(List<CampaignMember> camMembers)
{
Map<Id,CampaignMember> campaignLeads = new Map<Id,CampaignMember>{};
Map<Id,CampaignMember> campaignMems = new Map<Id,CampaignMember>{};
for(CampaignMember cm : camMembers)
{
campaignLeads.put(cm.LeadId, cm);
campaignMems.put(cm.Id, cm);
}
List<CampaignMember> CMsToUpdate = new List<CampaignMember>{};
for(CampaignMember CMem : [Select LeadId,Id,Lead.avg_attendance__c,Lead.avg_ticket_price__c,Lead.Estimated_Annual_Revenue__c,Average_Attendance__c, Average_Ticket_Price__c, Estimated_Annual_Rev__c from CampaignMember where Id in :campaignMems.keySet()])
{
CMem.Average_Attendance__c = Cmem.Lead.avg_attendance__c ;
CMem.Average_Ticket_Price__c = CMem.Lead.avg_ticket_price__c ;
CMem.Estimated_Annual_Rev__c = CMem.Lead.Estimated_Annual_Revenue__c;
CMem.Lead_Status__c = 'Open';
System.debug('AVERAGE ATTENDANCE LEAD VALUE '+ Cmem.Lead.avg_attendance__c);
System.debug('AVERAGE ATTENDANCE LEAD VALUE '+ Cmem.Lead.avg_ticket_price__c);
System.debug('AVERAGE ATTENDANCE LEAD VALUE '+ Cmem.Lead.avg_attendance__c);
CMsToUpdate.add(CMem) ;
}
}
}
Please help me in figuring out what I am missing.
-
- LauraStephens
- August 19, 2013
- Like
- 0
- Continue reading or reply
sending emails
Again i have comeup with some issues which i need help with....my learning curve
I need to create a generic class, method where i can pass the templateid, email address and the object or whatid ....i can call that method to send the emails to customers when the order(Custom Obj) has reached a certain stage in the order provisioning. The order stage is updated from external provisioning sytem via integration.
Please help with the logic
Yours
Newbie
-
- Team Works
- July 08, 2014
- Like
- 0
- Continue reading or reply
Use Salesforce as Backend for my Website
My friend has got website to sell the products. He now want to use Salesforce as a Backend for their website. I am doing the Salesforce development for my friend. I need Idea on how can i achieve the following.The website is currently ecommerce with CMS.
all new products to be added by salesforce.
all invoicing to managed by salesforce.
all inventory to be managed by salesforce.
the ability to take payments for sagepay gateway via salesforce.
the ability to take phone orders where products can be selected via salesforce to build a order for a customer.
Because i know the configuration adn Apex/VF pages development
Please give me ideas and i will implement it.
Many Thanks in advance
-
- Team Works
- June 27, 2014
- Like
- 0
- Continue reading or reply
Tab Panel in a visualforce page
I have got 3 tabs on my visualforce page. In each tabs i have got a search feature. Afer i search for a record in one tab the list list is displayed for Accounts. Then i go to another tab. Once i come back yto the first tab, it does'nt refresh the list but still displays the previous search results. I tries with SwitchType Client, Ajax and server but no gain.
Any ideas welcome and thanks in advance
-
- Team Works
- June 19, 2014
- Like
- 1
- Continue reading or reply
How to concatenate strings to form a Query
Again Stuck with the concatenation :
private final String SOQL_RECENT_REC = 'SELECT LastViewedDate,Type,UserRoleId FROM RecentlyViewed';
private final String CONDITION_USER_SORT = ' Order By LastViewedDate DESC LIMIT 20';
List<RecentlyViewed> recentViewed= new List<RecentlyViewed>();
recentViewed = Database.query(SOQL_RECENT_REC +' WHERE Type = \'Account \' ' + CONDITION_USER_SORT);
Should run a query like the following :
recentViewed = [SELECT LastViewedDate,Type,UserRoleId FROM RecentlyViewed Where Type='Account' Order By LastViewedDate DESC LIMIT 20];
Many Thanks !!
-
- Team Works
- June 12, 2014
- Like
- 0
- Continue reading or reply
Custom Visual Force Page
I hope you having a good day but i am kind of stuck.
I am currently displaying the User List in a custom VF Page. When i click the Name of the User it should take the user to a Custom Visualforce page where i will display the some user details, and list of his Activities, Accounts, Opportunities. Shall i use the standard User Controller and OR a custom controller. Please Guide me the steps.
Many Thanks
-
- Team Works
- June 11, 2014
- Like
- 0
- Continue reading or reply
Database.Query -- How to concaenate this SOQL as string
string sql1 = 'Select Custom_Name__c from Opportunity where AccountId IN';
string2 sql2= '(Select Id from Account where Europe__c =True)';
Opp=Database.query(sql1+sql2);
sysem.debug(Opp);
Doesn't work.Any Ideas?
-
- Team Works
- June 10, 2014
- Like
- 0
- Continue reading or reply
HomePage Component
I need to create a Home Page component with a Tab 'Interested In'. In this tab i need to display the Accounts i am following(irrespective of I own it or not.) I am the logged in User..
Please guide/suggest
Many Thanks
-
- Team Works
- June 08, 2014
- Like
- 0
- Continue reading or reply
Display the people who report to logged in user?
I need to create a visual force page where i need to display me and people who report to logged in User(me)....ofcourse based on the role hierarchy setup in my Org.
Kindly guide me to link explaining such an example or how can i approach this?
Many Thanks
-
- Team Works
- June 08, 2014
- Like
- 0
- Continue reading or reply
Help to Consume WADL file
Has anyone used the WADL file into salesforce. I have got WADL file from another Application Team. When i import this sfile into Salesforce it errors out.
Just looking for a way to consume WADL in salesforce if anyone can help?
-
- Team Works
- May 14, 2014
- Like
- 0
- Continue reading or reply
How to use WADL for Salesforce integration to Java application
Has anyone used the WADL file into salesforce. I have got WADL file from another Application Team. When i import this sfile into Salesforce it errors out.
Just looking for a way to consume WADL in salesforce if anyone can help
Many Thanks
-
- Team Works
- May 14, 2014
- Like
- 0
- Continue reading or reply
Custom settings
Just trying to Use Custom Setting in a Formula field. I have too many custom formula field on the account Object and hit the limit of max 15. Would like to know how can i use Heirarchical Custom setting in Cross Object Formuls..Many Thanks in advance
-
- Team Works
- January 21, 2014
- Like
- 0
- Continue reading or reply
Apex Batch Job for looping thru the 3 lookup relationship
Many Thanks in advance ...
global class MasterCity_BatchJob implements Database.Batchable<SObject>{
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator([Select Id from Pseudo_City__c where RecordTypeId='012m00000004HZLAA2']);
// where Id='a0Cm000000060Ai'
}
global void execute(Database.BatchableContext BC, List<SObject> mcityscope){
List<Pseudo_City__c> scope = (List<Pseudo_City__c>)mcityscope;//Casting sObject to Master City List
system.debug('The Scope created in Execute method is >>>>>'+scope );
MasterCityBatchJobHelper MChelper = new MasterCityBatchJobHelper();
MChelper.citiesInMasterCity(scope);
}
global void finish(Database.BatchableContext BC){}
}
-----------------------------------------------------------------------------------------
//Initialize the variables which will store summaries to 0
integer mtotalLiveAccount=0;
integer mtotalfivestarHotels=0;
integer mtotalfourstarHotels =0;
integer mtotalthreestarHotels =0;
integer mTotalGTAconnectRegional = 0;
integer mTotalGTAconnectGlobal = 0;
integer mTotalGTAconnectIndependent = 0;
integer mtotalCityCenterAccount = 0;
integer mtotalAirportAccount=0;
integer mtotalRegionAccount =0;
integer mtotalPOIAccount=0;
integer mtotalTwoStarorLess=0;
double GrandTotalRNs2013=0;
integer mTotalUnCategorized =0;
public Map<Id,City__c> mcitiesToUpdate = new Map<Id,City__c>();//Map to hold the cities
List<Pseudo_City__c> masterCitiesToUpdate = new List<Pseudo_City__c>();//List of Master Cities to be updated
List<Account> accToUpdateList = new List<Account>();
//constructor
public MasterCityBatchJobHelper(){}
public PageReference analyzeAccountFromPage() {
List<Pseudo_City__c> mcities = [select id from Pseudo_City__c where id = :ApexPages.currentPage().getParameters().get('id')];
system.debug('The mCities in ANalyse Accounts from PageReference is >>>>>'+ mcities );
citiesInMasterCity(mcities);
return new Pagereference('/'+ApexPages.currentPage().getParameters().get('id'));
}
//Methods
public void citiesInMasterCity(List<Pseudo_City__c> scope) {
scope = [Select Id,City_Categorisation__c,Name,GTA_3_Hotels__c,GTA_4_Hotels__c,GTA_5_Hotels__c,GTA_2_or_less_Hotels__c,GTA_Hotels_2012__c,RN_Projection_2014_Top_Focus__c,GTA_Independant__c,GTA_Global_Chain_Hotels__c,GTA_Regional_Chain_Hotels__c,Suburbs_Airport__c,GTA_POI_Hotels__c,uncategorised_properties__c,GTA_City_Centre_Penetration__c from Pseudo_City__c where Id IN: scope];
system.debug('The SCOPE in citiesInMasterCity is >>>>> '+ scope );
for(Pseudo_city__c mcity : scope){
system.debug('The value in the mastercitiestoUpdate before update>>>>>>>>>>>> ' + mcity.id );
masterCitiesToUpdate.add(analyzeMastercity(mCity));//Loads the list with Mastercities to be updated to List
}
Database.update(masterCitiesToUpdate);//Updates and commits the calculations in the List to the Database
}
private Pseudo_city__c analyzeMasterCity(Pseudo_city__c mCity) {
for(City__c city :[Select Id, Name,Master_City_Cluster_This_Year__c,City_Location__c FROM City__c where Master_City_Cluster_This_Year__c =:mCity.Id]){
If(city.Master_City_Cluster_This_Year__c != null )
mcitiesToUpdate.put(city.id,city);
}
system.debug('The cities within the Master cities are ::>>>> '+ mcitiesToUpdate );
return summarizeAccounts(mcitiesToUpdate, mCity);
}
private Pseudo_city__c summarizeAccounts(Map<Id,City__c> mcitiesToUpdate,Pseudo_City__c mCity){
for(Account acc : [Select Id,Name,Property_Status__c,Master_City_Cluster_Tier_This_Year__c,Master_City_Name_This_Year__c,Location__c,recordTypeId,Star_Rating__c,GTA_Connect_Chain__c,DI_Master_Chain__c,ThresholdC__c,Grand_Total_RNs_2013__c,City_New__c from Account where (RecordType.developerName='Property' AND Property_Status__c='LIVE' AND City_New__c IN :mcitiesToUpdate.keySet())]){
mtotalLiveAccount += 1;
if (acc.City_new__c != null){
acc.Master_City_Name_This_Year__c = mCity.Name;
acc.Master_City_Cluster_Tier_This_Year__c = mCity.City_Categorisation__c;
accToUpdateList.add(acc);
system.debug('The Account to be updated>>>>>>> ' +accToUpdateList);
}
if(mcitiesToUpdate.get(acc.City_New__c).City_Location__c != null){
if(mcitiesToUpdate.get(acc.City_New__c).City_Location__c == 'City Center')
mtotalCityCenterAccount+= 1;
if(mcitiesToUpdate.get(acc.City_New__c).City_Location__c == 'Suburb & Airport')
mtotalAirportAccount+= 1;
if(mcitiesToUpdate.get(acc.City_New__c).City_Location__c == 'Point of interest')
mtotalPOIAccount+= 1;
}
if ((acc.Star_Rating__c=='5 Star' || acc.Star_Rating__c=='5.5 Star') && acc.Star_Rating__c != null)
mtotalfivestarHotels += 1;
if ((acc.Star_Rating__c=='4 Star' || acc.Star_Rating__c=='4.5 Star' ) && acc.Star_Rating__c != null)
mtotalfourstarHotels += 1;
if ((acc.Star_Rating__c=='3 Star' || acc.Star_Rating__c=='3 Star' ) && acc.Star_Rating__c != null )
mtotalthreestarHotels += 1;
if(acc.Star_Rating__c =='1 Star' || acc.Star_Rating__c=='2 Star' || acc.Star_Rating__c== 'NA' )
mtotalTwoStarorLess+=1;
if (!((acc.DI_Master_Chain__c == 'ACCOR') || (acc.DI_Master_Chain__c == 'BW') || (acc.DI_Master_Chain__c == 'DESIGN') || (acc.DI_Master_Chain__c == 'EC') || (acc.DI_Master_Chain__c == 'FAIRMONT') || (acc.DI_Master_Chain__c == 'HILTON') || (acc.DI_Master_Chain__c == 'HYATT') || (acc.DI_Master_Chain__c == 'IHG') || (acc.DI_Master_Chain__c == 'JUMEIRAH') || (acc.DI_Master_Chain__c == 'KI') || (acc.DI_Master_Chain__c == 'LUXE') || (acc.DI_Master_Chain__c == 'MC') || (acc.DI_Master_Chain__c == 'MK') || (acc.DI_Master_Chain__c == 'MOHG') || (acc.DI_Master_Chain__c == 'SG') || (acc.DI_Master_Chain__c == 'WY') ) && (acc.GTA_Connect_Chain__c != null) && !((acc.GTA_Connect_Chain__c == 'Intercontinental Hotels Group') || (acc.GTA_Connect_Chain__c == 'Accor Hotels') || (acc.GTA_Connect_Chain__c == 'Best Western International') || (acc.GTA_Connect_Chain__c == 'Carlson Hospitality') || (acc.GTA_Connect_Chain__c == 'Choice Hotels International') || (acc.GTA_Connect_Chain__c == 'Design Hotels') || (acc.GTA_Connect_Chain__c == 'Fairmont Raffles Swissotel Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Four Seasons Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Hilton Worldwide') || (acc.GTA_Connect_Chain__c == 'Hyatt Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'Jumeirah International LLC') || (acc.GTA_Connect_Chain__c == 'Kempinski') || (acc.GTA_Connect_Chain__c == 'KEMPINSKI HOTELS & RESORTS') || (acc.GTA_Connect_Chain__c == 'Langham Hotels') || (acc.GTA_Connect_Chain__c == 'Luxe Worldwide Hotels') || (acc.GTA_Connect_Chain__c == 'Mandarin Oriental Hotel Group') || (acc.GTA_Connect_Chain__c == 'Marriott International Inc.') || (acc.GTA_Connect_Chain__c == 'Millennium & Copthorne Hotels plc') || (acc.GTA_Connect_Chain__c == 'Moevenpick Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Shangri-La Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'Starwood Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'The Ascott Group') || (acc.GTA_Connect_Chain__c == 'Wyndham Hotel Group' ) || (acc.GTA_Connect_Chain__c == 'independent' )))
mTotalGTAconnectRegional+= 1;
if (((acc.GTA_Connect_Chain__c == 'Intercontinental Hotels Group') || (acc.GTA_Connect_Chain__c == 'Accor Hotels') || (acc.GTA_Connect_Chain__c == 'Best Western International') || (acc.GTA_Connect_Chain__c == 'Carlson Hospitality') || (acc.GTA_Connect_Chain__c == 'Choice Hotels International') || (acc.GTA_Connect_Chain__c == 'Fairmont Raffles Swissotel Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Four Seasons Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Hilton Worldwide') || (acc.GTA_Connect_Chain__c == 'Hyatt Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'Jumeirah International LLC') || (acc.GTA_Connect_Chain__c == 'Kempinski') || (acc.GTA_Connect_Chain__c == 'KEMPINSKI HOTELS & RESORTS') || (acc.GTA_Connect_Chain__c == 'Langham Hotels') || (acc.GTA_Connect_Chain__c == 'Luxe Worldwide Hotels') || (acc.GTA_Connect_Chain__c == 'Mandarin Oriental Hotel Group') || (acc.GTA_Connect_Chain__c == 'Marriott International Inc.') || (acc.GTA_Connect_Chain__c == 'Millennium & Copthorne Hotels plc') || (acc.GTA_Connect_Chain__c == 'Moevenpick Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Shangri-La Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'Starwood Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'The Ascott Group') || (acc.GTA_Connect_Chain__c == 'Wyndham Hotel Group')) && !(acc.GTA_Connect_Chain__c == null))
mTotalGTAconnectGlobal+= 1;
if(((acc.GTA_Connect_Chain__c == 'independent') && !((acc.DI_Master_Chain__c == 'ACCOR') || (acc.DI_Master_Chain__c == 'BW') || (acc.DI_Master_Chain__c == 'EC') || (acc.DI_Master_Chain__c == 'FAIRMONT') || (acc.DI_Master_Chain__c == 'HILTON') || (acc.DI_Master_Chain__c == 'HYATT') || (acc.DI_Master_Chain__c == 'IHG') || (acc.DI_Master_Chain__c == 'JUMEIRAH') || (acc.DI_Master_Chain__c == 'KI') || (acc.DI_Master_Chain__c == 'MC') || (acc.DI_Master_Chain__c == 'MK') || (acc.DI_Master_Chain__c == 'MOHG') || (acc.DI_Master_Chain__c == 'SG') || (acc.DI_Master_Chain__c == 'WY'))))
mTotalGTAconnectIndependent +=1;
if(((acc.GTA_Connect_Chain__c == null) && !((acc.DI_Master_Chain__c == 'ACCOR') || (acc.DI_Master_Chain__c == 'BW') || (acc.DI_Master_Chain__c == 'EC') || (acc.DI_Master_Chain__c == 'FAIRMONT') || (acc.DI_Master_Chain__c == 'HILTON') || (acc.DI_Master_Chain__c == 'HYATT') || (acc.DI_Master_Chain__c == 'IHG') || (acc.DI_Master_Chain__c == 'JUMEIRAH') || (acc.DI_Master_Chain__c == 'KI') || (acc.DI_Master_Chain__c == 'MC') || (acc.DI_Master_Chain__c == 'MK') || (acc.DI_Master_Chain__c == 'MOHG') || (acc.DI_Master_Chain__c == 'SG') || (acc.DI_Master_Chain__c == 'WY'))))
mTotalUnCategorized +=1;
if(acc.ThresholdC__c=='Top Focus' && acc.ThresholdC__c!= null && acc.Grand_Total_RNs_2013__c != null)
GrandTotalRNs2013 = GrandTotalRNs2013 + acc.Grand_Total_RNs_2013__c;
}
accountToUpdate(accToUpdateList);
mCity.GTA_Hotels_2012__c = mtotalLiveAccount;
mCity.GTA_City_Centre_Penetration__c=mtotalCityCenterAccount;
mCity.Suburbs_Airport__c= mtotalAirportAccount;
mCity.GTA_POI_Hotels__c= mtotalPOIAccount;
mCity.GTA_Hotels_2012__c = mtotalLiveAccount;
mCity.GTA_5_Hotels__c= mtotalfivestarHotels;
mCity.GTA_4_Hotels__c= mtotalfourstarHotels;
mCity.GTA_3_Hotels__c = mtotalthreestarHotels;
mCity.GTA_2_or_less_Hotels__c=mtotalTwoStarorLess;
mCity.GTA_Global_Chain_Hotels__c=mTotalGTAconnectGlobal;
mCity.GTA_Regional_Chain_Hotels__c= mTotalGTAconnectRegional;
mCity.GTA_Independant__c = mTotalGTAconnectIndependent;
mCity.RN_Projection_2014_Top_Focus__c = GrandTotalRNs2013;
mCity.uncategorised_properties__c =mTotalUnCategorized ;
system.debug('The Total number of accounts for this Master City is '+ mtotalLiveAccount);
system.debug('The no hotels in CityCenter : ' + mtotalCityCenterAccount);
system.debug('The no hotels in Airport : ' + mtotalAirportAccount);
system.debug('The no of hotels in POI is : ' + mtotalPOIAccount);
system.debug('The Total number of accounts for this Master City is '+ mtotalLiveAccount);
system.debug('The no hotels in CityCenter : ' + mtotalCityCenterAccount);
system.debug('The no hotels in Airport : ' + mtotalAirportAccount);
system.debug('The no of hotels in POI is : ' + mtotalPOIAccount);
system.debug('The no of 3 star hotel here is : ' + mtotalthreestarHotels);
system.debug('The no of 4 star hotel here is : ' + mtotalfourstarHotels );
system.debug('The no of 5 star hotel here is : ' + mtotalfivestarHotels );
system.debug('The no of 2 star and less hotel is : ' + mtotalTwoStarorLess);
system.debug('The no of GTAconnectGlobal hotel is : ' + mTotalGTAconnectGlobal);
system.debug('The no of GTAconnectRegional hotel is : ' + mTotalGTAconnectRegional);
system.debug('The no of GTAconnectIndependent hotel is : ' + mTotalGTAconnectIndependent);
system.debug('The no hotels uncategorized : ' + mCity.uncategorised_properties__c);
return mCity;
}
private void accountToUpdate(List<Account> account){
Database.update(account);
}
}
-
- Team Works
- January 20, 2014
- Like
- 1
- Continue reading or reply
How can i invoke apex code from a button?
How can i invoke apex code from a button, where using the apex i should be able to aggregate the fields from the child records.?
Please suggest
Thanks!
-
- Team Works
- January 06, 2014
- Like
- 0
- Continue reading or reply
Maintaining records yearwise
I have a requirement where the records that were created for my City Strategy Object in 2013 should remain as it is and in Year 2014 those records should be recreated with the new values for 2014. Same should be done for year 2015.Eg revenue generated field and oher similar data for London city in 2013 should remain as it is and we will now create new reocrds for 2014 and maintain the aggregate of revenue generated for 2014 and then for 2015.
What should be the best way to do this? I am thinking of creating a Parent object 'Year' to this City Strategy Object using lookup Rel and populate the year field in old records with 2013 and then new records will be associated to Year 2015. But also business wants to display the field as eg Revenue generated for 2013=xxx and revenue generated for 2014 is yyy..for the London record.Similarly for other cities.
Heartly Thanks in advance for your help..
-
- Team Works
- January 06, 2014
- Like
- 0
- Continue reading or reply
Any improvements/suggestions for this trigger?
New coder in Apex here
Just need suggestions from the experienced people out there if my trigger is efficient and scalable? Many Thanks for you help in advance. Also if someone can suggest how to proceed for a test class for this trigger..i apppreciate your help
// This trigger counts all of the calls made for a particular record type and Event Type in Event //Displays the count on Account Pagetrigger Activity_Count on Event (after insert, after update, after delete) { Set<Id> eventIds = new Set<Id>(); Set<Id> accIds = new Set<Id>(); Map<Id,Account> accMap = new Map<Id,Account>(); List<Account> updateList = new List<Account>(); String accPrefix = Account.sObjectType.getDescribe().getKeyPrefix(); system.debug(accPrefix); for (Event e : Trigger.isDelete ? Trigger.old : Trigger.new) { eventIds.add(e.Id); String str = e.whatId; if(str != null && str.startsWith(accPrefix)) // Task belongs to Account accIds.add(e.whatId); } integer countercalls = 0; integer countermeetings = 0; //system.debug('This is the list of the account Ids selected related to Task ----'+accIds); if(accIds.size() > 0) { for(Account acc : [SELECT Id, Annual_Actuals_Calls__c,Annual_Actuals_Meetings__c FROM Account WHERE Id in :accIds]){ for(Event evt :[SELECT Id, RecordTypeId,Type FROM Event where WhatId = :acc.Id]){ If(evt.RecordTypeId == '01220000000YZcPAAW' && evt.Type == 'Sales Call') countercalls +=1; If(evt.RecordTypeId == '01220000000YZcPAAW' && (evt.Type == 'Sales Visit' || evt.Type == 'New Client Visit')) countermeetings +=1; } acc.Annual_Actuals_Calls__c = countercalls; acc.Annual_Actuals_Meetings__c = countermeetings; updateList.add(acc); } } if(updateList.size() > 0) { //system.debug('The list to be updated contains these accounts :-----'+updateList); upsert updateList; } }
-
- Team Works
- January 02, 2014
- Like
- 0
- Continue reading or reply
Is this trigger efficient ?
Help for a new salesforce enthusiastic..Cance of improving this trigger for bulk loads? How can i use try catch?
Many Thanks!!
trigger updateGTAHotelCount on Account (after delete, after insert, after update) {
//The Triger will update the GTA Hotels Statistics for this year in Strategy Master City for the Accounts with Property Status = LIVE and RecordType= Property.
//The Account Object has lookup to City__c and city__c has a lookup to Pseudo_city__c object.
//This trigger will aggregate the total number of Accounts for a Master City, total number of Five star Account etc
public Set<id> cityIds = new Set<id>();
public Set<Id> mCityIds = new Set<Id>();
public Map<Id, Pseudo_City__c> MCitiesToUpdate = new Map<Id, Pseudo_City__c>();
public Map<Id,City__c> citiesToUpdate = new Map<Id,City__c>();
//Create a set of city Ids for the Accounts and Map of Cities to update
List<Pseudo_city__c> updateMasterCity = new List<Pseudo_city__c>();
if(trigger.isInsert || Trigger.isUpdate){
for(Account item : Trigger.new){
if (Item.recordTypeId=='012200000004rPU' && Item.Property_Status__c=='LIVE' )
cityIds.add(item.city_new__c);
}
system.debug('The list of cities for insert/Update-- ' + cityIds);
}
if(Trigger.isDelete){
for(Account item : Trigger.old){
if (Item.recordTypeId=='012200000004rPU' && Item.Property_Status__c=='LIVE' )
cityIds.add(item.city_new__c);
}
system.debug('The list of cities Delete -- ' + cityIds);
}
for(City__c Tempcity : [Select Master_City_Cluster__c from city__c where ID IN :cityIds ]){
mcityIds.add(Tempcity.Master_City_Cluster__c );
}
system.debug('The Master cities to be updated ' + mCityIds );
for(Pseudo_city__c mcity :[Select Id,GTA_3_Hotels__c,GTA_4_Hotels__c,GTA_5_Hotels__c,GTA_2_or_less_Hotels__c,GTA_Hotels_2012__c from Pseudo_City__c where Id in :mcityIds]){
MCitiesToUpdate.put(mcity.Id, mcity);
}
system.debug('The master City Details '+ MCitiesToUpdate );
for(City__c city :[Select Id, Name,Master_City_Cluster__c,City_Location__c,(Select Id,Name,Property_Status__c,Location__c,recordTypeId,Star_Rating__c,GTA_Connect_Chain__c,DI_Master_Chain__c,ThresholdC__c,Grand_Total_RNs_2013__c from city__c.Accounts1__r) FROM city__c where Master_City_Cluster__c IN :mcityIds]){
If(city.Master_City_Cluster__c != null )
citiesToUpdate.put(city.Id,city);
}
system.debug('The cities to be updated ' + citiesToUpdate);
//Loop through every mastercity, then cities for each master cities and then accounts for each city and count them total and then based on matching criteria
for(Pseudo_city__c MCToUpdate :MCitiesToUpdate.values()){
//Initialize the variable to 0
integer mtotalLiveAccount = 0;
integer mtotalfivestarHotels=0;
integer mtotalfourstarHotels =0;
integer mtotalthreestarHotels =0;
integer mTotalGTAconnectRegional = 0;
integer mTotalGTAconnectGlobal = 0;
integer mTotalGTAconnectIndependent = 0;
integer mtotalCityCenterAccount = 0;
integer mtotalAirportAccount=0;
integer mtotalRegionAccount =0;
integer mtotalPOIAccount=0;
integer mtotalTwoStarorLess=0;
double GrandTotalRNs2013=0;
//looping thru the Master cities
for(city__c citi : citiesToUpdate.values()){
//looping through the cities in this Master city
if(citi.City_Location__c == 'City Center' && citi.City_Location__c != null ) {
for(Account acc : citi.Accounts1__r){
If(acc.Property_Status__c=='LIVE' && acc.recordTypeId=='012200000004rPU')
mtotalCityCenterAccount+= 1;
}
system.debug('In city loop City Center Hotels : ' + mtotalCityCenterAccount);
}
if(citi.City_Location__c == 'Suburb & Airport' && citi.City_Location__c != null) {
for(Account acc : citi.Accounts1__r){
If(acc.Property_Status__c=='LIVE' && acc.recordTypeId=='012200000004rPU')
mtotalAirportAccount+= 1;
}
system.debug('In city loop Airport Hotels : ' + mtotalAirportAccount);
}
if(citi.City_Location__c == 'Point of interest' && citi.City_Location__c != null) {
for(Account acc : citi.Accounts1__r){
If(acc.Property_Status__c=='LIVE' && acc.recordTypeId=='012200000004rPU')
mtotalPOIAccount+= 1;
}
system.debug('In city loop POI Hotels : ' + mtotalPOIAccount);
}
for(Account acc : citi.Accounts1__r){
If(acc.Property_Status__c=='LIVE' && acc.recordTypeId=='012200000004rPU')
mtotalLiveAccount+= 1;
if (acc.Star_Rating__c=='5 Star' && acc.Star_Rating__c != null)
If(acc.Property_Status__c=='LIVE' && acc.recordTypeId=='012200000004rPU')
mtotalfivestarHotels += 1;
if (acc.Star_Rating__c=='4 Star' && acc.Star_Rating__c != null)
If(acc.Property_Status__c=='LIVE' && acc.recordTypeId=='012200000004rPU')
mtotalfourstarHotels += 1;
if (acc.Star_Rating__c=='3 Star' && acc.Star_Rating__c != null )
If(acc.Property_Status__c=='LIVE' && acc.recordTypeId=='012200000004rPU')
mtotalthreestarHotels += 1;
if(acc.Star_Rating__c =='1 Star' || acc.Star_Rating__c=='2 Star' || acc.Star_Rating__c== 'NA')
If(acc.Property_Status__c=='LIVE' && acc.recordTypeId=='012200000004rPU')
mtotalTwoStarorLess+=1;
// if (((acc.DI_Master_Chain__c != 'ACCOR') || (acc.DI_Master_Chain__c != 'BW') || (acc.DI_Master_Chain__c != 'DESIGN') || (acc.DI_Master_Chain__c != 'EC') || (acc.DI_Master_Chain__c != 'FAIRMONT') || (acc.DI_Master_Chain__c != 'HILTON') || (acc.DI_Master_Chain__c != 'HYATT') || (acc.DI_Master_Chain__c != 'IHG') || (acc.DI_Master_Chain__c != 'JUMEIRAH') || (acc.DI_Master_Chain__c != 'KI') || (acc.DI_Master_Chain__c != 'LUXE') || (acc.DI_Master_Chain__c != 'MC') || (acc.DI_Master_Chain__c != 'MK') || (acc.DI_Master_Chain__c != 'MOHG') || (acc.DI_Master_Chain__c != 'SG') || (acc.DI_Master_Chain__c != 'WY') ) && (acc.GTA_Connect_Chain__c != null) && ((acc.GTA_Connect_Chain__c != 'Intercontinental Hotels Group') || (acc.GTA_Connect_Chain__c != 'Accor Hotels') || (acc.GTA_Connect_Chain__c != 'Best Western International') || (acc.GTA_Connect_Chain__c != 'Carlson Hospitality') || (acc.GTA_Connect_Chain__c != 'Choice Hotels International') || (acc.GTA_Connect_Chain__c != 'Design Hotels') || (acc.GTA_Connect_Chain__c != 'Fairmont Raffles Swissotel Hotels & Resorts') || (acc.GTA_Connect_Chain__c != 'Four Seasons Hotels & Resorts') || (acc.GTA_Connect_Chain__c != 'Hilton Worldwide') || (acc.GTA_Connect_Chain__c != 'Hyatt Hotels and Resorts') || (acc.GTA_Connect_Chain__c != 'Jumeirah International LLC') || (acc.GTA_Connect_Chain__c != 'Kempinski') || (acc.GTA_Connect_Chain__c != 'KEMPINSKI HOTELS & RESORTS') || (acc.GTA_Connect_Chain__c != 'Langham Hotels') || (acc.GTA_Connect_Chain__c != 'Luxe Worldwide Hotels') || (acc.GTA_Connect_Chain__c != 'Mandarin Oriental Hotel Group') || (acc.GTA_Connect_Chain__c != 'Marriott International Inc.') || (acc.GTA_Connect_Chain__c != 'Millennium & Copthorne Hotels plc') || (acc.GTA_Connect_Chain__c != 'Moevenpick Hotels & Resorts') || (acc.GTA_Connect_Chain__c != 'Shangri-La Hotels and Resorts') || (acc.GTA_Connect_Chain__c != 'Starwood Hotels and Resorts') || (acc.GTA_Connect_Chain__c != 'The Ascott Group') || (acc.GTA_Connect_Chain__c != 'Wyndham Hotel Group' ) || (acc.GTA_Connect_Chain__c != 'independent' )))
// If(acc.Property_Status__c=='LIVE' && acc.recordTypeId=='012200000004rPU')
// mTotalGTAconnectRegional+= 1;
if (!((acc.DI_Master_Chain__c == 'ACCOR') || (acc.DI_Master_Chain__c == 'BW') || (acc.DI_Master_Chain__c == 'DESIGN') || (acc.DI_Master_Chain__c == 'EC') || (acc.DI_Master_Chain__c == 'FAIRMONT') || (acc.DI_Master_Chain__c == 'HILTON') || (acc.DI_Master_Chain__c == 'HYATT') || (acc.DI_Master_Chain__c == 'IHG') || (acc.DI_Master_Chain__c == 'JUMEIRAH') || (acc.DI_Master_Chain__c == 'KI') || (acc.DI_Master_Chain__c == 'LUXE') || (acc.DI_Master_Chain__c == 'MC') || (acc.DI_Master_Chain__c == 'MK') || (acc.DI_Master_Chain__c == 'MOHG') || (acc.DI_Master_Chain__c == 'SG') || (acc.DI_Master_Chain__c == 'WY') ) && (acc.GTA_Connect_Chain__c != null) && !((acc.GTA_Connect_Chain__c == 'Intercontinental Hotels Group') || (acc.GTA_Connect_Chain__c == 'Accor Hotels') || (acc.GTA_Connect_Chain__c == 'Best Western International') || (acc.GTA_Connect_Chain__c == 'Carlson Hospitality') || (acc.GTA_Connect_Chain__c == 'Choice Hotels International') || (acc.GTA_Connect_Chain__c == 'Design Hotels') || (acc.GTA_Connect_Chain__c == 'Fairmont Raffles Swissotel Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Four Seasons Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Hilton Worldwide') || (acc.GTA_Connect_Chain__c == 'Hyatt Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'Jumeirah International LLC') || (acc.GTA_Connect_Chain__c == 'Kempinski') || (acc.GTA_Connect_Chain__c == 'KEMPINSKI HOTELS & RESORTS') || (acc.GTA_Connect_Chain__c == 'Langham Hotels') || (acc.GTA_Connect_Chain__c == 'Luxe Worldwide Hotels') || (acc.GTA_Connect_Chain__c == 'Mandarin Oriental Hotel Group') || (acc.GTA_Connect_Chain__c == 'Marriott International Inc.') || (acc.GTA_Connect_Chain__c == 'Millennium & Copthorne Hotels plc') || (acc.GTA_Connect_Chain__c == 'Moevenpick Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Shangri-La Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'Starwood Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'The Ascott Group') || (acc.GTA_Connect_Chain__c == 'Wyndham Hotel Group' ) || (acc.GTA_Connect_Chain__c == 'independent' )))
If(acc.Property_Status__c=='LIVE' && acc.recordTypeId=='012200000004rPU')
mTotalGTAconnectRegional+= 1;
if (((acc.GTA_Connect_Chain__c == 'Intercontinental Hotels Group') || (acc.GTA_Connect_Chain__c == 'Accor Hotels') || (acc.GTA_Connect_Chain__c == 'Best Western International') || (acc.GTA_Connect_Chain__c == 'Carlson Hospitality') || (acc.GTA_Connect_Chain__c == 'Choice Hotels International') || (acc.GTA_Connect_Chain__c == 'Fairmont Raffles Swissotel Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Four Seasons Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Hilton Worldwide') || (acc.GTA_Connect_Chain__c == 'Hyatt Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'Jumeirah International LLC') || (acc.GTA_Connect_Chain__c == 'Kempinski') || (acc.GTA_Connect_Chain__c == 'KEMPINSKI HOTELS & RESORTS') || (acc.GTA_Connect_Chain__c == 'Langham Hotels') || (acc.GTA_Connect_Chain__c == 'Luxe Worldwide Hotels') || (acc.GTA_Connect_Chain__c == 'Mandarin Oriental Hotel Group') || (acc.GTA_Connect_Chain__c == 'Marriott International Inc.') || (acc.GTA_Connect_Chain__c == 'Millennium & Copthorne Hotels plc') || (acc.GTA_Connect_Chain__c == 'Moevenpick Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Shangri-La Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'Starwood Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'The Ascott Group') || (acc.GTA_Connect_Chain__c == 'Wyndham Hotel Group')) && !(acc.GTA_Connect_Chain__c == null))
If(acc.Property_Status__c=='LIVE' && acc.recordTypeId=='012200000004rPU')
mTotalGTAconnectGlobal+= 1;
if(((acc.GTA_Connect_Chain__c == 'independent') && !((acc.DI_Master_Chain__c == 'ACCOR') || (acc.DI_Master_Chain__c == 'BW') || (acc.DI_Master_Chain__c == 'EC') || (acc.DI_Master_Chain__c == 'FAIRMONT') || (acc.DI_Master_Chain__c == 'HILTON') || (acc.DI_Master_Chain__c == 'HYATT') || (acc.DI_Master_Chain__c == 'IHG') || (acc.DI_Master_Chain__c == 'JUMEIRAH') || (acc.DI_Master_Chain__c == 'KI') || (acc.DI_Master_Chain__c == 'MC') || (acc.DI_Master_Chain__c == 'MK') || (acc.DI_Master_Chain__c == 'MOHG') || (acc.DI_Master_Chain__c == 'SG') || (acc.DI_Master_Chain__c == 'WY'))))
If(acc.Property_Status__c=='LIVE' && acc.recordTypeId=='012200000004rPU')
mTotalGTAconnectIndependent +=1;
if(acc.ThresholdC__c=='Top Focus' && acc.ThresholdC__c!= null && acc.Grand_Total_RNs_2013__c != null){
GrandTotalRNs2013 = GrandTotalRNs2013 + acc.Grand_Total_RNs_2013__c;
}
}
}
system.debug('The Total number of accounts for this Master City is '+ mtotalLiveAccount);
system.debug('The no hotels in CityCenter : ' + mtotalCityCenterAccount);
system.debug('The no hotels in Airport : ' + mtotalAirportAccount);
system.debug('The no of hotels in POI is : ' + mtotalPOIAccount);
system.debug('The no of 3 star hotel here is : ' + mtotalthreestarHotels);
system.debug('The no of 4 star hotel here is : ' + mtotalfourstarHotels );
system.debug('The no of 5 star hotel here is : ' + mtotalfivestarHotels );
system.debug('The no of 2 star and less hotel is : ' + mtotalTwoStarorLess);
system.debug('The no of GTAconnectGlobal hotel is : ' + mTotalGTAconnectGlobal);
system.debug('The no of GTAconnectRegional hotel is : ' + mTotalGTAconnectRegional);
system.debug('The no of GTAconnectIndependent hotel is : ' + mTotalGTAconnectIndependent);
MCToUpdate.GTA_Hotels_2012__c = mtotalLiveAccount;
MCToUpdate.GTA_5_Hotels__c= mtotalfivestarHotels;
MCToUpdate.GTA_4_Hotels__c= mtotalfourstarHotels;
MCToUpdate.GTA_3_Hotels__c = mtotalthreestarHotels;
MCToUpdate.GTA_2_or_less_Hotels__c=mtotalTwoStarorLess;
MCToUpdate.GTA_City_Centre_Penetration__c=mtotalCityCenterAccount;
MCToUpdate.Suburbs_Airport__c= mtotalAirportAccount;
MCToUpdate.GTA_POI_Hotels__c= mtotalPOIAccount;
MCToUpdate.GTA_Global_Chain_Hotels__c=mTotalGTAconnectGlobal;
MCToUpdate.GTA_Regional_Chain_Hotels__c= mTotalGTAconnectRegional;
MCToUpdate.GTA_Independant__c = mTotalGTAconnectIndependent;
MCToUpdate.RN_Projection_2014_Top_Focus__c = GrandTotalRNs2013;
updateMasterCity.add(MCToUpdate);
}
//Finally update all affected cities:
update updateMasterCity;
}
-
- Team Works
- December 29, 2014
- Like
- 0
- Continue reading or reply
Customization done in last three months
Merry Xmas to all.
My doubt is --Is there a way i can find out what are the customizations/changes done in the Org in last three months so that easy for my to prepare my change sets.
Many Thanks
-
- Team Works
- December 25, 2013
- Like
- 0
- Continue reading or reply
Schema Validation by you experts for my small project
I am building a small project for maintaining customers for my restaurant and provide online Table Bookings.
I will use Person Account/Accounts to manage the cusomers. In the websitye when a customer wants to Book a table he will enter his Name, email, mobile to book a table, I want to use web to lead to create a Lead which shoul(HOW) will auto create an account and opportunity. I then call customer and add the line item(Menu Items) to the opportunity which will hold a Table No field from the Table Object. Table object has a lookup to ropportunity.
In the lookup it will display only the unbooked tables for the day.
Any addition of line items can be made when customer is dining. Once the bill is paid we close the opportunity , the ammount the table No is now free to be booked.
Is this feasible design?
Many Thanks for advice..
-
- Team Works
- December 25, 2013
- Like
- 0
- Continue reading or reply
Auto Opportunity on Web to Lead
Anyone has ideas around how can i create an opportunity automatically on web to Lead OR can i use Lead as an Opportunity to attach Line Items and price list...I basically want users to book a table in Restaurant from website form page and on submit an opportunity will be created and a table No field from the Table object will be auto populated in the opportunity..I can then add the menu selection to the Opportunity.
Many Thanks in advance
-
- Team Works
- December 25, 2013
- Like
- 0
- Continue reading or reply
Bulkified Trigger to on child object to check the values and then update
I have to wite a Trigger on a Object Override which has a lookup to Contract Object. When a new override is created it should check all the override already existing on the contract and make them inactive. The one which is created latest should be active...
Any help is appreciated.
Many Thanks!
-
- Team Works
- December 24, 2013
- Like
- 0
- Continue reading or reply
Tab Panel in a visualforce page
I have got 3 tabs on my visualforce page. In each tabs i have got a search feature. Afer i search for a record in one tab the list list is displayed for Accounts. Then i go to another tab. Once i come back yto the first tab, it does'nt refresh the list but still displays the previous search results. I tries with SwitchType Client, Ajax and server but no gain.
Any ideas welcome and thanks in advance
-
- Team Works
- June 19, 2014
- Like
- 1
- Continue reading or reply
Apex Batch Job for looping thru the 3 lookup relationship
Many Thanks in advance ...
global class MasterCity_BatchJob implements Database.Batchable<SObject>{
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator([Select Id from Pseudo_City__c where RecordTypeId='012m00000004HZLAA2']);
// where Id='a0Cm000000060Ai'
}
global void execute(Database.BatchableContext BC, List<SObject> mcityscope){
List<Pseudo_City__c> scope = (List<Pseudo_City__c>)mcityscope;//Casting sObject to Master City List
system.debug('The Scope created in Execute method is >>>>>'+scope );
MasterCityBatchJobHelper MChelper = new MasterCityBatchJobHelper();
MChelper.citiesInMasterCity(scope);
}
global void finish(Database.BatchableContext BC){}
}
-----------------------------------------------------------------------------------------
//Initialize the variables which will store summaries to 0
integer mtotalLiveAccount=0;
integer mtotalfivestarHotels=0;
integer mtotalfourstarHotels =0;
integer mtotalthreestarHotels =0;
integer mTotalGTAconnectRegional = 0;
integer mTotalGTAconnectGlobal = 0;
integer mTotalGTAconnectIndependent = 0;
integer mtotalCityCenterAccount = 0;
integer mtotalAirportAccount=0;
integer mtotalRegionAccount =0;
integer mtotalPOIAccount=0;
integer mtotalTwoStarorLess=0;
double GrandTotalRNs2013=0;
integer mTotalUnCategorized =0;
public Map<Id,City__c> mcitiesToUpdate = new Map<Id,City__c>();//Map to hold the cities
List<Pseudo_City__c> masterCitiesToUpdate = new List<Pseudo_City__c>();//List of Master Cities to be updated
List<Account> accToUpdateList = new List<Account>();
//constructor
public MasterCityBatchJobHelper(){}
public PageReference analyzeAccountFromPage() {
List<Pseudo_City__c> mcities = [select id from Pseudo_City__c where id = :ApexPages.currentPage().getParameters().get('id')];
system.debug('The mCities in ANalyse Accounts from PageReference is >>>>>'+ mcities );
citiesInMasterCity(mcities);
return new Pagereference('/'+ApexPages.currentPage().getParameters().get('id'));
}
//Methods
public void citiesInMasterCity(List<Pseudo_City__c> scope) {
scope = [Select Id,City_Categorisation__c,Name,GTA_3_Hotels__c,GTA_4_Hotels__c,GTA_5_Hotels__c,GTA_2_or_less_Hotels__c,GTA_Hotels_2012__c,RN_Projection_2014_Top_Focus__c,GTA_Independant__c,GTA_Global_Chain_Hotels__c,GTA_Regional_Chain_Hotels__c,Suburbs_Airport__c,GTA_POI_Hotels__c,uncategorised_properties__c,GTA_City_Centre_Penetration__c from Pseudo_City__c where Id IN: scope];
system.debug('The SCOPE in citiesInMasterCity is >>>>> '+ scope );
for(Pseudo_city__c mcity : scope){
system.debug('The value in the mastercitiestoUpdate before update>>>>>>>>>>>> ' + mcity.id );
masterCitiesToUpdate.add(analyzeMastercity(mCity));//Loads the list with Mastercities to be updated to List
}
Database.update(masterCitiesToUpdate);//Updates and commits the calculations in the List to the Database
}
private Pseudo_city__c analyzeMasterCity(Pseudo_city__c mCity) {
for(City__c city :[Select Id, Name,Master_City_Cluster_This_Year__c,City_Location__c FROM City__c where Master_City_Cluster_This_Year__c =:mCity.Id]){
If(city.Master_City_Cluster_This_Year__c != null )
mcitiesToUpdate.put(city.id,city);
}
system.debug('The cities within the Master cities are ::>>>> '+ mcitiesToUpdate );
return summarizeAccounts(mcitiesToUpdate, mCity);
}
private Pseudo_city__c summarizeAccounts(Map<Id,City__c> mcitiesToUpdate,Pseudo_City__c mCity){
for(Account acc : [Select Id,Name,Property_Status__c,Master_City_Cluster_Tier_This_Year__c,Master_City_Name_This_Year__c,Location__c,recordTypeId,Star_Rating__c,GTA_Connect_Chain__c,DI_Master_Chain__c,ThresholdC__c,Grand_Total_RNs_2013__c,City_New__c from Account where (RecordType.developerName='Property' AND Property_Status__c='LIVE' AND City_New__c IN :mcitiesToUpdate.keySet())]){
mtotalLiveAccount += 1;
if (acc.City_new__c != null){
acc.Master_City_Name_This_Year__c = mCity.Name;
acc.Master_City_Cluster_Tier_This_Year__c = mCity.City_Categorisation__c;
accToUpdateList.add(acc);
system.debug('The Account to be updated>>>>>>> ' +accToUpdateList);
}
if(mcitiesToUpdate.get(acc.City_New__c).City_Location__c != null){
if(mcitiesToUpdate.get(acc.City_New__c).City_Location__c == 'City Center')
mtotalCityCenterAccount+= 1;
if(mcitiesToUpdate.get(acc.City_New__c).City_Location__c == 'Suburb & Airport')
mtotalAirportAccount+= 1;
if(mcitiesToUpdate.get(acc.City_New__c).City_Location__c == 'Point of interest')
mtotalPOIAccount+= 1;
}
if ((acc.Star_Rating__c=='5 Star' || acc.Star_Rating__c=='5.5 Star') && acc.Star_Rating__c != null)
mtotalfivestarHotels += 1;
if ((acc.Star_Rating__c=='4 Star' || acc.Star_Rating__c=='4.5 Star' ) && acc.Star_Rating__c != null)
mtotalfourstarHotels += 1;
if ((acc.Star_Rating__c=='3 Star' || acc.Star_Rating__c=='3 Star' ) && acc.Star_Rating__c != null )
mtotalthreestarHotels += 1;
if(acc.Star_Rating__c =='1 Star' || acc.Star_Rating__c=='2 Star' || acc.Star_Rating__c== 'NA' )
mtotalTwoStarorLess+=1;
if (!((acc.DI_Master_Chain__c == 'ACCOR') || (acc.DI_Master_Chain__c == 'BW') || (acc.DI_Master_Chain__c == 'DESIGN') || (acc.DI_Master_Chain__c == 'EC') || (acc.DI_Master_Chain__c == 'FAIRMONT') || (acc.DI_Master_Chain__c == 'HILTON') || (acc.DI_Master_Chain__c == 'HYATT') || (acc.DI_Master_Chain__c == 'IHG') || (acc.DI_Master_Chain__c == 'JUMEIRAH') || (acc.DI_Master_Chain__c == 'KI') || (acc.DI_Master_Chain__c == 'LUXE') || (acc.DI_Master_Chain__c == 'MC') || (acc.DI_Master_Chain__c == 'MK') || (acc.DI_Master_Chain__c == 'MOHG') || (acc.DI_Master_Chain__c == 'SG') || (acc.DI_Master_Chain__c == 'WY') ) && (acc.GTA_Connect_Chain__c != null) && !((acc.GTA_Connect_Chain__c == 'Intercontinental Hotels Group') || (acc.GTA_Connect_Chain__c == 'Accor Hotels') || (acc.GTA_Connect_Chain__c == 'Best Western International') || (acc.GTA_Connect_Chain__c == 'Carlson Hospitality') || (acc.GTA_Connect_Chain__c == 'Choice Hotels International') || (acc.GTA_Connect_Chain__c == 'Design Hotels') || (acc.GTA_Connect_Chain__c == 'Fairmont Raffles Swissotel Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Four Seasons Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Hilton Worldwide') || (acc.GTA_Connect_Chain__c == 'Hyatt Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'Jumeirah International LLC') || (acc.GTA_Connect_Chain__c == 'Kempinski') || (acc.GTA_Connect_Chain__c == 'KEMPINSKI HOTELS & RESORTS') || (acc.GTA_Connect_Chain__c == 'Langham Hotels') || (acc.GTA_Connect_Chain__c == 'Luxe Worldwide Hotels') || (acc.GTA_Connect_Chain__c == 'Mandarin Oriental Hotel Group') || (acc.GTA_Connect_Chain__c == 'Marriott International Inc.') || (acc.GTA_Connect_Chain__c == 'Millennium & Copthorne Hotels plc') || (acc.GTA_Connect_Chain__c == 'Moevenpick Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Shangri-La Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'Starwood Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'The Ascott Group') || (acc.GTA_Connect_Chain__c == 'Wyndham Hotel Group' ) || (acc.GTA_Connect_Chain__c == 'independent' )))
mTotalGTAconnectRegional+= 1;
if (((acc.GTA_Connect_Chain__c == 'Intercontinental Hotels Group') || (acc.GTA_Connect_Chain__c == 'Accor Hotels') || (acc.GTA_Connect_Chain__c == 'Best Western International') || (acc.GTA_Connect_Chain__c == 'Carlson Hospitality') || (acc.GTA_Connect_Chain__c == 'Choice Hotels International') || (acc.GTA_Connect_Chain__c == 'Fairmont Raffles Swissotel Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Four Seasons Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Hilton Worldwide') || (acc.GTA_Connect_Chain__c == 'Hyatt Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'Jumeirah International LLC') || (acc.GTA_Connect_Chain__c == 'Kempinski') || (acc.GTA_Connect_Chain__c == 'KEMPINSKI HOTELS & RESORTS') || (acc.GTA_Connect_Chain__c == 'Langham Hotels') || (acc.GTA_Connect_Chain__c == 'Luxe Worldwide Hotels') || (acc.GTA_Connect_Chain__c == 'Mandarin Oriental Hotel Group') || (acc.GTA_Connect_Chain__c == 'Marriott International Inc.') || (acc.GTA_Connect_Chain__c == 'Millennium & Copthorne Hotels plc') || (acc.GTA_Connect_Chain__c == 'Moevenpick Hotels & Resorts') || (acc.GTA_Connect_Chain__c == 'Shangri-La Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'Starwood Hotels and Resorts') || (acc.GTA_Connect_Chain__c == 'The Ascott Group') || (acc.GTA_Connect_Chain__c == 'Wyndham Hotel Group')) && !(acc.GTA_Connect_Chain__c == null))
mTotalGTAconnectGlobal+= 1;
if(((acc.GTA_Connect_Chain__c == 'independent') && !((acc.DI_Master_Chain__c == 'ACCOR') || (acc.DI_Master_Chain__c == 'BW') || (acc.DI_Master_Chain__c == 'EC') || (acc.DI_Master_Chain__c == 'FAIRMONT') || (acc.DI_Master_Chain__c == 'HILTON') || (acc.DI_Master_Chain__c == 'HYATT') || (acc.DI_Master_Chain__c == 'IHG') || (acc.DI_Master_Chain__c == 'JUMEIRAH') || (acc.DI_Master_Chain__c == 'KI') || (acc.DI_Master_Chain__c == 'MC') || (acc.DI_Master_Chain__c == 'MK') || (acc.DI_Master_Chain__c == 'MOHG') || (acc.DI_Master_Chain__c == 'SG') || (acc.DI_Master_Chain__c == 'WY'))))
mTotalGTAconnectIndependent +=1;
if(((acc.GTA_Connect_Chain__c == null) && !((acc.DI_Master_Chain__c == 'ACCOR') || (acc.DI_Master_Chain__c == 'BW') || (acc.DI_Master_Chain__c == 'EC') || (acc.DI_Master_Chain__c == 'FAIRMONT') || (acc.DI_Master_Chain__c == 'HILTON') || (acc.DI_Master_Chain__c == 'HYATT') || (acc.DI_Master_Chain__c == 'IHG') || (acc.DI_Master_Chain__c == 'JUMEIRAH') || (acc.DI_Master_Chain__c == 'KI') || (acc.DI_Master_Chain__c == 'MC') || (acc.DI_Master_Chain__c == 'MK') || (acc.DI_Master_Chain__c == 'MOHG') || (acc.DI_Master_Chain__c == 'SG') || (acc.DI_Master_Chain__c == 'WY'))))
mTotalUnCategorized +=1;
if(acc.ThresholdC__c=='Top Focus' && acc.ThresholdC__c!= null && acc.Grand_Total_RNs_2013__c != null)
GrandTotalRNs2013 = GrandTotalRNs2013 + acc.Grand_Total_RNs_2013__c;
}
accountToUpdate(accToUpdateList);
mCity.GTA_Hotels_2012__c = mtotalLiveAccount;
mCity.GTA_City_Centre_Penetration__c=mtotalCityCenterAccount;
mCity.Suburbs_Airport__c= mtotalAirportAccount;
mCity.GTA_POI_Hotels__c= mtotalPOIAccount;
mCity.GTA_Hotels_2012__c = mtotalLiveAccount;
mCity.GTA_5_Hotels__c= mtotalfivestarHotels;
mCity.GTA_4_Hotels__c= mtotalfourstarHotels;
mCity.GTA_3_Hotels__c = mtotalthreestarHotels;
mCity.GTA_2_or_less_Hotels__c=mtotalTwoStarorLess;
mCity.GTA_Global_Chain_Hotels__c=mTotalGTAconnectGlobal;
mCity.GTA_Regional_Chain_Hotels__c= mTotalGTAconnectRegional;
mCity.GTA_Independant__c = mTotalGTAconnectIndependent;
mCity.RN_Projection_2014_Top_Focus__c = GrandTotalRNs2013;
mCity.uncategorised_properties__c =mTotalUnCategorized ;
system.debug('The Total number of accounts for this Master City is '+ mtotalLiveAccount);
system.debug('The no hotels in CityCenter : ' + mtotalCityCenterAccount);
system.debug('The no hotels in Airport : ' + mtotalAirportAccount);
system.debug('The no of hotels in POI is : ' + mtotalPOIAccount);
system.debug('The Total number of accounts for this Master City is '+ mtotalLiveAccount);
system.debug('The no hotels in CityCenter : ' + mtotalCityCenterAccount);
system.debug('The no hotels in Airport : ' + mtotalAirportAccount);
system.debug('The no of hotels in POI is : ' + mtotalPOIAccount);
system.debug('The no of 3 star hotel here is : ' + mtotalthreestarHotels);
system.debug('The no of 4 star hotel here is : ' + mtotalfourstarHotels );
system.debug('The no of 5 star hotel here is : ' + mtotalfivestarHotels );
system.debug('The no of 2 star and less hotel is : ' + mtotalTwoStarorLess);
system.debug('The no of GTAconnectGlobal hotel is : ' + mTotalGTAconnectGlobal);
system.debug('The no of GTAconnectRegional hotel is : ' + mTotalGTAconnectRegional);
system.debug('The no of GTAconnectIndependent hotel is : ' + mTotalGTAconnectIndependent);
system.debug('The no hotels uncategorized : ' + mCity.uncategorised_properties__c);
return mCity;
}
private void accountToUpdate(List<Account> account){
Database.update(account);
}
}
-
- Team Works
- January 20, 2014
- Like
- 1
- Continue reading or reply
Prevent Duplicate Contact on an Account
Need to write a trigger such that if a Contact already exists ( based on email, phone or name) on the Parent Account or any of the Parents' Child accounts, then if a user tries to Create a Contact, an error should be thrown.
This trigger should be Account based and not Org.
Lets say a Contact is created on Account 'B'. Account 'A' is the parent for account B. and if i try to create same contact on Account 'C' ( another Child of Account 'A'), error should be thrown.
or also if the Contact exists on Parent and if we try to create a duplicate on any of its Child, even then an error should be thrown.
I had written a trigger but that worked only on a single account.
Thank You.
- Wik
- October 21, 2014
- Like
- 0
- Continue reading or reply
How to concatenate strings to form a Query
Again Stuck with the concatenation :
private final String SOQL_RECENT_REC = 'SELECT LastViewedDate,Type,UserRoleId FROM RecentlyViewed';
private final String CONDITION_USER_SORT = ' Order By LastViewedDate DESC LIMIT 20';
List<RecentlyViewed> recentViewed= new List<RecentlyViewed>();
recentViewed = Database.query(SOQL_RECENT_REC +' WHERE Type = \'Account \' ' + CONDITION_USER_SORT);
Should run a query like the following :
recentViewed = [SELECT LastViewedDate,Type,UserRoleId FROM RecentlyViewed Where Type='Account' Order By LastViewedDate DESC LIMIT 20];
Many Thanks !!
- Team Works
- June 12, 2014
- Like
- 0
- Continue reading or reply
Custom Visual Force Page
I hope you having a good day but i am kind of stuck.
I am currently displaying the User List in a custom VF Page. When i click the Name of the User it should take the user to a Custom Visualforce page where i will display the some user details, and list of his Activities, Accounts, Opportunities. Shall i use the standard User Controller and OR a custom controller. Please Guide me the steps.
Many Thanks
- Team Works
- June 11, 2014
- Like
- 0
- Continue reading or reply
Database.Query -- How to concaenate this SOQL as string
string sql1 = 'Select Custom_Name__c from Opportunity where AccountId IN';
string2 sql2= '(Select Id from Account where Europe__c =True)';
Opp=Database.query(sql1+sql2);
sysem.debug(Opp);
Doesn't work.Any Ideas?
- Team Works
- June 10, 2014
- Like
- 0
- Continue reading or reply
HomePage Component
I need to create a Home Page component with a Tab 'Interested In'. In this tab i need to display the Accounts i am following(irrespective of I own it or not.) I am the logged in User..
Please guide/suggest
Many Thanks
- Team Works
- June 08, 2014
- Like
- 0
- Continue reading or reply
Display the people who report to logged in user?
I need to create a visual force page where i need to display me and people who report to logged in User(me)....ofcourse based on the role hierarchy setup in my Org.
Kindly guide me to link explaining such an example or how can i approach this?
Many Thanks
- Team Works
- June 08, 2014
- Like
- 0
- Continue reading or reply
Help to Consume WADL file
Has anyone used the WADL file into salesforce. I have got WADL file from another Application Team. When i import this sfile into Salesforce it errors out.
Just looking for a way to consume WADL in salesforce if anyone can help?
- Team Works
- May 14, 2014
- Like
- 0
- Continue reading or reply
Custom settings
Just trying to Use Custom Setting in a Formula field. I have too many custom formula field on the account Object and hit the limit of max 15. Would like to know how can i use Heirarchical Custom setting in Cross Object Formuls..Many Thanks in advance
- Team Works
- January 21, 2014
- Like
- 0
- Continue reading or reply
How can i invoke apex code from a button?
How can i invoke apex code from a button, where using the apex i should be able to aggregate the fields from the child records.?
Please suggest
Thanks!
- Team Works
- January 06, 2014
- Like
- 0
- Continue reading or reply
- Reks
- December 10, 2013
- Like
- 0
- Continue reading or reply
Using Apex variables with LIKE in SOQL queries
I thought I'd share since figuring this out was kind of crappy. Since you can't (or I couldn't find how) concatenate a string in an SOQL query to combine wildcards like % and _ to make a query, you need to do so with the variable you want to pass in.
So if you want to do an SOQL query using LIKE, wild cards, and an Apex variable, this will work.
//create a string
String s = 'mystring';
//add wildcards around it to be more flexible in the search
s = '%' + s + '%';
//create an SOBject list with the results from our query
SObject[] obj = [select id from SObjectName where Name LIKE :s];
and this will return any row from the SObjectName where the "Name" field has "mystring" in it.
- paul-lmi
- May 14, 2009
- Like
- 2
- Continue reading or reply