private boolean m_isExecuting = True;
private integer BatchSize = 0;
public ContactTriggerHandler(boolean isExecuting, integer size)
{
m_isExecuting = isExecuting;
BatchSize = size;
}
/* public void onBeforeInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
}
public void OnBeforeUpdate(list<Contact> triggerNew, map<id,Contact> triggerNewMap, map<id,Contact> triggerOldMap)
{
}*/
public void OnAfterInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
updateNumberOfGenderContactsOnAccount(triggerNew, triggerNewMap);
// updateNumberOfContactsOnAccount(triggerNew, triggerNewMap);
}
public void OnBeforeDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
}
public void OnAfterDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
// system.debug('after delete class');
// updateNumberOfContactsOnAccount(triggerold, triggeroldMap);
}
/* private void updateNumberOfContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
setOfAccountIdFromContact.add(eachCon.AccountId);
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
list<Account> lstAccount = [select id, Name, Total_Contacts__c,
(select id from contacts)
from Account
where Id IN : setOfAccountIdFromContact];
if(lstAccount != null && lstAccount.size() > 0)
{
for(Account eachAccount : lstAccount)
{
eachAccount.Total_Contacts__c = eachAccount.contacts.size();
//eachAccount.Name += '_1';
}
update lstAccount;
}
}
}*/
private void updateNumberOfGenderContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
{setOfAccountIdFromContact.add(eachCon.AccountId); }
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
List<Account> lstAccount = [select id, Name, Total_Contacts__c,Total_Female_Contacts__c,Total_male_Contacts__c from Account
where Id IN : setOfAccountIdFromContact];
List<AggregateResult> lst=[SELECT Gender__c, COUNT(id) FROM Contact where accountid IN:setOfAccountIdFromContact GROUP BY Gender__c];
for(Account objAccount :lstAccount)
{
for(AggregateResult objAggregateResult :lst)
{
if(objAggregateResult.gender__c='male')
{objAccount.Total_Male_Contacts__c=objAggregateResult.COUNT(objAggregateResult.gender__c);}
if(objAggregateResult.gender__c='female')
{ objAccount.Total_Female_Contacts__c=objAggregateResult.total_contact;}
}
}
update lstAccount;
}
}
}public class ContactTriggerHandler{
private boolean m_isExecuting = True;
private integer BatchSize = 0;
public ContactTriggerHandler(boolean isExecuting, integer size)
{
m_isExecuting = isExecuting;
BatchSize = size;
}
/* public void onBeforeInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
}
public void OnBeforeUpdate(list<Contact> triggerNew, map<id,Contact> triggerNewMap, map<id,Contact> triggerOldMap)
{
}*/
public void OnAfterInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
updateNumberOfGenderContactsOnAccount(triggerNew, triggerNewMap);
// updateNumberOfContactsOnAccount(triggerNew, triggerNewMap);
}
public void OnBeforeDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
}
public void OnAfterDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
// system.debug('after delete class');
// updateNumberOfContactsOnAccount(triggerold, triggeroldMap);
}
/* private void updateNumberOfContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
setOfAccountIdFromContact.add(eachCon.AccountId);
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
list<Account> lstAccount = [select id, Name, Total_Contacts__c,
(select id from contacts)
from Account
where Id IN : setOfAccountIdFromContact];
if(lstAccount != null && lstAccount.size() > 0)
{
for(Account eachAccount : lstAccount)
{
eachAccount.Total_Contacts__c = eachAccount.contacts.size();
//eachAccount.Name += '_1';
}
update lstAccount;
}
}
}*/
private void updateNumberOfGenderContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
{setOfAccountIdFromContact.add(eachCon.AccountId); }
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
List<Account> lstAccount = [select id, Name, Total_Contacts__c,Total_Female_Contacts__c,Total_male_Contacts__c from Account
where Id IN : setOfAccountIdFromContact];
AggregateResult[] agrResult=[SELECT Gender__c, COUNT(id) total_contacts FROM Contact where accountid IN:setOfAccountIdFromContact GROUP BY Gender__c];
for(Account objAccount :lstAccount)
{
for(AggregateResult objAggregateResult :agrResult)
{
if(objAggregateResult.get('gender__c')='male')
{objAccount.Total_Male_Contacts__c=objAggregateResult.get('total_contacts');}
if(objAggregateResult.gender__c='female')
{ objAccount.Total_Female_Contacts__c=objAggregateResult.get('total_contact');}
}
}
update lstAccount;
}
}
}public class ContactTriggerHandler
{ private boolean m_isExecuting = True;
private integer BatchSize = 0;
public ContactTriggerHandler(boolean isExecuting, integer size)
{
m_isExecuting = isExecuting;
BatchSize = size;
}
/* public void onBeforeInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
}
public void OnBeforeUpdate(list<Contact> triggerNew, map<id,Contact> triggerNewMap, map<id,Contact> triggerOldMap)
{
}*/
public void OnAfterInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
updateNumberOfGenderContactsOnAccount(triggerNew, triggerNewMap);
// updateNumberOfContactsOnAccount(triggerNew, triggerNewMap);
}
public void OnBeforeDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
}
public void OnAfterDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
// system.debug('after delete class');
// updateNumberOfContactsOnAccount(triggerold, triggeroldMap);
}
/* private void updateNumberOfContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
setOfAccountIdFromContact.add(eachCon.AccountId);
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
list<Account> lstAccount = [select id, Name, Total_Contacts__c,
(select id from contacts)
from Account
where Id IN : setOfAccountIdFromContact];
if(lstAccount != null && lstAccount.size() > 0)
{
for(Account eachAccount : lstAccount)
{
eachAccount.Total_Contacts__c = eachAccount.contacts.size();
//eachAccount.Name += '_1';
}
update lstAccount;
}
}
}*/
private void updateNumberOfGenderContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
Set<String> setOfGenderFromContact=new Set<String>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
{
setOfAccountIdFromContact.add(eachCon.AccountId);
setOfgenderFromContact.add(eachCon.Gender__c);
}
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0 && setOfgenderFromContact='')
{
for(String objString :setOfgenderFromContact)
{
if(objString='male')
{
List<Account> lstAccount = [select id, Name, Total_Contacts__c,Total_male_Contacts__c,(select id from contacts where gender__c='male') from Account
where Id IN : setOfAccountIdFromContact];
for(Account objAccount :lstAccount)
{
objAccount.Total_Male_Contacts__c=objAccount.contacts.size();
}
}
if(objString='female')
{
List<Account> lstAccount2 = [select id, Name, Total_Contacts__c,Total_male_Contacts__c,(select id from contacts where gender__c='female') from Account
where Id IN : setOfAccountIdFromContact];
}
}
update lstAccount;
}
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
List<Account> lstAccount = [select id, Name, Total_Contacts__c,Total_male_Contacts__c,(select id from contacts where gender__c='male') from Account
where Id IN : setOfAccountIdFromContact];
List<Account> lstAccount2 = [select id, Name, Total_Contacts__c,Total_female_Contacts__c,(select id from contacts where gender__c='female') from Account
where Id IN : setOfAccountIdFromContact];
for(Account objAccount :lstAccount)
{
objAccount.Total_Male_Contacts__c=objAccount.contacts.size();
}
for(Account objAccount :lstAccount)
{
objAccount.Total_Female_Contacts__c=objAccount.contacts.size();
}
}
update lstAccount;
update lstAccount2;public class ContactTriggerHandler
{ private boolean m_isExecuting = True;
private integer BatchSize = 0;
public ContactTriggerHandler(boolean isExecuting, integer size)
{
m_isExecuting = isExecuting;
BatchSize = size;
}
/* public void onBeforeInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
}
public void OnBeforeUpdate(list<Contact> triggerNew, map<id,Contact> triggerNewMap, map<id,Contact> triggerOldMap)
{
}*/
public void OnAfterInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
updateNumberOfGenderContactsOnAccount(triggerNew, triggerNewMap);
updateNumberOfContactsOnAccount(triggerNew, triggerNewMap);
}
public void OnBeforeDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
}
public void OnAfterDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
// system.debug('after delete class');
updateNumberOfContactsOnAccount(triggerold, triggeroldMap);
updateNumberOfGenderContactsOnAccount(triggerOld, triggerOldMap);
}
private void updateNumberOfContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
setOfAccountIdFromContact.add(eachCon.AccountId);
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
list<Account> lstAccount = [select id, Name, Total_Contacts__c,
(select id from contacts)
from Account
where Id IN : setOfAccountIdFromContact];
if(lstAccount != null && lstAccount.size() > 0)
{
for(Account eachAccount : lstAccount)
{
eachAccount.Total_Contacts__c = eachAccount.contacts.size();
//eachAccount.Name += '_1';
}
update lstAccount;
}
}
}
private void updateNumberOfGenderContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
Set<String> setOfGenderFromContact=new Set<String>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
{
setOfAccountIdFromContact.add(eachCon.AccountId);
setOfgenderFromContact.add(eachCon.Gender__c);
}
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
List<Account> lstAccount = [select id, Name, Total_Contacts__c,Total_male_Contacts__c,(select id from contacts where gender__c='male') from Account
where Id IN : setOfAccountIdFromContact];
List<Account> lstAccount2 = [select id, Name, Total_Contacts__c,Total_female_Contacts__c,(select id from contacts where gender__c='female') from Account
where Id IN : setOfAccountIdFromContact];
for(Account objAccount :lstAccount)
{
objAccount.Total_Male_Contacts__c=objAccount.contacts.size();
}
for(Account objAccount :lstAccount)
{
objAccount.Total_Female_Contacts__c=objAccount.contacts.size();
}
update lstAccount;
update lstAccount2;
}
}
}public class ContactTriggerHandler
{ private boolean m_isExecuting = True;
private integer BatchSize = 0;
public ContactTriggerHandler(boolean isExecuting, integer size)
{
m_isExecuting = isExecuting;
BatchSize = size;
}
/* public void onBeforeInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
}
public void OnBeforeUpdate(list<Contact> triggerNew, map<id,Contact> triggerNewMap, map<id,Contact> triggerOldMap)
{
}*/
public void OnAfterInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
updateNumberOfGenderContactsOnAccount(triggerNew, triggerNewMap);
updateNumberOfContactsOnAccount(triggerNew, triggerNewMap);
}
public void OnBeforeDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
}
public void OnAfterDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
// system.debug('after delete class');
updateNumberOfContactsOnAccount(triggerold, triggeroldMap);
updateNumberOfGenderContactsOnAccount(triggerOld, triggerOldMap);
}
private void updateNumberOfContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
setOfAccountIdFromContact.add(eachCon.AccountId);
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
list<Account> lstAccount = [select id, Name, Total_Contacts__c,
(select id from contacts)
from Account
where Id IN : setOfAccountIdFromContact];
if(lstAccount != null && lstAccount.size() > 0)
{
for(Account eachAccount : lstAccount)
{
eachAccount.Total_Contacts__c = eachAccount.contacts.size();
//eachAccount.Name += '_1';
}
update lstAccount;
}
}
}
private void updateNumberOfGenderContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
{
setOfAccountIdFromContact.add(eachCon.AccountId);
}
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
List<Account> lstAccount = [select id, Name, Total_Contacts__c,Total_male_Contacts__c,(select id from contacts where gender__c='male') from Account
where Id IN : setOfAccountIdFromContact];
List<Account> lstAccount2 = [select id, Name, Total_Contacts__c,Total_female_Contacts__c,(select id from contacts where gender__c='female') from Account
where Id IN : setOfAccountIdFromContact];
for(Account objAccount :lstAccount)
{
objAccount.Total_Male_Contacts__c=objAccount.contacts.size();
}
for(Account objAccount :lstAccount2)
{
objAccount.Total_Female_Contacts__c=objAccount.contacts.size();
}
update lstAccount;
update lstAccount2;
}
}
}
private void updateNumberOfGenderContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
Set<String> setOfGenderFromContact=new Set<String>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
{
setOfAccountIdFromContact.add(eachCon.AccountId);
setOfgenderFromContact.add(eachCon.Gender__c);
}
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
for(String st:setOfgenderFromContact)
{
List<Account> lstAccount = [select id, Name, Total_Contacts__c,Total_male_Contacts__c,(select id from contacts where gender__c IN:setOfgenderFromContact) from Account
where Id IN : setOfAccountIdFromContact];
if(setOfgenderFromContact='male')
{
for(Account objAccount :lstAccount)
{
objAccount.Total_Male_Contacts__c=objAccount.contacts.size();
}
}
if(setOfgenderFromContact='female')
{
for(Account objAccount :lstAccount)
{
objAccount.Total_Female_Contacts__c=objAccount.contacts.size();
}
}
update lstAccount;
}
}
}
private void OppurtunityUpdate()
{
Set<ID> setOfAccountID=new Set<ID>();
if(trigger.new!=null)
{
for(Opportunity objOpportunity:trigger.New)
{
if(objOpportunity.AccountID!=null)
{
setOfAccountID.add(objOpportunity.AccountID);
}
}
}
if(setOfAccountId != null && setOfAccountId.size() > 0)
{
list<Account> lstAccount = [select id, Name, Total_Contacts__c,
(select id,name from contacts)
from Account where Id IN : setOfAccountId];
if(lstAccount != null && lstAccount.size() > 0)
{
for(Account eachAccount : lstAccount)
{
eachOpportunity.Total_Contacts__c = (Opportunity)(eachAccount.contacts.size());
}
)
update lstAccount;
}
private void updateNumberOfContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
setOfAccountIdFromContact.add(eachCon.AccountId);
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
list<Account> lstAccount = [select id, Name, Total_Contacts__c,
(select id from contacts)
from Account
where Id IN : setOfAccountIdFromContact];
if(lstAccount != null && lstAccount.size() > 0)
{
for(Account eachAccount : lstAccount)
{
eachAccount.Total_Contacts__c = eachAccount.contacts.size();
//eachAccount.Name += '_1';
}
update lstAccount;
}
}
}
public class ContactTriggerHandler
{ private boolean m_isExecuting = True;
private integer BatchSize = 0;
public ContactTriggerHandler(boolean isExecuting, integer size)
{
m_isExecuting = isExecuting;
BatchSize = size;
}
public void onBeforeInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
}
public void OnBeforeOpportunityUpdate(list<Opportunity> triggerOld, map<id,Opportunity> triggerOldMap)
{
onUpdateOfrOfOpportunity(triggerOld,triggerOldMap);
}
public void OnAfterInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
updateNumberOfGenderContactsOnAccount(triggerNew, triggerNewMap);
updateNumberOfContactsOnAccount(triggerNew, triggerNewMap);
}
public void OnBeforeDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
}
public void OnAfterDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
// system.debug('after delete class');
updateNumberOfContactsOnAccount(triggerold, triggeroldMap);
updateNumberOfGenderContactsOnAccount(triggerOld, triggerOldMap);
}
private void updateNumberOfContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
setOfAccountIdFromContact.add(eachCon.AccountId);
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
list<Account> lstAccount = [select id, Name, Total_Contacts__c,
(select id from contacts)
from Account
where Id IN : setOfAccountIdFromContact];
if(lstAccount != null && lstAccount.size() > 0)
{
for(Account eachAccount : lstAccount)
{
eachAccount.Total_Contacts__c = eachAccount.contacts.size();
//eachAccount.Name += '_1';
}
update lstAccount;
}
}
}
private void onUpdateOfrOfOpportunity(List<Opportunity> triggerOld,Map<id,Opportunity> triggerOldMap)
{
Set<ID> setOfAccountID=new Set<ID>();
if(triggerOld!=null)
{
for(Opportunity objOpportunity:triggerOld)
{
if(objOpportunity.AccountID!=null)
{
setOfAccountID.add(objOpportunity.AccountID);
}
}
}
if(setOfAccountId != null && setOfAccountId.size() > 0)
{
list<Account> lstAccount = [select id, Name, Total_Contacts__c,
(select id,name from contacts)
from Account where Id IN : setOfAccountId];
Opportunity eachOpportunity=new Opportunity();
if(lstAccount != null && lstAccount.size() > 0)
{
for(Account eachAccount : lstAccount)
{
eachOpportunity.Total_Contacts_Linked__c = (eachAccount.contacts.size());
}
}
update lstAccount;
}
}
private void updateNumberOfGenderContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
Set<String> setOfGenderFromContact=new Set<String>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
{
setOfAccountIdFromContact.add(eachCon.AccountId);
setOfgenderFromContact.add(eachCon.Gender__c);
}
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
for(String st:setOfgenderFromContact)
{
List<Account> lstAccount = [select id, Name, Total_Contacts__c,Total_male_Contacts__c,(select id from contacts where gender__c IN:setOfgenderFromContact) from Account
where Id IN : setOfAccountIdFromContact];
if(st=='male')
{
for(Account objAccount :lstAccount)
{
objAccount.Total_Male_Contacts__c=objAccount.contacts.size();
}
}
if(st=='female')
{
for(Account objAccount :lstAccount)
{
objAccount.Total_Female_Contacts__c=objAccount.contacts.size();
}
}
update lstAccount;
}
}
}
}/**
* An apex page controller that exposes the change password functionality
*/
public with sharing class ChangePasswordController {
public String oldPassword {get; set;}
public String newPassword {get; set;}
public String verifyNewPassword {get; set;}
public PageReference changePassword() {
return Site.changePassword(newPassword, verifyNewPassword, oldpassword);
}
public ChangePasswordController() {}
}/**
* An apex page controller that exposes the change password functionality
*/
@IsTest public with sharing class ChangePasswordControllerTest {
@IsTest(SeeAllData=true) public static void testChangePasswordController() {
// Instantiate a new controller with all parameters in the page
ChangePasswordController controller = new ChangePasswordController();
controller.oldPassword = '123456';
controller.newPassword = 'qwerty1';
controller.verifyNewPassword = 'qwerty1';
System.assertEquals(controller.changePassword(),null);
}
}/**
* An apex page controller that exposes the site forgot password functionality
*/
public with sharing class ForgotPasswordController {
public String username {get; set;}
public ForgotPasswordController() {}
public PageReference forgotPassword() {
boolean success = Site.forgotPassword(username);
PageReference pr = Page.ForgotPasswordConfirm;
pr.setRedirect(true);
if (success) {
return pr;
}
return null;
}
}/**
* An apex page controller that exposes the site forgot password functionality
*/
@IsTest public with sharing class ForgotPasswordControllerTest {
@IsTest(SeeAllData=true) public static void testForgotPasswordController() {
// Instantiate a new controller with all parameters in the page
ForgotPasswordController controller = new ForgotPasswordController();
controller.username = 'test@salesforce.com';
System.assertEquals(controller.forgotPassword(),null);
}
}/**
* An apex class that keeps updates of a portal user in sync with its corresponding contact.
Guest users are never able to access this page.
*/
@IsTest public with sharing class MyProfilePageControllerTest {
@IsTest(SeeAllData=true) static void testSetContactFields() {
User u = [select title, firstname, lastname, email, phone, mobilephone, fax, street, city, state, postalcode, country
FROM User WHERE id =: UserInfo.getUserId()];
Contact c = new Contact();
MyProfilePageController.setContactFields(c, u);
System.assertEquals(c.firstname, u.firstname, 'firstname should have been set as the firstname of the user for the contact');
System.assertEquals(c.lastname, u.lastname, 'lastname should have been set as the lastname of the user for the contact');
}
@IsTest(SeeAllData=true) static void testSave() {
// Modify the test to query for a portal user that exists in your org
List<User> existingPortalUsers = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess'];
if (existingPortalUsers.isEmpty()) {
User currentUser = [select id, title, firstname, lastname, email, phone, mobilephone, fax, street, city, state, postalcode, country
FROM User WHERE id =: UserInfo.getUserId()];
MyProfilePageController controller = new MyProfilePageController();
System.assertEquals(currentUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
System.assert(controller.getIsEdit() == false, 'isEdit should default to false');
controller.edit();
System.assert(controller.getIsEdit() == true);
controller.cancel();
System.assert(controller.getIsEdit() == false);
Contact c = new Contact();
c.LastName = 'TestContact';
insert c;
c.title = currentUser.title;
c.firstname = currentUser.firstname;
c.lastname = currentUser.lastname;
c.email = currentUser.email;
c.phone = currentUser.phone;
c.mobilephone = currentUser.mobilephone;
c.fax = currentUser.fax;
c.mailingstreet = currentUser.street;
c.mailingcity = currentUser.city;
c.mailingstate = currentUser.state;
c.mailingpostalcode = currentUser.postalcode;
c.mailingcountry = currentUser.country;
controller.save();
System.assert(Page.ChangePassword.getUrl().equals(controller.changePassword().getUrl()));
} else {
User existingPortalUser = existingPortalUsers[0];
String randFax = Math.rint(Math.random() * 1000) + '5551234';
System.runAs(existingPortalUser) {
MyProfilePageController controller = new MyProfilePageController();
System.assertEquals(existingPortalUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
System.assert(controller.getIsEdit() == false, 'isEdit should default to false');
controller.edit();
System.assert(controller.getIsEdit() == true);
controller.cancel();
System.assert(controller.getIsEdit() == false);
controller.getUser().Fax = randFax;
controller.save();
System.assert(controller.getIsEdit() == false);
}
// verify that the user and contact were updated
existingPortalUser = [Select id, fax, Contact.Fax from User where id =: existingPortalUser.Id];
System.assert(existingPortalUser.fax == randFax);
System.assert(existingPortalUser.Contact.fax == randFax);
}
}
}public class opcontact{
private boolean m_isExecuting = True;
private integer BatchSize = 0;
public opcontact(boolean isexecuting, integer size)
{
m_isexecuting=isexecuting;
batchsize=size;
}
public void onbeforeinsert(list<opportunity> triggernew,map<id,opportunity> triggernewmap)
{
updatelist(triggernew,triggernewmap);
}
private void updatelist(list<opportunity> triggernew,map<id,opportunity> triggernewmap)
{
set<id> sid=new set<id>();
if(triggernew!=null && triggernew.size()>0)
{
for(opportunity c: triggernew)
{
sid.add(c.accountid);
}}
if(sid!=null && sid.size()>0)
{
map<id,account> mapAccIdToAccount = new map<id,account>([select id,
(select id from contacts)
from account
where Id IN : sid]);
//list<opportunity> opc = [select id,no_of_contacts__c from opportunity];
if(triggernew!= null && triggernew.size() > 0)
{
for(opportunity eachopp : triggernew)
{
if(mapAccIdToAccount.get(eachopp.AccountId) != null)
{
Account objAcc = mapAccIdToAccount.get(eachopp.AccountId);
eachopp.NO_of_contacts__c = objAcc.contacts.size();
}
}
}
}
}
}/**
* An apex page controller that exposes the site login functionality
*/
global with sharing class SiteLoginController {
global String username {get; set;}
global String password {get; set;}
global PageReference login() {
String startUrl = System.currentPageReference().getParameters().get('startURL');
return Site.login(username, password, startUrl);
}
global SiteLoginController () {}
}/**
* An apex page controller that exposes the site login functionality
*/
@IsTest global with sharing class SiteLoginControllerTest {
@IsTest(SeeAllData=true) global static void testSiteLoginController () {
// Instantiate a new controller with all parameters in the page
SiteLoginController controller = new SiteLoginController ();
controller.username = 'test@salesforce.com';
controller.password = '123456';
System.assertEquals(controller.login(),null);
}
}/**
* An apex class that creates a portal user
*/
public with sharing class SiteRegisterController {
// PORTAL_ACCOUNT_ID is the account on which the contact will be created on and then enabled as a portal user.
// you need to add the account owner into the role hierarchy before this will work - please see Customer Portal Setup help for more information.
private static Id PORTAL_ACCOUNT_ID = '001x000xxx35tPN';
public SiteRegisterController () {
}
public String username {get; set;}
public String email {get; set;}
public String password {get; set {password = value == null ? value : value.trim(); } }
public String confirmPassword {get; set { confirmPassword = value == null ? value : value.trim(); } }
public String communityNickname {get; set { communityNickname = value == null ? value : value.trim(); } }
private boolean isValidPassword() {
return password == confirmPassword;
}
public PageReference registerUser() {
// it's okay if password is null - we'll send the user a random password in that case
if (!isValidPassword()) {
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.site.passwords_dont_match);
ApexPages.addMessage(msg);
return null;
}
User u = new User();
u.Username = username;
u.Email = email;
u.CommunityNickname = communityNickname;
String accountId = PORTAL_ACCOUNT_ID;
// lastName is a required field on user, but if it isn't specified, we'll default it to the username
String userId = Site.createPortalUser(u, accountId, password);
if (userId != null) {
if (password != null && password.length() > 1) {
return Site.login(username, password, null);
}
else {
PageReference page = System.Page.SiteRegisterConfirm;
page.setRedirect(true);
return page;
}
}
return null;
}
}/**
* Class containing tests for SiteRegisterController
*/
@IsTest public with sharing class SiteRegisterControllerTest {
@IsTest(SeeAllData=true) static void testRegistration() {
SiteRegisterController controller = new SiteRegisterController();
controller.username = 'test@force.com';
controller.email = 'test@force.com';
controller.communityNickname = 'test';
// registerUser will always return null when the page isn't accessed as a guest user
System.assert(controller.registerUser() == null);
controller.password = 'abcd1234';
controller.confirmPassword = 'abcd123';
System.assert(controller.registerUser() == null);
}
}/**
* Class containing tests for SiteRegisterController
*/
@IsTest public with sharing class SiteRegisterControllerTest {
@IsTest(SeeAllData=true) static void testRegistration() {
SiteRegisterController controller = new SiteRegisterController();
controller.username = 'test@force.com';
controller.email = 'test@force.com';
controller.communityNickname = 'test';
// registerUser will always return null when the page isn't accessed as a guest user
System.assert(controller.registerUser() == null);
controller.password = 'abcd1234';
controller.confirmPassword = 'abcd123';
System.assert(controller.registerUser() == null);
}
}
Select recordtype.id,id,name from contact where recordtype.id='01290000000tdmAAAQ'
SELECT Gender__c, COUNT(id) FROM Contact GROUP BY Gender__c
SELECT Gender__c, COUNT(id) FROM Contact where accountid='0019000000njPGeAAM' GROUP BY Gender__c
0019000000njPGeAAM
list<Account> lstAccount =
[select id, Name, Total_Contacts__c,(select id from contacts) from Account
where Id IN : setOfAccountIdFromContact];
public class ContactTriggerHandler{
private boolean m_isExecuting = True;
private integer BatchSize = 0;
public ContactTriggerHandler(boolean isExecuting, integer size)
{
m_isExecuting = isExecuting;
BatchSize = size;
}
/* public void onBeforeInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
}
public void OnBeforeUpdate(list<Contact> triggerNew, map<id,Contact> triggerNewMap, map<id,Contact> triggerOldMap)
{
}*/
public void OnAfterInsert(list<Contact> triggerNew, map<id,Contact> triggerNewMap)
{
updateNumberOfGenderContactsOnAccount(triggerNew, triggerNewMap);
updateNumberOfContactsOnAccount(triggerNew, triggerNewMap);
}
public void OnBeforeDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
}
public void OnAfterDelete(list<Contact> triggerOld, map<id,Contact> triggerOldMap)
{
// system.debug('after delete class');
updateNumberOfContactsOnAccount(triggerold, triggeroldMap);
}
/* private void updateNumberOfContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
setOfAccountIdFromContact.add(eachCon.AccountId);
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
list<Account> lstAccount = [select id, Name, Total_Contacts__c,
(select id from contacts)
from Account
where Id IN : setOfAccountIdFromContact];
if(lstAccount != null && lstAccount.size() > 0)
{
for(Account eachAccount : lstAccount)
{
eachAccount.Total_Contacts__c = eachAccount.contacts.size();
//eachAccount.Name += '_1';
}
update lstAccount;
}
}
}*/
private void updateNumberOfGenderContactsOnAccount(List<Contact> triggerNew,Map<id,Contact> triggerNewMap)
{
Set<id> setOfAccountIdFromContact=new Set<id>();
if(triggerNew!=null&&triggerNew.size()>0)
{
for(Contact eachCon : triggerNew)
{
if(eachCon.AccountId != null)
{
setOfAccountIdFromContact.add(eachCon.AccountId);
}
}
}
if(setOfAccountIdFromContact != null && setOfAccountIdFromContact.size() > 0)
{
List<Account> lstAccount = [select id, Name, Total_Contacts__c,Total_Female_Contacts__c,Total_male_Contacts__c from Account
where Id IN : setOfAccountIdFromContact];
List<Contact> lstcontact=[SELECT Gender__c, COUNT(id) total_Contact FROM Contact where accountid IN:setOfAccountIdFromContact GROUP BY Gender__c];
for(Account objAccount :lstAccount)
{
for(Contact objContact :lstContact)
{
if(objContact.gender__c='male')
{objAccount.Total_Male_Contacts=objContact.total_contact;}
if(objContact.gender__c='female')
{ objAccount.Total_Female_Contacts=objContact.total_contact;}
}
}
}
update lstAccount;
}
}
No comments:
Post a Comment