-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
1Questions
-
2Replies
NullPointer error message at deploy from sandbox to production
Hello,
I just use the right function to cut a string as is shown in the code below, the modified line is bold, the program works very well in the sand box, but when I deploy on the production environment I get a NullPointer error message on the modified line.
Thank you for your help
public without sharing class Ctrl001_NouveauProspect {
public string keyword {set;get;}
public string firstName{set;get;}
public string lastName{set;get;}
public string phone{set;get;}
public string email{set;get;}
public string CIN{set;get;}
public boolean AddButton {set;get;}
public boolean SearchResultButton{set;get;}
public boolean SearchResultLeadsButton{set;get;}
public boolean SearchResultAccountsButton{set;get;}
public boolean creationbutton{set;get;}
public Account [] accounts{set;get;}
public List<Account> ResultListAccount{set;get;}
public List<Lead> ResultListLead{set;get;}
public Lead[] leads{set;get;}
String accountQureyString ;
String LeadQureyString ;
public Account acc {set;get;}
public Lead piste {set;get;}
public Id accId {set;get;}
public Id pisteId {set;get;}
public Ctrl001_NouveauProspect(ApexPages.StandardController controller) {
ResultListAccount = new List<Account>();
ResultListLead = new List<Lead>();
}
public Ctrl001_NouveauProspect() {
AddButton = false;
SearchResultButton =false;
SearchResultLeadsButton =false;
SearchResultAccountsButton=false;
creationbutton=false;
}
public PageReference createProspect() {
string url = '/001/e?retURL=%2F001%2Fo';
if(firstName != null) {
url = url + '&name_firstacc2=' + firstName ;
}
if(lastName != null) {
url = url + '&name_lastacc2=' + lastName ;
}
if(phone != null) {
url = url + '&acc10=' + phone ;
}
if(email != null) {
url = url + '&PersonEmail=' + email ;
}
if(CIN != null) {
url = url + '&00N24000009s6qi=' + CIN ;
}
return new Pagereference(url);
}
public PageReference search(){
AddButton = false;
ResultListAccount = new List<Account>();
ResultListLead = new List<Lead>();
creationbutton=false;
string phone_like = '%'+phone.right(9)+'%';
System.debug('##KeyWord##'+keyword);
if(CIN != null && CIN.contains(' '))
{Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.WARNING,'Merci de saisir un CIN sans espaces'));}
//if(keyword!=null && keyword!=''){
System.debug('firstName'+firstName+'lastName'+lastName+'phone'+phone+'CIN'+CIN);
// List<List <sObject>> myQuery = search.query(SOSL_search_string);
// String searchquery='FIND\''+firstName+' '+lastName+' '+phone+' '+CIN+' *\'IN ALL FIELDS RETURNING Account(id,FirstName,LastName,Phone,N_piece_cni__c), Lead(id,FirstName,LastName,Phone)';
// 'SELECT Id FROM MyCustomObject__c WHERE field1__c = :myVariable.field1__c';
accountQureyString ='SELECT a.firstName, a.lastName, a.phone,a.PersonEmail, a.CIN__c from Account a WHERE ID !=null ';
if(firstName!=null && firstName!='')
{ accountQureyString+='AND (a.firstName =: firstName OR a.lastName =: firstName)'; }
if(lastName!=null && lastName!='')
{accountQureyString+='AND (a.lastName =: lastName OR a.firstName =: lastName)';}
if(phone!=null && phone!='')
//{ accountQureyString+='AND (a.phone =: phone OR a.PersonMobilePhone=: phone ) ';}
{ accountQureyString+='AND (a.phone like :phone_like OR a.PersonMobilePhone like :phone_like ) ';}
if(CIN!=null && CIN!='')
{accountQureyString+='AND a.CIN__c=: CIN ';}
if(email!=null && email!='')
{
accountQureyString+='AND a.PersonEmail =: email ';}
accountQureyString+=' limit 20';
System.debug('accountQureyString'+accountQureyString);
leadQureyString ='SELECT a.firstName, a.lastName, a.phone, a.Email from Lead a WHERE ID !=null ';
if(firstName!=null && firstName!='')
{ leadQureyString+='AND (a.firstName =: firstName OR a.lastName =: firstName)'; }
if(leadQureyString!=null && lastName!='')
{leadQureyString+='AND (a.lastName =: lastName OR a.firstName =: lastName)';}
if(phone!=null && phone!='')
{ leadQureyString+='AND (a.phone =: phone OR a.MobilePhone =: phone OR a.Fax =: phone)';}
if(email!=null && email!='')
{leadQureyString+='AND a.Email =: email ';}
leadQureyString+=' AND IsConverted = false limit 50';
//String searchquery='FIND\''+firstName+' '+lastName+' '+phone+' '+CIN+' *\'IN All Fields RETURNING Account(id,FirstName,LastName,Phone,CIN__c), Lead(id,FirstName,LastName,Phone)';
//System.debug('##searchquery'+searchquery);
if((firstName!=null && firstName!='') || (lastName!=null && lastName!='') || (phone!=null && phone!='') || (CIN!=null && CIN!='') || (email!=null && email!=''))
{ResultListAccount = Database.query(accountQureyString);}
if((firstName!=null && firstName!='') || (lastName!=null && lastName!='') || (phone!=null && phone!='') || (email!=null && email!=''))
{ResultListLead = Database.query(leadQureyString);}
System.debug('##ResultListAccount'+ResultListAccount);
System.debug('##ResultListLead'+ResultListLead);
//List<List<SObject>>searchList=search.query(searchquery);
//accounts = ((List<Account>)searchList[0]);
//leads = ((List<Lead>)searchList[1]);
//System.debug('accounts'+accounts);
//System.debug('leads'+leads);
if(ResultListAccount != null ||ResultListLead != null /*ResultListAccount.size()>0 ||ResultListLead.size()>0*/){
SearchResultButton=true;
}
if(ResultListAccount != null && (ResultListLead == null|| ResultListLead.size()==0)/*ResultListAccount.size()>0*/){
SearchResultAccountsButton=true;
}
if(ResultListLead != null /*ResultListLead.size()>0*/){
SearchResultLeadsButton=true;
}
if ((CIN!=null && CIN!='')||(phone!=null && phone!='')|| (email!=null && email!='')){
AddButton=true;
}
// }
if(ResultListAccount.size() == 0 && ResultListLead.size() == 0)
{creationbutton=true;}
//}
return null;
}
public PageReference addtoaccountteam(){
system.debug('>>>>>>>>>'+accId);
AccountTeamMember[] newmembers = new AccountTeamMember[]{}; //list of new team members to add
AccountShare[] newShare = new AccountShare[]{}; //list of new shares to add
User currentuser = [select id,name,department from user where id=:UserInfo.getUserId() LIMIT 1]; //get the user running the trigger, anyone that changes the Account will added to the account team
ID uid=currentuser.id;
String dept=currentuser.department;
AccountTeamMember Teammemberad=new AccountTeamMember();
Teammemberad.AccountId=accID;
Teammemberad.UserId=uid;
//Teammemberad.TeamMemberRole = dept;
Teammemberad.TeamMemberRole = 'Commercial';
newmembers.add(Teammemberad);
Database.SaveResult[] lsr = Database.insert(newmembers,false);//insert any valid members then add their entry if they were successfully added
Integer newcnt=0;
for(Database.SaveResult sr:lsr){
if(!sr.isSuccess()){
Database.Error emsg =sr.getErrors()[0];
system.debug('\n\nERROR ADDING TEAM MEMBER:'+emsg);
}else{
newShare.add(new AccountShare(UserOrGroupId=newmembers[newcnt].UserId, AccountId=newmembers[newcnt].Accountid, AccountAccessLevel='Edit',OpportunityAccessLevel='Edit',CaseAccessLevel='Read'));
}
newcnt++;
}
Database.SaveResult[] lsr0 =Database.insert(newShare,false); //insert the new shares
Integer newcnt0=0;
for(Database.SaveResult sr0:lsr0){
if(!sr0.isSuccess()){
Database.Error emsg0=sr0.getErrors()[0];
system.debug('\n\nERROR ADDING SHARING:'+newShare[newcnt0]+'::'+emsg0);
}
newcnt0++;
}
return new PageReference('/'+accId);
}
}
I just use the right function to cut a string as is shown in the code below, the modified line is bold, the program works very well in the sand box, but when I deploy on the production environment I get a NullPointer error message on the modified line.
Thank you for your help
public without sharing class Ctrl001_NouveauProspect {
public string keyword {set;get;}
public string firstName{set;get;}
public string lastName{set;get;}
public string phone{set;get;}
public string email{set;get;}
public string CIN{set;get;}
public boolean AddButton {set;get;}
public boolean SearchResultButton{set;get;}
public boolean SearchResultLeadsButton{set;get;}
public boolean SearchResultAccountsButton{set;get;}
public boolean creationbutton{set;get;}
public Account [] accounts{set;get;}
public List<Account> ResultListAccount{set;get;}
public List<Lead> ResultListLead{set;get;}
public Lead[] leads{set;get;}
String accountQureyString ;
String LeadQureyString ;
public Account acc {set;get;}
public Lead piste {set;get;}
public Id accId {set;get;}
public Id pisteId {set;get;}
public Ctrl001_NouveauProspect(ApexPages.StandardController controller) {
ResultListAccount = new List<Account>();
ResultListLead = new List<Lead>();
}
public Ctrl001_NouveauProspect() {
AddButton = false;
SearchResultButton =false;
SearchResultLeadsButton =false;
SearchResultAccountsButton=false;
creationbutton=false;
}
public PageReference createProspect() {
string url = '/001/e?retURL=%2F001%2Fo';
if(firstName != null) {
url = url + '&name_firstacc2=' + firstName ;
}
if(lastName != null) {
url = url + '&name_lastacc2=' + lastName ;
}
if(phone != null) {
url = url + '&acc10=' + phone ;
}
if(email != null) {
url = url + '&PersonEmail=' + email ;
}
if(CIN != null) {
url = url + '&00N24000009s6qi=' + CIN ;
}
return new Pagereference(url);
}
public PageReference search(){
AddButton = false;
ResultListAccount = new List<Account>();
ResultListLead = new List<Lead>();
creationbutton=false;
string phone_like = '%'+phone.right(9)+'%';
System.debug('##KeyWord##'+keyword);
if(CIN != null && CIN.contains(' '))
{Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.WARNING,'Merci de saisir un CIN sans espaces'));}
//if(keyword!=null && keyword!=''){
System.debug('firstName'+firstName+'lastName'+lastName+'phone'+phone+'CIN'+CIN);
// List<List <sObject>> myQuery = search.query(SOSL_search_string);
// String searchquery='FIND\''+firstName+' '+lastName+' '+phone+' '+CIN+' *\'IN ALL FIELDS RETURNING Account(id,FirstName,LastName,Phone,N_piece_cni__c), Lead(id,FirstName,LastName,Phone)';
// 'SELECT Id FROM MyCustomObject__c WHERE field1__c = :myVariable.field1__c';
accountQureyString ='SELECT a.firstName, a.lastName, a.phone,a.PersonEmail, a.CIN__c from Account a WHERE ID !=null ';
if(firstName!=null && firstName!='')
{ accountQureyString+='AND (a.firstName =: firstName OR a.lastName =: firstName)'; }
if(lastName!=null && lastName!='')
{accountQureyString+='AND (a.lastName =: lastName OR a.firstName =: lastName)';}
if(phone!=null && phone!='')
//{ accountQureyString+='AND (a.phone =: phone OR a.PersonMobilePhone=: phone ) ';}
{ accountQureyString+='AND (a.phone like :phone_like OR a.PersonMobilePhone like :phone_like ) ';}
if(CIN!=null && CIN!='')
{accountQureyString+='AND a.CIN__c=: CIN ';}
if(email!=null && email!='')
{
accountQureyString+='AND a.PersonEmail =: email ';}
accountQureyString+=' limit 20';
System.debug('accountQureyString'+accountQureyString);
leadQureyString ='SELECT a.firstName, a.lastName, a.phone, a.Email from Lead a WHERE ID !=null ';
if(firstName!=null && firstName!='')
{ leadQureyString+='AND (a.firstName =: firstName OR a.lastName =: firstName)'; }
if(leadQureyString!=null && lastName!='')
{leadQureyString+='AND (a.lastName =: lastName OR a.firstName =: lastName)';}
if(phone!=null && phone!='')
{ leadQureyString+='AND (a.phone =: phone OR a.MobilePhone =: phone OR a.Fax =: phone)';}
if(email!=null && email!='')
{leadQureyString+='AND a.Email =: email ';}
leadQureyString+=' AND IsConverted = false limit 50';
//String searchquery='FIND\''+firstName+' '+lastName+' '+phone+' '+CIN+' *\'IN All Fields RETURNING Account(id,FirstName,LastName,Phone,CIN__c), Lead(id,FirstName,LastName,Phone)';
//System.debug('##searchquery'+searchquery);
if((firstName!=null && firstName!='') || (lastName!=null && lastName!='') || (phone!=null && phone!='') || (CIN!=null && CIN!='') || (email!=null && email!=''))
{ResultListAccount = Database.query(accountQureyString);}
if((firstName!=null && firstName!='') || (lastName!=null && lastName!='') || (phone!=null && phone!='') || (email!=null && email!=''))
{ResultListLead = Database.query(leadQureyString);}
System.debug('##ResultListAccount'+ResultListAccount);
System.debug('##ResultListLead'+ResultListLead);
//List<List<SObject>>searchList=search.query(searchquery);
//accounts = ((List<Account>)searchList[0]);
//leads = ((List<Lead>)searchList[1]);
//System.debug('accounts'+accounts);
//System.debug('leads'+leads);
if(ResultListAccount != null ||ResultListLead != null /*ResultListAccount.size()>0 ||ResultListLead.size()>0*/){
SearchResultButton=true;
}
if(ResultListAccount != null && (ResultListLead == null|| ResultListLead.size()==0)/*ResultListAccount.size()>0*/){
SearchResultAccountsButton=true;
}
if(ResultListLead != null /*ResultListLead.size()>0*/){
SearchResultLeadsButton=true;
}
if ((CIN!=null && CIN!='')||(phone!=null && phone!='')|| (email!=null && email!='')){
AddButton=true;
}
// }
if(ResultListAccount.size() == 0 && ResultListLead.size() == 0)
{creationbutton=true;}
//}
return null;
}
public PageReference addtoaccountteam(){
system.debug('>>>>>>>>>'+accId);
AccountTeamMember[] newmembers = new AccountTeamMember[]{}; //list of new team members to add
AccountShare[] newShare = new AccountShare[]{}; //list of new shares to add
User currentuser = [select id,name,department from user where id=:UserInfo.getUserId() LIMIT 1]; //get the user running the trigger, anyone that changes the Account will added to the account team
ID uid=currentuser.id;
String dept=currentuser.department;
AccountTeamMember Teammemberad=new AccountTeamMember();
Teammemberad.AccountId=accID;
Teammemberad.UserId=uid;
//Teammemberad.TeamMemberRole = dept;
Teammemberad.TeamMemberRole = 'Commercial';
newmembers.add(Teammemberad);
Database.SaveResult[] lsr = Database.insert(newmembers,false);//insert any valid members then add their entry if they were successfully added
Integer newcnt=0;
for(Database.SaveResult sr:lsr){
if(!sr.isSuccess()){
Database.Error emsg =sr.getErrors()[0];
system.debug('\n\nERROR ADDING TEAM MEMBER:'+emsg);
}else{
newShare.add(new AccountShare(UserOrGroupId=newmembers[newcnt].UserId, AccountId=newmembers[newcnt].Accountid, AccountAccessLevel='Edit',OpportunityAccessLevel='Edit',CaseAccessLevel='Read'));
}
newcnt++;
}
Database.SaveResult[] lsr0 =Database.insert(newShare,false); //insert the new shares
Integer newcnt0=0;
for(Database.SaveResult sr0:lsr0){
if(!sr0.isSuccess()){
Database.Error emsg0=sr0.getErrors()[0];
system.debug('\n\nERROR ADDING SHARING:'+newShare[newcnt0]+'::'+emsg0);
}
newcnt0++;
}
return new PageReference('/'+accId);
}
}
- el mougali rachid 5
- July 01, 2016
- Like
- 0
NullPointer error message at deploy from sandbox to production
Hello,
I just use the right function to cut a string as is shown in the code below, the modified line is bold, the program works very well in the sand box, but when I deploy on the production environment I get a NullPointer error message on the modified line.
Thank you for your help
public without sharing class Ctrl001_NouveauProspect {
public string keyword {set;get;}
public string firstName{set;get;}
public string lastName{set;get;}
public string phone{set;get;}
public string email{set;get;}
public string CIN{set;get;}
public boolean AddButton {set;get;}
public boolean SearchResultButton{set;get;}
public boolean SearchResultLeadsButton{set;get;}
public boolean SearchResultAccountsButton{set;get;}
public boolean creationbutton{set;get;}
public Account [] accounts{set;get;}
public List<Account> ResultListAccount{set;get;}
public List<Lead> ResultListLead{set;get;}
public Lead[] leads{set;get;}
String accountQureyString ;
String LeadQureyString ;
public Account acc {set;get;}
public Lead piste {set;get;}
public Id accId {set;get;}
public Id pisteId {set;get;}
public Ctrl001_NouveauProspect(ApexPages.StandardController controller) {
ResultListAccount = new List<Account>();
ResultListLead = new List<Lead>();
}
public Ctrl001_NouveauProspect() {
AddButton = false;
SearchResultButton =false;
SearchResultLeadsButton =false;
SearchResultAccountsButton=false;
creationbutton=false;
}
public PageReference createProspect() {
string url = '/001/e?retURL=%2F001%2Fo';
if(firstName != null) {
url = url + '&name_firstacc2=' + firstName ;
}
if(lastName != null) {
url = url + '&name_lastacc2=' + lastName ;
}
if(phone != null) {
url = url + '&acc10=' + phone ;
}
if(email != null) {
url = url + '&PersonEmail=' + email ;
}
if(CIN != null) {
url = url + '&00N24000009s6qi=' + CIN ;
}
return new Pagereference(url);
}
public PageReference search(){
AddButton = false;
ResultListAccount = new List<Account>();
ResultListLead = new List<Lead>();
creationbutton=false;
string phone_like = '%'+phone.right(9)+'%';
System.debug('##KeyWord##'+keyword);
if(CIN != null && CIN.contains(' '))
{Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.WARNING,'Merci de saisir un CIN sans espaces'));}
//if(keyword!=null && keyword!=''){
System.debug('firstName'+firstName+'lastName'+lastName+'phone'+phone+'CIN'+CIN);
// List<List <sObject>> myQuery = search.query(SOSL_search_string);
// String searchquery='FIND\''+firstName+' '+lastName+' '+phone+' '+CIN+' *\'IN ALL FIELDS RETURNING Account(id,FirstName,LastName,Phone,N_piece_cni__c), Lead(id,FirstName,LastName,Phone)';
// 'SELECT Id FROM MyCustomObject__c WHERE field1__c = :myVariable.field1__c';
accountQureyString ='SELECT a.firstName, a.lastName, a.phone,a.PersonEmail, a.CIN__c from Account a WHERE ID !=null ';
if(firstName!=null && firstName!='')
{ accountQureyString+='AND (a.firstName =: firstName OR a.lastName =: firstName)'; }
if(lastName!=null && lastName!='')
{accountQureyString+='AND (a.lastName =: lastName OR a.firstName =: lastName)';}
if(phone!=null && phone!='')
//{ accountQureyString+='AND (a.phone =: phone OR a.PersonMobilePhone=: phone ) ';}
{ accountQureyString+='AND (a.phone like :phone_like OR a.PersonMobilePhone like :phone_like ) ';}
if(CIN!=null && CIN!='')
{accountQureyString+='AND a.CIN__c=: CIN ';}
if(email!=null && email!='')
{
accountQureyString+='AND a.PersonEmail =: email ';}
accountQureyString+=' limit 20';
System.debug('accountQureyString'+accountQureyString);
leadQureyString ='SELECT a.firstName, a.lastName, a.phone, a.Email from Lead a WHERE ID !=null ';
if(firstName!=null && firstName!='')
{ leadQureyString+='AND (a.firstName =: firstName OR a.lastName =: firstName)'; }
if(leadQureyString!=null && lastName!='')
{leadQureyString+='AND (a.lastName =: lastName OR a.firstName =: lastName)';}
if(phone!=null && phone!='')
{ leadQureyString+='AND (a.phone =: phone OR a.MobilePhone =: phone OR a.Fax =: phone)';}
if(email!=null && email!='')
{leadQureyString+='AND a.Email =: email ';}
leadQureyString+=' AND IsConverted = false limit 50';
//String searchquery='FIND\''+firstName+' '+lastName+' '+phone+' '+CIN+' *\'IN All Fields RETURNING Account(id,FirstName,LastName,Phone,CIN__c), Lead(id,FirstName,LastName,Phone)';
//System.debug('##searchquery'+searchquery);
if((firstName!=null && firstName!='') || (lastName!=null && lastName!='') || (phone!=null && phone!='') || (CIN!=null && CIN!='') || (email!=null && email!=''))
{ResultListAccount = Database.query(accountQureyString);}
if((firstName!=null && firstName!='') || (lastName!=null && lastName!='') || (phone!=null && phone!='') || (email!=null && email!=''))
{ResultListLead = Database.query(leadQureyString);}
System.debug('##ResultListAccount'+ResultListAccount);
System.debug('##ResultListLead'+ResultListLead);
//List<List<SObject>>searchList=search.query(searchquery);
//accounts = ((List<Account>)searchList[0]);
//leads = ((List<Lead>)searchList[1]);
//System.debug('accounts'+accounts);
//System.debug('leads'+leads);
if(ResultListAccount != null ||ResultListLead != null /*ResultListAccount.size()>0 ||ResultListLead.size()>0*/){
SearchResultButton=true;
}
if(ResultListAccount != null && (ResultListLead == null|| ResultListLead.size()==0)/*ResultListAccount.size()>0*/){
SearchResultAccountsButton=true;
}
if(ResultListLead != null /*ResultListLead.size()>0*/){
SearchResultLeadsButton=true;
}
if ((CIN!=null && CIN!='')||(phone!=null && phone!='')|| (email!=null && email!='')){
AddButton=true;
}
// }
if(ResultListAccount.size() == 0 && ResultListLead.size() == 0)
{creationbutton=true;}
//}
return null;
}
public PageReference addtoaccountteam(){
system.debug('>>>>>>>>>'+accId);
AccountTeamMember[] newmembers = new AccountTeamMember[]{}; //list of new team members to add
AccountShare[] newShare = new AccountShare[]{}; //list of new shares to add
User currentuser = [select id,name,department from user where id=:UserInfo.getUserId() LIMIT 1]; //get the user running the trigger, anyone that changes the Account will added to the account team
ID uid=currentuser.id;
String dept=currentuser.department;
AccountTeamMember Teammemberad=new AccountTeamMember();
Teammemberad.AccountId=accID;
Teammemberad.UserId=uid;
//Teammemberad.TeamMemberRole = dept;
Teammemberad.TeamMemberRole = 'Commercial';
newmembers.add(Teammemberad);
Database.SaveResult[] lsr = Database.insert(newmembers,false);//insert any valid members then add their entry if they were successfully added
Integer newcnt=0;
for(Database.SaveResult sr:lsr){
if(!sr.isSuccess()){
Database.Error emsg =sr.getErrors()[0];
system.debug('\n\nERROR ADDING TEAM MEMBER:'+emsg);
}else{
newShare.add(new AccountShare(UserOrGroupId=newmembers[newcnt].UserId, AccountId=newmembers[newcnt].Accountid, AccountAccessLevel='Edit',OpportunityAccessLevel='Edit',CaseAccessLevel='Read'));
}
newcnt++;
}
Database.SaveResult[] lsr0 =Database.insert(newShare,false); //insert the new shares
Integer newcnt0=0;
for(Database.SaveResult sr0:lsr0){
if(!sr0.isSuccess()){
Database.Error emsg0=sr0.getErrors()[0];
system.debug('\n\nERROR ADDING SHARING:'+newShare[newcnt0]+'::'+emsg0);
}
newcnt0++;
}
return new PageReference('/'+accId);
}
}
I just use the right function to cut a string as is shown in the code below, the modified line is bold, the program works very well in the sand box, but when I deploy on the production environment I get a NullPointer error message on the modified line.
Thank you for your help
public without sharing class Ctrl001_NouveauProspect {
public string keyword {set;get;}
public string firstName{set;get;}
public string lastName{set;get;}
public string phone{set;get;}
public string email{set;get;}
public string CIN{set;get;}
public boolean AddButton {set;get;}
public boolean SearchResultButton{set;get;}
public boolean SearchResultLeadsButton{set;get;}
public boolean SearchResultAccountsButton{set;get;}
public boolean creationbutton{set;get;}
public Account [] accounts{set;get;}
public List<Account> ResultListAccount{set;get;}
public List<Lead> ResultListLead{set;get;}
public Lead[] leads{set;get;}
String accountQureyString ;
String LeadQureyString ;
public Account acc {set;get;}
public Lead piste {set;get;}
public Id accId {set;get;}
public Id pisteId {set;get;}
public Ctrl001_NouveauProspect(ApexPages.StandardController controller) {
ResultListAccount = new List<Account>();
ResultListLead = new List<Lead>();
}
public Ctrl001_NouveauProspect() {
AddButton = false;
SearchResultButton =false;
SearchResultLeadsButton =false;
SearchResultAccountsButton=false;
creationbutton=false;
}
public PageReference createProspect() {
string url = '/001/e?retURL=%2F001%2Fo';
if(firstName != null) {
url = url + '&name_firstacc2=' + firstName ;
}
if(lastName != null) {
url = url + '&name_lastacc2=' + lastName ;
}
if(phone != null) {
url = url + '&acc10=' + phone ;
}
if(email != null) {
url = url + '&PersonEmail=' + email ;
}
if(CIN != null) {
url = url + '&00N24000009s6qi=' + CIN ;
}
return new Pagereference(url);
}
public PageReference search(){
AddButton = false;
ResultListAccount = new List<Account>();
ResultListLead = new List<Lead>();
creationbutton=false;
string phone_like = '%'+phone.right(9)+'%';
System.debug('##KeyWord##'+keyword);
if(CIN != null && CIN.contains(' '))
{Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.WARNING,'Merci de saisir un CIN sans espaces'));}
//if(keyword!=null && keyword!=''){
System.debug('firstName'+firstName+'lastName'+lastName+'phone'+phone+'CIN'+CIN);
// List<List <sObject>> myQuery = search.query(SOSL_search_string);
// String searchquery='FIND\''+firstName+' '+lastName+' '+phone+' '+CIN+' *\'IN ALL FIELDS RETURNING Account(id,FirstName,LastName,Phone,N_piece_cni__c), Lead(id,FirstName,LastName,Phone)';
// 'SELECT Id FROM MyCustomObject__c WHERE field1__c = :myVariable.field1__c';
accountQureyString ='SELECT a.firstName, a.lastName, a.phone,a.PersonEmail, a.CIN__c from Account a WHERE ID !=null ';
if(firstName!=null && firstName!='')
{ accountQureyString+='AND (a.firstName =: firstName OR a.lastName =: firstName)'; }
if(lastName!=null && lastName!='')
{accountQureyString+='AND (a.lastName =: lastName OR a.firstName =: lastName)';}
if(phone!=null && phone!='')
//{ accountQureyString+='AND (a.phone =: phone OR a.PersonMobilePhone=: phone ) ';}
{ accountQureyString+='AND (a.phone like :phone_like OR a.PersonMobilePhone like :phone_like ) ';}
if(CIN!=null && CIN!='')
{accountQureyString+='AND a.CIN__c=: CIN ';}
if(email!=null && email!='')
{
accountQureyString+='AND a.PersonEmail =: email ';}
accountQureyString+=' limit 20';
System.debug('accountQureyString'+accountQureyString);
leadQureyString ='SELECT a.firstName, a.lastName, a.phone, a.Email from Lead a WHERE ID !=null ';
if(firstName!=null && firstName!='')
{ leadQureyString+='AND (a.firstName =: firstName OR a.lastName =: firstName)'; }
if(leadQureyString!=null && lastName!='')
{leadQureyString+='AND (a.lastName =: lastName OR a.firstName =: lastName)';}
if(phone!=null && phone!='')
{ leadQureyString+='AND (a.phone =: phone OR a.MobilePhone =: phone OR a.Fax =: phone)';}
if(email!=null && email!='')
{leadQureyString+='AND a.Email =: email ';}
leadQureyString+=' AND IsConverted = false limit 50';
//String searchquery='FIND\''+firstName+' '+lastName+' '+phone+' '+CIN+' *\'IN All Fields RETURNING Account(id,FirstName,LastName,Phone,CIN__c), Lead(id,FirstName,LastName,Phone)';
//System.debug('##searchquery'+searchquery);
if((firstName!=null && firstName!='') || (lastName!=null && lastName!='') || (phone!=null && phone!='') || (CIN!=null && CIN!='') || (email!=null && email!=''))
{ResultListAccount = Database.query(accountQureyString);}
if((firstName!=null && firstName!='') || (lastName!=null && lastName!='') || (phone!=null && phone!='') || (email!=null && email!=''))
{ResultListLead = Database.query(leadQureyString);}
System.debug('##ResultListAccount'+ResultListAccount);
System.debug('##ResultListLead'+ResultListLead);
//List<List<SObject>>searchList=search.query(searchquery);
//accounts = ((List<Account>)searchList[0]);
//leads = ((List<Lead>)searchList[1]);
//System.debug('accounts'+accounts);
//System.debug('leads'+leads);
if(ResultListAccount != null ||ResultListLead != null /*ResultListAccount.size()>0 ||ResultListLead.size()>0*/){
SearchResultButton=true;
}
if(ResultListAccount != null && (ResultListLead == null|| ResultListLead.size()==0)/*ResultListAccount.size()>0*/){
SearchResultAccountsButton=true;
}
if(ResultListLead != null /*ResultListLead.size()>0*/){
SearchResultLeadsButton=true;
}
if ((CIN!=null && CIN!='')||(phone!=null && phone!='')|| (email!=null && email!='')){
AddButton=true;
}
// }
if(ResultListAccount.size() == 0 && ResultListLead.size() == 0)
{creationbutton=true;}
//}
return null;
}
public PageReference addtoaccountteam(){
system.debug('>>>>>>>>>'+accId);
AccountTeamMember[] newmembers = new AccountTeamMember[]{}; //list of new team members to add
AccountShare[] newShare = new AccountShare[]{}; //list of new shares to add
User currentuser = [select id,name,department from user where id=:UserInfo.getUserId() LIMIT 1]; //get the user running the trigger, anyone that changes the Account will added to the account team
ID uid=currentuser.id;
String dept=currentuser.department;
AccountTeamMember Teammemberad=new AccountTeamMember();
Teammemberad.AccountId=accID;
Teammemberad.UserId=uid;
//Teammemberad.TeamMemberRole = dept;
Teammemberad.TeamMemberRole = 'Commercial';
newmembers.add(Teammemberad);
Database.SaveResult[] lsr = Database.insert(newmembers,false);//insert any valid members then add their entry if they were successfully added
Integer newcnt=0;
for(Database.SaveResult sr:lsr){
if(!sr.isSuccess()){
Database.Error emsg =sr.getErrors()[0];
system.debug('\n\nERROR ADDING TEAM MEMBER:'+emsg);
}else{
newShare.add(new AccountShare(UserOrGroupId=newmembers[newcnt].UserId, AccountId=newmembers[newcnt].Accountid, AccountAccessLevel='Edit',OpportunityAccessLevel='Edit',CaseAccessLevel='Read'));
}
newcnt++;
}
Database.SaveResult[] lsr0 =Database.insert(newShare,false); //insert the new shares
Integer newcnt0=0;
for(Database.SaveResult sr0:lsr0){
if(!sr0.isSuccess()){
Database.Error emsg0=sr0.getErrors()[0];
system.debug('\n\nERROR ADDING SHARING:'+newShare[newcnt0]+'::'+emsg0);
}
newcnt0++;
}
return new PageReference('/'+accId);
}
}
- el mougali rachid 5
- July 01, 2016
- Like
- 0