-
ChatterFeed
-
1Best Answers
-
1Likes Received
-
0Likes Given
-
17Questions
-
17Replies
Can you create a custom button with javascript that is able to change the label of the button?
Hey,
I'm in the process of developing a custom button on Salesforce that is able to toggle a checkbox on and off.
At this point, I am using the Salesforce AJAX Toolkit in order to do the main backend functions of the custom button.
I have the backend working, but I was hoping I could have the custom button label toggle between "Start Process" and "End Process".
To do this, I assume I would need the custom button to change it's own label.
I attempted this by placing these lines in my code:
It's also entirely possible that I cannot change the name of the button with the AJAX Toolkit.
I am very new to Salesforce and learning about this tool, so any ideas or suggestions will be greatly appreciated!
Thanks,
TF
I'm in the process of developing a custom button on Salesforce that is able to toggle a checkbox on and off.
At this point, I am using the Salesforce AJAX Toolkit in order to do the main backend functions of the custom button.
I have the backend working, but I was hoping I could have the custom button label toggle between "Start Process" and "End Process".
To do this, I assume I would need the custom button to change it's own label.
I attempted this by placing these lines in my code:
var toggleButton = new sforce.SObject("Lead"); var toggleButtonT ="{!Lead.Begin_Touch_Process}"; //my attempt to reference the button toggleButtonT.Id = "00bc0000000QoaE"; // my attempt to reference the button id toggleButtonT.Label = "test"; // entering new value for the button label result = sforce.connection.update([toggleButton]); // updating the buttonNOTE: {!RequireScript} is already mentioned in script.
It's also entirely possible that I cannot change the name of the button with the AJAX Toolkit.
I am very new to Salesforce and learning about this tool, so any ideas or suggestions will be greatly appreciated!
Thanks,
TF
- Thomas Fuller
- June 03, 2014
- Like
- 0
- Continue reading or reply
Retrieve Data from a field using string.
Hello All,
I have the Api name of a field in string format. How can i retrieve the data from that field using that string. For example,
On Lead object i ahave a field called Points__c.
Now in apex code i have somthing like this. String field = 'Points__c';
From this how can i get the value of lead.Points__c?
Thanks in advance.
I have the Api name of a field in string format. How can i retrieve the data from that field using that string. For example,
On Lead object i ahave a field called Points__c.
Now in apex code i have somthing like this. String field = 'Points__c';
From this how can i get the value of lead.Points__c?
Thanks in advance.
- Vishnu_SFDC
- November 20, 2014
- Like
- 0
- Continue reading or reply
HTTP POST bad request error.
Hi Guys,
Below is the format in which i had to send data.
POST https://<target_domain>/db/main HTTP/1.0
Content-Type: application/xml
Content-Length:
QUICKBASE-ACTION: API_Authenticate
<qdbapi>
<username>PTBarnum</username>
<password>TopSecret</password>
<hours>24</hours>
<udata>optional data</udata>
</qdbapi>
Below is the APEX class i am using to build the above request.
I get bad request as the responce.
i need some help in finding out where i am going wrong.
Thanks,
Vishnu
Below is the format in which i had to send data.
POST https://<target_domain>/db/main HTTP/1.0
Content-Type: application/xml
Content-Length:
QUICKBASE-ACTION: API_Authenticate
<qdbapi>
<username>PTBarnum</username>
<password>TopSecret</password>
<hours>24</hours>
<udata>optional data</udata>
</qdbapi>
Below is the APEX class i am using to build the above request.
HttpRequest req = new HttpRequest(); HttpResponse res = new HttpResponse(); Http http = new Http(); string test = ' <qdbapi><username>xx</username><password>xx</password><hours>24</hours><udata>optional data</udata></qdbapi>'; req.setEndpoint('https://oneroofenergy.quickbase.com/db/main HTTP/1.0'); req.setheader('content-Length',''); req.setheader('QUICKBASE-ACTION','API_Authenticate'); req.setHeader('Content-Type', 'application/xml'); req.setMethod('POST'); req.setBody(test); res = http.send(req); system.debug(res);
I get bad request as the responce.
i need some help in finding out where i am going wrong.
Thanks,
Vishnu
- Vishnu_SFDC
- August 18, 2014
- Like
- 0
- Continue reading or reply
Iterate through the list and compare each element with every other element.
To achieve this i am using two for loops which is a bad approch. can any one suggest me a better approch than this.
for example: if i compare slot[10] and slot[11] and i remove slot[11], i also have to compare slot[10] and slot[12] which is not happening in below code without using extra for loop.
T
hanks for your help.
for example: if i compare slot[10] and slot[11] and i remove slot[11], i also have to compare slot[10] and slot[12] which is not happening in below code without using extra for loop.
T
for(integer j=0;j<=repsid.size();j++) { for(integer i=0;i<=slots.size()-2;i++) { if(slots[i].StartDateTime==slots[i+1].StartDateTime) { if(slots[i].NumberofEvents==slots[i+1].NumberofEvents && slots[i].distance==slots[i+1].distance) { slots.remove(i+1); } else { if(slots[i].NumberofEvents==slots[i+1].NumberofEvents && slots[i].distance!=slots[i+1].distance && apptmin != 90) { if(slots[i].distance<slots[i+1].distance) { slots.remove(i+1); } else { slots.remove(i); } } else { if((slots[i].NumberofEvents!=slots[i+1].NumberofEvents && slots[i].distance>10 && slots[i+1].distance>10) || slots[i].NumberofEvents!=slots[i+1].NumberofEvents && apptmin==90) { if(slots[i].NumberofEvents<slots[i+1].NumberofEvents) { slots.remove(i+1); } else { slots.remove(i); } } else { if(slots[i].distance < slots[i+1].distance) { slots.remove(i+1); } else { slots.remove(i); } } } } } } }
hanks for your help.
- Vishnu_SFDC
- July 16, 2014
- Like
- 0
- Continue reading or reply
List Index out of bounds Error
Hello ,
Below is the code for which i am getting the error.
but i get List index out of bounds: 263 error.
can someone help me out with this.
Thanks,
Vishnu
Below is the code for which i am getting the error.
system.debug(slots.size()); for(Integer i =slots.size()-1;i>=0; i--) { system.debug(slots[i]); date d = Date.newinstance((slots[i].StartDateTime).year(),(slots[i].StartDateTime).month(),(slots[i].StartDateTime).day()); for (event__c e : event) { system.debug(e); system.debug(today2); //date d2 = Date.newinstance((e.Start_Datetime__c).year(),(e.Start_Datetime__c).month(),(e.Start_Datetime__c).day()); if(((slots[i].startDateTime<e.Start_Datetime__c && slots[i].StartDateTime.addminutes(apptmin)<e.Start_Datetime__c) || (slots[i].startDateTime>e.End_Datetime__c && slots[i].startDateTime.addminutes(apptmin)>e.End_Datetime__c)) && (e.Start_Datetime__c <=today2.addDays(6) && e.Start_DateTime__c >= today2.addDays(-1))) { } else { if(slots[i].userid == e.Event_Owner__c) { slots.remove(i); } } } }When i debug the size i get size = 264.
but i get List index out of bounds: 263 error.
can someone help me out with this.
Thanks,
Vishnu
- Vishnu_SFDC
- July 02, 2014
- Like
- 0
- Continue reading or reply
How to compare date with another custom date in an SOQL query
Hello,
Below is the requirment.
I have to get all records which are greater than a custom date(which is calculated in apex class).
example:
list<event__c> e = [select Id,Start_Datetime__c From event__c Where Start_Datetime__c > "Custom date" ];
Thanks,
Vishnu
Below is the requirment.
I have to get all records which are greater than a custom date(which is calculated in apex class).
example:
list<event__c> e = [select Id,Start_Datetime__c From event__c Where Start_Datetime__c > "Custom date" ];
Thanks,
Vishnu
- Vishnu_SFDC
- July 01, 2014
- Like
- 0
- Continue reading or reply
Passing value from visualforce Radio Button to Controller
Hi Everyone,
Below is my visualforce page.
<apex:column headerValue="Select" >
<apex:actionsupport event="onclick" >
<input type="radio" />
<apex:param name="RepId" value="{!Item.id}">
</apex:param></apex:actionsupport>
</apex:column>
<apex:column headervalue="Name">
<apex:outputfield style="width:2500px" value="{!Item.User__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Start DateTime">
<apex:outputfield value="{!Item.Start_DateTime__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="End DateTime">
<apex:outputfield value="{!Item.End_DateTime__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Approximate Distance To Appointment">
<apex:outputfield value="{!Item.Distance__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Number of events">
<apex:outputfield value="{!Item.Number_of_Events__c}">
How can i pass the value of of that row to the controller class.
Thanks in advance.
Below is my visualforce page.
<apex:column headerValue="Select" >
<apex:actionsupport event="onclick" >
<input type="radio" />
<apex:param name="RepId" value="{!Item.id}">
</apex:param></apex:actionsupport>
</apex:column>
<apex:column headervalue="Name">
<apex:outputfield style="width:2500px" value="{!Item.User__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Start DateTime">
<apex:outputfield value="{!Item.Start_DateTime__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="End DateTime">
<apex:outputfield value="{!Item.End_DateTime__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Approximate Distance To Appointment">
<apex:outputfield value="{!Item.Distance__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Number of events">
<apex:outputfield value="{!Item.Number_of_Events__c}">
How can i pass the value of of that row to the controller class.
Thanks in advance.
- Vishnu_SFDC
- June 06, 2014
- Like
- 0
- Continue reading or reply
System.CalloutException
I get this error when using RESt API and future call to post data to external system "System.CalloutException: IO Exception: java.security.cert.CertificateException: No subject alternative names present".
But when i use java script to post data to same URL i works fine.
Can any body heplp me with tis.
Thanks,
Vishnu
But when i use java script to post data to same URL i works fine.
Can any body heplp me with tis.
Thanks,
Vishnu
- Vishnu_SFDC
- May 21, 2014
- Like
- 0
- Continue reading or reply
Scheduled apex jobs are not running properly.
some scheduled batch jobs show up in the scheduled jobs list as completed but are missing in the Apex jobs page. These batch jobs are not even beng executed.
- Vishnu_SFDC
- May 18, 2014
- Like
- 0
- Continue reading or reply
Urgent: Internal Salesforce Error for following apex class.
It was working fine till yesterday. Suddenly its giving me the above error in DEBUG Logs and in Apex jobs page it gives First error: AsyncApexExecutions Limit exceeded.
can some one please help me.
Thanks in advance.
global class DEREDistributer implements Database.Batchable<sObject>, Database.AllowsCallouts,Database.stateful {
global integer x=0;
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Name,Times_The_Lead_Is_Distributed__c,Hawaii__c,SV_Priority_Hidden__c, Id, AssignToUserId_Hidden__c FROM Lead WHERE IsConverted =false and Hawaii__c = false and To_Be_Distributed__c=true and DE_Synched__c=true and Is_Distributed__c =True ';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Lead> scope) {
List<Team1__c> L1 = [SELECT Name,CheckIn__c From Team1__c Where CheckIn__c = True];
integer i = L1.size();
integer z=1;
//Initialize the AZ Qualification Team
for(Team1__c L2 :[SELECT Name,CheckIn__c,UserId__c From Team1__c] )
{
If(L2.CheckIn__c == True)
{
L2.UserId__c = z++;
update L2;
}
else
{
L2.UserId__c =0;
update L2;
}
}
for (Lead e : scope) {
//assingn user id,distribution count and distributed flag.
x++;
decimal y = e.Times_The_Lead_Is_Distributed__c;
e.AssignToUserId_Hidden__c = math.MOD(x, i) + 1;
e.Is_Distributed__c =True;
e.Times_The_Lead_Is_Distributed__c = y +1;
Update scope;
}
}
global void finish(Database.BatchableContext BC) { }
}
can some one please help me.
Thanks in advance.
global class DEREDistributer implements Database.Batchable<sObject>, Database.AllowsCallouts,Database.stateful {
global integer x=0;
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Name,Times_The_Lead_Is_Distributed__c,Hawaii__c,SV_Priority_Hidden__c, Id, AssignToUserId_Hidden__c FROM Lead WHERE IsConverted =false and Hawaii__c = false and To_Be_Distributed__c=true and DE_Synched__c=true and Is_Distributed__c =True ';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Lead> scope) {
List<Team1__c> L1 = [SELECT Name,CheckIn__c From Team1__c Where CheckIn__c = True];
integer i = L1.size();
integer z=1;
//Initialize the AZ Qualification Team
for(Team1__c L2 :[SELECT Name,CheckIn__c,UserId__c From Team1__c] )
{
If(L2.CheckIn__c == True)
{
L2.UserId__c = z++;
update L2;
}
else
{
L2.UserId__c =0;
update L2;
}
}
for (Lead e : scope) {
//assingn user id,distribution count and distributed flag.
x++;
decimal y = e.Times_The_Lead_Is_Distributed__c;
e.AssignToUserId_Hidden__c = math.MOD(x, i) + 1;
e.Is_Distributed__c =True;
e.Times_The_Lead_Is_Distributed__c = y +1;
Update scope;
}
}
global void finish(Database.BatchableContext BC) { }
}
- Vishnu_SFDC
- May 10, 2014
- Like
- 0
- Continue reading or reply
Receiving Non-Selective Query Error
Hi All,
I am receiving the above arror only for phone and Street. As email Is already idexed its working fine.
How can i make Phone and Street Fields Indexed. I contactacted salesforce support and ther redirected me to post my question here.
Can someone help me out with this.
Code:
trigger leadDuplicatePreventer on Lead (before insert, before update) {
//ORE Record Type
Map<String, Lead> leadMapORE = new Map<String, Lead>(); //for email
Map<String, Lead> leadMapOREPhone = new Map<String, Lead>(); //for phone
Map<String, Lead> leadMapOREStreet = new Map<String, Lead>(); //for street
for (Lead leadORE : System.Trigger.new) {
if(leadORE.RecordTypeId=='012i0000000VWJS')
{
// check weater any new lead with same email,phone, street is being created(list uploads)
if ((leadORE.Email != null) &&
(System.Trigger.isInsert ||
(leadORE.Email !=System.Trigger.oldMap.get(leadORE.Id).Email))) {
// Make sure another new lead isn't also a duplicate
if (leadMapORE.containsKey(leadORE.Email)) {
leadORE.Email.addError('Another new lead has the same email Address.');
} else {
leadMapORE.put(leadORE.Email, leadORE); //add email to email list
}
}
if ((leadORE.Phone != null) &&
(System.Trigger.isInsert ||
(leadORE.Phone !=System.Trigger.oldMap.get(leadORE.Id).Phone))) {
if (leadMapOREPhone.containsKey(leadORE.Phone)) {
leadORE.Email.addError('Another new lead has the same Phone Number.');
} else {
leadMapOREPhone.put(leadORE.Phone, leadORE); //add phone to phone list
}
}
if ((leadORE.Street != null) &&
(System.Trigger.isInsert ||
(leadORE.Street !=System.Trigger.oldMap.get(leadORE.Id).Street))) {
if (leadMapOREStreet.containsKey(leadORE.Street)) {
leadORE.Street.addError('Another new lead has the same Street Address.');
} else {
leadMapOREStreet.put(leadORE.Street, leadORE); //add street to street list.
}
}
}
}
//Referral Affiliate Record Type
Map<String, Lead> leadMapRA = new Map<String, Lead>(); //for email
Map<String, Lead> leadMapRAPhone = new Map<String, Lead>(); //for phone
Map<String, Lead> leadMapRAStreet = new Map<String, Lead>(); //for street
for (Lead leadRA : System.Trigger.new) {
if(leadRA.RecordTypeId=='012i0000000XXNU')
{
// check weater any new lead with same email,phone, street is being created(list uploads)
if ((leadRA.Email != null) &&
(System.Trigger.isInsert ||
(leadRA.Email !=System.Trigger.oldMap.get(leadRA.Id).Email))) {
// Make sure another new lead isn't also a duplicate
if (leadMapRA.containsKey(leadRA.Email)) {
leadRA.Email.addError('Another new lead has the same email Address.');
} else {
leadMapRA.put(leadRA.Email, leadRA); //add email to email list
}
}
if ((leadRA.Phone != null) &&
(System.Trigger.isInsert ||
(leadRA.Phone !=System.Trigger.oldMap.get(leadRA.Id).Phone))) {
if (leadMapRAPhone.containsKey(leadRA.Phone)) {
leadRA.Email.addError('Another new lead has the same Phone Number.');
} else {
leadMapRAPhone.put(leadRA.Phone, leadRA); //add phone to phone list
}
}
if ((leadRA.Street != null) &&
(System.Trigger.isInsert ||
(leadRA.Street !=System.Trigger.oldMap.get(leadRA.Id).Street))) {
if (leadMapRAStreet.containsKey(leadRA.Street)) {
leadRA.Email.addError('Another new lead has the same Street Address.');
} else {
leadMapRAStreet.put(leadRA.Street, leadRA); //add street to street list.
}
}
}
}
if(leadMapORE.size()!=0)
{
// Query for all the leads with same email address in the email list for ORE Record Type.
List<Lead> phoneore = new list<Lead>();
for (Lead lead : [SELECT Email,Name,email_notification__c, Isconverted FROM Lead WHERE Email IN :leadMapORE.KeySet()
and RecordTypeId='012i0000000VWJS' and Name!='' and Isconverted=False
and Email!='']) {
Lead newLead = leadMapORE.get(lead.Email);
if(newLead.Email != 'noemail@noemail.com')
{
if(newLead.email_notification__c == false) // check to see wheater it is through web-to-lead
{
newLead.addError(' A lead with this email already exists -' + lead.Name + '. If you do not know the Email use noemail@noemail.com');
System.debug(Logginglevel.Finest,'MsgTxt');
}
else //if lead is from web-to-lead create lead and update following fields.
{
newLead.Duplicate_lead__c = true;
newLead.Duplicate_lead_Id__c = lead.Id;
}
}
}
}
if(leadMapOREPhone.size()!=0)
{
// Query for all the leads with same email address in the email list for Referral Affiliate Record type.
for (Lead lead : [SELECT Email,Name,email_notification__c, Isconverted FROM Lead WHERE Email IN :leadMapRA.KeySet()
and RecordTypeId='012i0000000XXNU' and Name!='' and Isconverted=False
and Email!='']) {
Lead newLead = leadMapRA.get(lead.Email);
if(newLead.Email != 'noemail@noemail.com')
{
if(newLead.email_notification__c == false) // check to see wheater it is through web-to-lead
{
newLead.addError(' A lead with this email already exists -' + lead.Name + '. If you do not know the Email use noemail@noemail.com');
System.debug(Logginglevel.Finest,'MsgTxt');
}
else //if lead is from web-to-lead create lead and update following fields.
{
newLead.Duplicate_lead__c = true;
newLead.Duplicate_lead_Id__c = lead.Id;
}
}
}
}
if(leadMapOREPhone.size()!=0)
{
// Query for all the leads with same Phone in the Phone list for ORE Record Type.
for (Lead lead1 : [SELECT Email,Name,Phone,email_notification__c, Isconverted FROM Lead WHERE Phone IN :leadMapOREPhone.KeySet()
and RecordTypeId='012i0000000VWJS'and Name!='' and Isconverted=False
and Phone!='' ]) {
Lead newLead1 = leadMapOREPhone.get(lead1.Phone);
if(newLead1.Phone != '(555) 555-5555')
{
if(newLead1.email_notification__c == false ) // check to see wheater it is through web-to-lead
{
newLead1.addError(' A lead with this Phone Number already exists -'+Lead1.Name + '. If you do not know the Phone number use (555) 555-5555');
System.debug(Logginglevel.Finest,'MsgTxt');
}
else //if lead i from web-to-lead create lead and update following fields.
{
newLead1.Duplicate_lead__c = true;
newLead1.Duplicate_lead_Id__c = lead1.Id;
}
}
}
}
if(leadMapRAPhone.size()!=0)
{
// Query for all the leads with same Phone in the Phone list for Referral Affiliate Record type.
for (Lead lead1 : [SELECT Email,Name,Phone,email_notification__c, Isconverted FROM Lead WHERE Phone IN :leadMapRAPhone.KeySet()
and RecordTypeId='012i0000000XXNU' and Name!='' and Isconverted=False
and Phone!='']) {
Lead newLead1 = leadMapRAPhone.get(lead1.Phone);
if(newLead1.Phone != '(555) 555-5555')
{
if(newLead1.email_notification__c == false ) // check to see wheater it is through web-to-lead
{
newLead1.addError(' A lead with this Phone Number already exists -'+Lead1.Name + '. If you do not know the Phone number use (555) 555-5555');
System.debug(Logginglevel.Finest,'MsgTxt');
}
else //if lead i from web-to-lead create lead and update following fields.
{
newLead1.Duplicate_lead__c = true;
newLead1.Duplicate_lead_Id__c = lead1.Id;
}
}
}
}
if(leadMapOREStreet.size()!=0)
{
// Query for all the leads with same street address in the Street list for ORE Record Type.
for (Lead lead2 : [SELECT Email,Name,Phone,Street,email_notification__c, Isconverted FROM Lead WHERE Street IN :leadMapOREStreet.KeySet()
and recordtypeId= '012i0000000VWJS' and Name!='' and Isconverted=False
and Street!='']) {
Lead newLead2 = leadMapOREStreet.get(lead2.Street);
if(newLead2.email_notification__c == false) // check to see wheater it is through web-to-lead
{
newLead2.addError('A lead with this Street Address already exists.' + lead2.Name);
System.debug(Logginglevel.Finest,'MsgTxt');
}
else //if lead is from web-to-lead create lead and update following fields.
{
newLead2.Duplicate_lead__c = true;
newLead2.Duplicate_lead_Id__c = lead2.Id;
}
}
}
if(leadMapRaStreet.size()!=0)
{
// Query for all the leads with same street address in the Street list for Referral Affiliate Record type.
for (Lead lead2 : [SELECT Email,Name,Phone,Street,email_notification__c, Isconverted FROM Lead WHERE Street IN :leadMapRAStreet.KeySet()
and recordtypeId= '012i0000000XXNU' and Name!='' and Isconverted=False
and Street!='']) {
Lead newLead2 = leadMapRAStreet.get(lead2.Street);
if(newLead2.email_notification__c == false) // check to see wheater it is through web-to-lead
{
newLead2.addError('A lead with this Street Address already exists.' + lead2.Name);
System.debug(Logginglevel.Finest,'MsgTxt');
}
else //if lead is from web-to-lead create lead and update following fields.
{
newLead2.Duplicate_lead__c = true;
newLead2.Duplicate_lead_Id__c = lead2.Id;
}
}
}}
Thanks,
Vishnu
I am receiving the above arror only for phone and Street. As email Is already idexed its working fine.
How can i make Phone and Street Fields Indexed. I contactacted salesforce support and ther redirected me to post my question here.
Can someone help me out with this.
Code:
trigger leadDuplicatePreventer on Lead (before insert, before update) {
//ORE Record Type
Map<String, Lead> leadMapORE = new Map<String, Lead>(); //for email
Map<String, Lead> leadMapOREPhone = new Map<String, Lead>(); //for phone
Map<String, Lead> leadMapOREStreet = new Map<String, Lead>(); //for street
for (Lead leadORE : System.Trigger.new) {
if(leadORE.RecordTypeId=='012i0000000VWJS')
{
// check weater any new lead with same email,phone, street is being created(list uploads)
if ((leadORE.Email != null) &&
(System.Trigger.isInsert ||
(leadORE.Email !=System.Trigger.oldMap.get(leadORE.Id).Email))) {
// Make sure another new lead isn't also a duplicate
if (leadMapORE.containsKey(leadORE.Email)) {
leadORE.Email.addError('Another new lead has the same email Address.');
} else {
leadMapORE.put(leadORE.Email, leadORE); //add email to email list
}
}
if ((leadORE.Phone != null) &&
(System.Trigger.isInsert ||
(leadORE.Phone !=System.Trigger.oldMap.get(leadORE.Id).Phone))) {
if (leadMapOREPhone.containsKey(leadORE.Phone)) {
leadORE.Email.addError('Another new lead has the same Phone Number.');
} else {
leadMapOREPhone.put(leadORE.Phone, leadORE); //add phone to phone list
}
}
if ((leadORE.Street != null) &&
(System.Trigger.isInsert ||
(leadORE.Street !=System.Trigger.oldMap.get(leadORE.Id).Street))) {
if (leadMapOREStreet.containsKey(leadORE.Street)) {
leadORE.Street.addError('Another new lead has the same Street Address.');
} else {
leadMapOREStreet.put(leadORE.Street, leadORE); //add street to street list.
}
}
}
}
//Referral Affiliate Record Type
Map<String, Lead> leadMapRA = new Map<String, Lead>(); //for email
Map<String, Lead> leadMapRAPhone = new Map<String, Lead>(); //for phone
Map<String, Lead> leadMapRAStreet = new Map<String, Lead>(); //for street
for (Lead leadRA : System.Trigger.new) {
if(leadRA.RecordTypeId=='012i0000000XXNU')
{
// check weater any new lead with same email,phone, street is being created(list uploads)
if ((leadRA.Email != null) &&
(System.Trigger.isInsert ||
(leadRA.Email !=System.Trigger.oldMap.get(leadRA.Id).Email))) {
// Make sure another new lead isn't also a duplicate
if (leadMapRA.containsKey(leadRA.Email)) {
leadRA.Email.addError('Another new lead has the same email Address.');
} else {
leadMapRA.put(leadRA.Email, leadRA); //add email to email list
}
}
if ((leadRA.Phone != null) &&
(System.Trigger.isInsert ||
(leadRA.Phone !=System.Trigger.oldMap.get(leadRA.Id).Phone))) {
if (leadMapRAPhone.containsKey(leadRA.Phone)) {
leadRA.Email.addError('Another new lead has the same Phone Number.');
} else {
leadMapRAPhone.put(leadRA.Phone, leadRA); //add phone to phone list
}
}
if ((leadRA.Street != null) &&
(System.Trigger.isInsert ||
(leadRA.Street !=System.Trigger.oldMap.get(leadRA.Id).Street))) {
if (leadMapRAStreet.containsKey(leadRA.Street)) {
leadRA.Email.addError('Another new lead has the same Street Address.');
} else {
leadMapRAStreet.put(leadRA.Street, leadRA); //add street to street list.
}
}
}
}
if(leadMapORE.size()!=0)
{
// Query for all the leads with same email address in the email list for ORE Record Type.
List<Lead> phoneore = new list<Lead>();
for (Lead lead : [SELECT Email,Name,email_notification__c, Isconverted FROM Lead WHERE Email IN :leadMapORE.KeySet()
and RecordTypeId='012i0000000VWJS' and Name!='' and Isconverted=False
and Email!='']) {
Lead newLead = leadMapORE.get(lead.Email);
if(newLead.Email != 'noemail@noemail.com')
{
if(newLead.email_notification__c == false) // check to see wheater it is through web-to-lead
{
newLead.addError(' A lead with this email already exists -' + lead.Name + '. If you do not know the Email use noemail@noemail.com');
System.debug(Logginglevel.Finest,'MsgTxt');
}
else //if lead is from web-to-lead create lead and update following fields.
{
newLead.Duplicate_lead__c = true;
newLead.Duplicate_lead_Id__c = lead.Id;
}
}
}
}
if(leadMapOREPhone.size()!=0)
{
// Query for all the leads with same email address in the email list for Referral Affiliate Record type.
for (Lead lead : [SELECT Email,Name,email_notification__c, Isconverted FROM Lead WHERE Email IN :leadMapRA.KeySet()
and RecordTypeId='012i0000000XXNU' and Name!='' and Isconverted=False
and Email!='']) {
Lead newLead = leadMapRA.get(lead.Email);
if(newLead.Email != 'noemail@noemail.com')
{
if(newLead.email_notification__c == false) // check to see wheater it is through web-to-lead
{
newLead.addError(' A lead with this email already exists -' + lead.Name + '. If you do not know the Email use noemail@noemail.com');
System.debug(Logginglevel.Finest,'MsgTxt');
}
else //if lead is from web-to-lead create lead and update following fields.
{
newLead.Duplicate_lead__c = true;
newLead.Duplicate_lead_Id__c = lead.Id;
}
}
}
}
if(leadMapOREPhone.size()!=0)
{
// Query for all the leads with same Phone in the Phone list for ORE Record Type.
for (Lead lead1 : [SELECT Email,Name,Phone,email_notification__c, Isconverted FROM Lead WHERE Phone IN :leadMapOREPhone.KeySet()
and RecordTypeId='012i0000000VWJS'and Name!='' and Isconverted=False
and Phone!='' ]) {
Lead newLead1 = leadMapOREPhone.get(lead1.Phone);
if(newLead1.Phone != '(555) 555-5555')
{
if(newLead1.email_notification__c == false ) // check to see wheater it is through web-to-lead
{
newLead1.addError(' A lead with this Phone Number already exists -'+Lead1.Name + '. If you do not know the Phone number use (555) 555-5555');
System.debug(Logginglevel.Finest,'MsgTxt');
}
else //if lead i from web-to-lead create lead and update following fields.
{
newLead1.Duplicate_lead__c = true;
newLead1.Duplicate_lead_Id__c = lead1.Id;
}
}
}
}
if(leadMapRAPhone.size()!=0)
{
// Query for all the leads with same Phone in the Phone list for Referral Affiliate Record type.
for (Lead lead1 : [SELECT Email,Name,Phone,email_notification__c, Isconverted FROM Lead WHERE Phone IN :leadMapRAPhone.KeySet()
and RecordTypeId='012i0000000XXNU' and Name!='' and Isconverted=False
and Phone!='']) {
Lead newLead1 = leadMapRAPhone.get(lead1.Phone);
if(newLead1.Phone != '(555) 555-5555')
{
if(newLead1.email_notification__c == false ) // check to see wheater it is through web-to-lead
{
newLead1.addError(' A lead with this Phone Number already exists -'+Lead1.Name + '. If you do not know the Phone number use (555) 555-5555');
System.debug(Logginglevel.Finest,'MsgTxt');
}
else //if lead i from web-to-lead create lead and update following fields.
{
newLead1.Duplicate_lead__c = true;
newLead1.Duplicate_lead_Id__c = lead1.Id;
}
}
}
}
if(leadMapOREStreet.size()!=0)
{
// Query for all the leads with same street address in the Street list for ORE Record Type.
for (Lead lead2 : [SELECT Email,Name,Phone,Street,email_notification__c, Isconverted FROM Lead WHERE Street IN :leadMapOREStreet.KeySet()
and recordtypeId= '012i0000000VWJS' and Name!='' and Isconverted=False
and Street!='']) {
Lead newLead2 = leadMapOREStreet.get(lead2.Street);
if(newLead2.email_notification__c == false) // check to see wheater it is through web-to-lead
{
newLead2.addError('A lead with this Street Address already exists.' + lead2.Name);
System.debug(Logginglevel.Finest,'MsgTxt');
}
else //if lead is from web-to-lead create lead and update following fields.
{
newLead2.Duplicate_lead__c = true;
newLead2.Duplicate_lead_Id__c = lead2.Id;
}
}
}
if(leadMapRaStreet.size()!=0)
{
// Query for all the leads with same street address in the Street list for Referral Affiliate Record type.
for (Lead lead2 : [SELECT Email,Name,Phone,Street,email_notification__c, Isconverted FROM Lead WHERE Street IN :leadMapRAStreet.KeySet()
and recordtypeId= '012i0000000XXNU' and Name!='' and Isconverted=False
and Street!='']) {
Lead newLead2 = leadMapRAStreet.get(lead2.Street);
if(newLead2.email_notification__c == false) // check to see wheater it is through web-to-lead
{
newLead2.addError('A lead with this Street Address already exists.' + lead2.Name);
System.debug(Logginglevel.Finest,'MsgTxt');
}
else //if lead is from web-to-lead create lead and update following fields.
{
newLead2.Duplicate_lead__c = true;
newLead2.Duplicate_lead_Id__c = lead2.Id;
}
}
}}
Thanks,
Vishnu
- Vishnu_SFDC
- April 23, 2014
- Like
- 0
- Continue reading or reply
Error:execution of BeforeInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Thanks In Advance.
I am geting the above error for my query. i have more than 200k records in our instance.
for (Lead leadORE : System.Trigger.new) {
if(leadORE.RecordTypeId=='012i0000000VWJS')
{
if ((leadORE.Email != null) &&
(System.Trigger.isInsert ||
(leadORE.Email !=System.Trigger.oldMap.get(leadORE.Id).Email))) {
if (leadMapORE.containsKey(leadORE.Email)) {
leadORE.Email.addError('Another new lead has the same email Address.');
} else {
leadMapORE.put(leadORE.Email, leadORE); //add email to email list
}
}
if(leadMapORE.size()!=0)
{
// Query for all the leads with same email address in the email list for ORE Record Type.
List<Lead> phoneore = new list<Lead>();
for (Lead lead : [SELECT Email,Name,email_notification__c FROM Lead WHERE Email IN :leadMapORE.KeySet() and RecordTypeId='012i0000000VWJS' and Email!='' ]) {
Lead newLead = leadMapORE.get(lead.Email);
if(newLead.Email != 'noemail@noemail.com')
{
if(newLead.email_notification__c == false)
{
newLead.addError(' A lead with this email already exists -' + lead.Name + '. If you do not know the Email use noemail@noemail.com');
System.debug(Logginglevel.Finest,'MsgTxt');
}
else
{
newLead.Duplicate_lead__c = true;
newLead.Duplicate_lead_Id__c = lead.Id;
}
}
}
}
Thnaks.
I am geting the above error for my query. i have more than 200k records in our instance.
for (Lead leadORE : System.Trigger.new) {
if(leadORE.RecordTypeId=='012i0000000VWJS')
{
if ((leadORE.Email != null) &&
(System.Trigger.isInsert ||
(leadORE.Email !=System.Trigger.oldMap.get(leadORE.Id).Email))) {
if (leadMapORE.containsKey(leadORE.Email)) {
leadORE.Email.addError('Another new lead has the same email Address.');
} else {
leadMapORE.put(leadORE.Email, leadORE); //add email to email list
}
}
if(leadMapORE.size()!=0)
{
// Query for all the leads with same email address in the email list for ORE Record Type.
List<Lead> phoneore = new list<Lead>();
for (Lead lead : [SELECT Email,Name,email_notification__c FROM Lead WHERE Email IN :leadMapORE.KeySet() and RecordTypeId='012i0000000VWJS' and Email!='' ]) {
Lead newLead = leadMapORE.get(lead.Email);
if(newLead.Email != 'noemail@noemail.com')
{
if(newLead.email_notification__c == false)
{
newLead.addError(' A lead with this email already exists -' + lead.Name + '. If you do not know the Email use noemail@noemail.com');
System.debug(Logginglevel.Finest,'MsgTxt');
}
else
{
newLead.Duplicate_lead__c = true;
newLead.Duplicate_lead_Id__c = lead.Id;
}
}
}
}
Thnaks.
- Vishnu_SFDC
- April 23, 2014
- Like
- 0
- Continue reading or reply
System.LimitException: Too many SOQL queries: 101 on Trigger
trigger DEUpdateLeadOwner on Lead (before update) {
for(Lead Lead1:trigger.new)
{
if(Lead1.Is_Distributed__c==True)
{
Map<integer,String> UsersCA = new Map<integer,String>();
Map<integer,String> UsersHI = new Map<integer,String>();
Set<integer> User = new Set<integer>();
for(Lead record : trigger.new)
{
user.add(Integer.valueof(record.AssignToUserId_Hidden__c));
}
//get the users in team 1 and team2 who are in user list.
List< Team1__c> user1 = [select UserId__c,UserId_hidden__c from Team1__c where UserId__c in : user];
for(Team1__c userA : user1 )
{
UsersCA.put(Integer.valueof(userA.UserId__c),userA.UserId_hidden__c);
}
List<Team2__c> user2 = [select UserId__c,UserId_hidden__c from Team2__c where UserId__c in : user];
for(Team2__c userB : user2 )
{
UsersHI.put(Integer.valueof(userb.UserId__c),userb.UserId_hidden__c);
}
//Change lead owner for CA Leads
If(Lead1.Hawaii__c == false)
{
for(Lead le : trigger.new)
{
if(UsersCA.containsKey(Integer.valueof(le.AssignToUserId_Hidden__c)))
{
le.OwnerId=UsersCA.get(Integer.valueof(le.AssignToUserId_Hidden__c));
le.AssignToUserId_Hidden__c =null;
}
}
}
Error:
Trigger.DEUpdateLeadOwner: line 18, column 1
15:37:15.123 (3123786000)|FATAL_ERROR|System.LimitException: Too many SOQL queries: 101
Can someone help me with this.
Thanks in advance.
for(Lead Lead1:trigger.new)
{
if(Lead1.Is_Distributed__c==True)
{
Map<integer,String> UsersCA = new Map<integer,String>();
Map<integer,String> UsersHI = new Map<integer,String>();
Set<integer> User = new Set<integer>();
for(Lead record : trigger.new)
{
user.add(Integer.valueof(record.AssignToUserId_Hidden__c));
}
//get the users in team 1 and team2 who are in user list.
List< Team1__c> user1 = [select UserId__c,UserId_hidden__c from Team1__c where UserId__c in : user];
for(Team1__c userA : user1 )
{
UsersCA.put(Integer.valueof(userA.UserId__c),userA.UserId_hidden__c);
}
List<Team2__c> user2 = [select UserId__c,UserId_hidden__c from Team2__c where UserId__c in : user];
for(Team2__c userB : user2 )
{
UsersHI.put(Integer.valueof(userb.UserId__c),userb.UserId_hidden__c);
}
//Change lead owner for CA Leads
If(Lead1.Hawaii__c == false)
{
for(Lead le : trigger.new)
{
if(UsersCA.containsKey(Integer.valueof(le.AssignToUserId_Hidden__c)))
{
le.OwnerId=UsersCA.get(Integer.valueof(le.AssignToUserId_Hidden__c));
le.AssignToUserId_Hidden__c =null;
}
}
}
Error:
Trigger.DEUpdateLeadOwner: line 18, column 1
15:37:15.123 (3123786000)|FATAL_ERROR|System.LimitException: Too many SOQL queries: 101
Can someone help me with this.
Thanks in advance.
- Vishnu_SFDC
- March 20, 2014
- Like
- 0
- Continue reading or reply
Error on save button in Visulforce page
ERROR: Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:commandButton> in page installer_view
My Visualforce page:
<apex:page standardController="Installers__c" showHeader="true" tabStyle="Installers__c" extensions="MultiAttachmentController">
<apex:sectionHeader subtitle="{!Installers__c.Name}" title="Installer"/>
<chatter:feedWithFollowers entityId="{!Installers__c.id}"/>
<br>
</br>
<apex:form >
<apex:actionRegion >
<apex:pageblock title="Installer Detail" mode="mainDetail">
<apex:pageBlockButtons >
<apex:commandButton value="Edit" action="{!Edit}" style="display: inline;" />
<apex:commandButton value="Delete" action="{!Delete}" />
<apex:commandButton action="{!URLFOR($Action.Installers__c.Upload_Documents,Installers__c.Id)}" value="Upload Documents"/>
<apex:commandButton Action="{!save}" id="saveButton" value="Save" />
<apex:commandButton Action="{!Cancel}" id="cancelButton" value="Cancel" style="display: None;" />
........
My Component
<apex:component controller="MultiAttachmentController" allowDML="true">
<apex:attribute name="objId" type="String" description="The id of the object to manage attachments for" required="true" assignTo="{!sobjId}"/>
<apex:form id="attForm">
<apex:pageBlock title="Upload Attachments">
<apex:repeat value="{!newAttachments}" var="newAtt">
<apex:pageBlockSection columns="3">
<apex:outputLabel value="Title">
<apex:selectList id="Title" value="{!Title}" size="1">
.......................
My Controller
public with sharing class MultiAttachmentController
{
public String delet { get; set; }
id token = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');
Id attId = System.currentPageReference().getParameters().get('id');
public MultiAttachmentController(ApexPages.StandardController stdcontroller2) {
}
// the parent object it
public Id sobjId {get; set;}
// list of existing attachments - populated on demand
public List<Attachment> attachments ;
public List<Note> Notes ;
//list of picklist values
public String Title {get; set;}
// list of new attachments to add
public List<Attachment> newAttachments {get; set;}
// the number of new attachments to add to the list when the user clicks 'Add More'
public static final Integer NUM_ATTACHMENTS_TO_ADD=5;
// constructor
public MultiAttachmentController()
{
// instantiate the list with a single attachment
newAttachments=new List<Attachment>{new Attachment()};
}
....................
I get this error in only View mode(Inline Editing). When i am in Edit mode i dont get this error.
Error is in expression '{!save}' in component <apex:commandButton> in page installer_view
My Visualforce page:
<apex:page standardController="Installers__c" showHeader="true" tabStyle="Installers__c" extensions="MultiAttachmentController">
<apex:sectionHeader subtitle="{!Installers__c.Name}" title="Installer"/>
<chatter:feedWithFollowers entityId="{!Installers__c.id}"/>
<br>
</br>
<apex:form >
<apex:actionRegion >
<apex:pageblock title="Installer Detail" mode="mainDetail">
<apex:pageBlockButtons >
<apex:commandButton value="Edit" action="{!Edit}" style="display: inline;" />
<apex:commandButton value="Delete" action="{!Delete}" />
<apex:commandButton action="{!URLFOR($Action.Installers__c.Upload_Documents,Installers__c.Id)}" value="Upload Documents"/>
<apex:commandButton Action="{!save}" id="saveButton" value="Save" />
<apex:commandButton Action="{!Cancel}" id="cancelButton" value="Cancel" style="display: None;" />
........
My Component
<apex:component controller="MultiAttachmentController" allowDML="true">
<apex:attribute name="objId" type="String" description="The id of the object to manage attachments for" required="true" assignTo="{!sobjId}"/>
<apex:form id="attForm">
<apex:pageBlock title="Upload Attachments">
<apex:repeat value="{!newAttachments}" var="newAtt">
<apex:pageBlockSection columns="3">
<apex:outputLabel value="Title">
<apex:selectList id="Title" value="{!Title}" size="1">
.......................
My Controller
public with sharing class MultiAttachmentController
{
public String delet { get; set; }
id token = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');
Id attId = System.currentPageReference().getParameters().get('id');
public MultiAttachmentController(ApexPages.StandardController stdcontroller2) {
}
// the parent object it
public Id sobjId {get; set;}
// list of existing attachments - populated on demand
public List<Attachment> attachments ;
public List<Note> Notes ;
//list of picklist values
public String Title {get; set;}
// list of new attachments to add
public List<Attachment> newAttachments {get; set;}
// the number of new attachments to add to the list when the user clicks 'Add More'
public static final Integer NUM_ATTACHMENTS_TO_ADD=5;
// constructor
public MultiAttachmentController()
{
// instantiate the list with a single attachment
newAttachments=new List<Attachment>{new Attachment()};
}
....................
I get this error in only View mode(Inline Editing). When i am in Edit mode i dont get this error.
- Vishnu_SFDC
- March 20, 2014
- Like
- 0
- Continue reading or reply
Error for save botton in visualforce page
ERROR: Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:commandButton> in page installer_view
My Visualforce page:
<apex:page standardController="Installers__c" showHeader="true" tabStyle="Installers__c" extensions="MultiAttachmentController">
<apex:sectionHeader subtitle="{!Installers__c.Name}" title="Installer"/>
<chatter:feedWithFollowers entityId="{!Installers__c.id}"/>
<br>
</br>
<apex:form >
<apex:actionRegion >
<apex:pageblock title="Installer Detail" mode="mainDetail">
<apex:pageBlockButtons >
<apex:commandButton value="Edit" action="{!Edit}" style="display: inline;" />
<apex:commandButton value="Delete" action="{!Delete}" />
<apex:commandButton action="{!URLFOR($Action.Installers__c.Upload_Documents,Installers__c.Id)}" value="Upload Documents"/>
<apex:commandButton Action="{!save}" id="saveButton" value="Save" />
<apex:commandButton Action="{!Cancel}" id="cancelButton" value="Cancel" style="display: None;" />
........
My Component
<apex:component controller="MultiAttachmentController" allowDML="true">
<apex:attribute name="objId" type="String" description="The id of the object to manage attachments for" required="true" assignTo="{!sobjId}"/>
<apex:form id="attForm">
<apex:pageBlock title="Upload Attachments">
<apex:repeat value="{!newAttachments}" var="newAtt">
<apex:pageBlockSection columns="3">
<apex:outputLabel value="Title">
<apex:selectList id="Title" value="{!Title}" size="1">
.......................
My Controller
public with sharing class MultiAttachmentController
{
public String delet { get; set; }
id token = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');
Id attId = System.currentPageReference().getParameters().get('id');
public MultiAttachmentController(ApexPages.StandardController stdcontroller2) {
}
// the parent object it
public Id sobjId {get; set;}
// list of existing attachments - populated on demand
public List<Attachment> attachments ;
public List<Note> Notes ;
//list of picklist values
public String Title {get; set;}
// list of new attachments to add
public List<Attachment> newAttachments {get; set;}
// the number of new attachments to add to the list when the user clicks 'Add More'
public static final Integer NUM_ATTACHMENTS_TO_ADD=5;
// constructor
public MultiAttachmentController()
{
// instantiate the list with a single attachment
newAttachments=new List<Attachment>{new Attachment()};
}
....................
I get this error in only View mode(Inline Editing). When i am in Edit mode i dont get this error.
Error is in expression '{!save}' in component <apex:commandButton> in page installer_view
My Visualforce page:
<apex:page standardController="Installers__c" showHeader="true" tabStyle="Installers__c" extensions="MultiAttachmentController">
<apex:sectionHeader subtitle="{!Installers__c.Name}" title="Installer"/>
<chatter:feedWithFollowers entityId="{!Installers__c.id}"/>
<br>
</br>
<apex:form >
<apex:actionRegion >
<apex:pageblock title="Installer Detail" mode="mainDetail">
<apex:pageBlockButtons >
<apex:commandButton value="Edit" action="{!Edit}" style="display: inline;" />
<apex:commandButton value="Delete" action="{!Delete}" />
<apex:commandButton action="{!URLFOR($Action.Installers__c.Upload_Documents,Installers__c.Id)}" value="Upload Documents"/>
<apex:commandButton Action="{!save}" id="saveButton" value="Save" />
<apex:commandButton Action="{!Cancel}" id="cancelButton" value="Cancel" style="display: None;" />
........
My Component
<apex:component controller="MultiAttachmentController" allowDML="true">
<apex:attribute name="objId" type="String" description="The id of the object to manage attachments for" required="true" assignTo="{!sobjId}"/>
<apex:form id="attForm">
<apex:pageBlock title="Upload Attachments">
<apex:repeat value="{!newAttachments}" var="newAtt">
<apex:pageBlockSection columns="3">
<apex:outputLabel value="Title">
<apex:selectList id="Title" value="{!Title}" size="1">
.......................
My Controller
public with sharing class MultiAttachmentController
{
public String delet { get; set; }
id token = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');
Id attId = System.currentPageReference().getParameters().get('id');
public MultiAttachmentController(ApexPages.StandardController stdcontroller2) {
}
// the parent object it
public Id sobjId {get; set;}
// list of existing attachments - populated on demand
public List<Attachment> attachments ;
public List<Note> Notes ;
//list of picklist values
public String Title {get; set;}
// list of new attachments to add
public List<Attachment> newAttachments {get; set;}
// the number of new attachments to add to the list when the user clicks 'Add More'
public static final Integer NUM_ATTACHMENTS_TO_ADD=5;
// constructor
public MultiAttachmentController()
{
// instantiate the list with a single attachment
newAttachments=new List<Attachment>{new Attachment()};
}
....................
I get this error in only View mode(Inline Editing). When i am in Edit mode i dont get this error.
- Vishnu_SFDC
- March 19, 2014
- Like
- 0
- Continue reading or reply
External Entry Point Exception for my batch class
My test class for Batch apex is throwing error when its frocessing more than 1 record. When i set the limit as 1 it works fine. When i increase the limit I get External Entry Point Exception.
<----------Batch Class------------>
global class DEUserCheckOut implements Database.Batchable<sObject>,Database.AllowsCallouts,Database.stateful {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id,Calls_Logged_Today__c,profileId,Check_In__c,Qualification__c,Call_Logged__c From User Where Check_In__c = true Limit 2 ';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<User> scope) {
for(User e : scope){
{
e.Check_In__C = False;
e.Calls_Logged_Today__c = 0;
Update Scope;
}
}
}
global void finish(Database.BatchableContext BC) { }
}
<-------------Test Class-------------->
@istest(SeeAllData=False)
public class TestDEUserCheckOut{
Static testmethod void TestDEUserCheckOut()
{
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
UserRole teleRole = [SELECT Id FROM UserRole WHERE Name='Qualifier' LIMIT 1];
User brian = new User(Alias = 'standt', Email='standarduser@testorg.com',
EmailEncodingKey='UTF-8', FirstName='Brian', LastName='Mulhair', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = '00ei0000000iZri', UserRoleId = teleRole.Id,
TimeZoneSidKey='America/Los_Angeles',IsActive=true,Check_In__c = True, UserName='unique@user.name12345');
insert brian;
Test.startTest();
Database.executeBatch(new DEUserCheckOut(),1);
Test.stopTest();
}
}
Thanks In Advance.
<----------Batch Class------------>
global class DEUserCheckOut implements Database.Batchable<sObject>,Database.AllowsCallouts,Database.stateful {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id,Calls_Logged_Today__c,profileId,Check_In__c,Qualification__c,Call_Logged__c From User Where Check_In__c = true Limit 2 ';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<User> scope) {
for(User e : scope){
{
e.Check_In__C = False;
e.Calls_Logged_Today__c = 0;
Update Scope;
}
}
}
global void finish(Database.BatchableContext BC) { }
}
<-------------Test Class-------------->
@istest(SeeAllData=False)
public class TestDEUserCheckOut{
Static testmethod void TestDEUserCheckOut()
{
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
UserRole teleRole = [SELECT Id FROM UserRole WHERE Name='Qualifier' LIMIT 1];
User brian = new User(Alias = 'standt', Email='standarduser@testorg.com',
EmailEncodingKey='UTF-8', FirstName='Brian', LastName='Mulhair', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = '00ei0000000iZri', UserRoleId = teleRole.Id,
TimeZoneSidKey='America/Los_Angeles',IsActive=true,Check_In__c = True, UserName='unique@user.name12345');
insert brian;
Test.startTest();
Database.executeBatch(new DEUserCheckOut(),1);
Test.stopTest();
}
}
Thanks In Advance.
- Vishnu_SFDC
- February 19, 2014
- Like
- 0
- Continue reading or reply
Too many soql error :101 on different trigger when executing a apex class
I am trying to execute the following class from a button. when i set the limit to 9 it wors fine. When i remove limit on the 1st query it throws error on other triggers.
global class DERedistribute{
@future
webservice static void DERedistribute(){
List<Lead> l = [SELECT Name,Times_The_Lead_Is_Distributed__c,Hawaii__c,SV_Priority_Hidden__c, Id, AssignToUserId_Hidden__c FROM Lead WHERE IsConverted =false and Hawaii__c = false and To_Be_Distributed__c=true and DE_Synched__c=true and Is_Distributed__c =True];
integer x=0;
List<Team1__c> L1 = [SELECT Name,CheckIn__c From Team1__c Where CheckIn__c = True];
integer i = L1.size();
integer z=1;
for(Team1__c L2 :[SELECT Name,CheckIn__c,UserId__c From Team1__c] )
{
If(L2.CheckIn__c == True)
{
L2.UserId__c = z++;
}
else
{
L2.UserId__c =0;
}
update L2;
}
for(Lead e : l)
{
x++;
decimal y = e.Times_The_Lead_Is_Distributed__c;
e.AssignToUserId_Hidden__c = math.MOD(x, i) + 1;
e.Is_Distributed__c =True;
e.Times_The_Lead_Is_Distributed__c = y +1;
update e;
}
}
}
global class DERedistribute{
@future
webservice static void DERedistribute(){
List<Lead> l = [SELECT Name,Times_The_Lead_Is_Distributed__c,Hawaii__c,SV_Priority_Hidden__c, Id, AssignToUserId_Hidden__c FROM Lead WHERE IsConverted =false and Hawaii__c = false and To_Be_Distributed__c=true and DE_Synched__c=true and Is_Distributed__c =True];
integer x=0;
List<Team1__c> L1 = [SELECT Name,CheckIn__c From Team1__c Where CheckIn__c = True];
integer i = L1.size();
integer z=1;
for(Team1__c L2 :[SELECT Name,CheckIn__c,UserId__c From Team1__c] )
{
If(L2.CheckIn__c == True)
{
L2.UserId__c = z++;
}
else
{
L2.UserId__c =0;
}
update L2;
}
for(Lead e : l)
{
x++;
decimal y = e.Times_The_Lead_Is_Distributed__c;
e.AssignToUserId_Hidden__c = math.MOD(x, i) + 1;
e.Is_Distributed__c =True;
e.Times_The_Lead_Is_Distributed__c = y +1;
update e;
}
}
}
- Vishnu_SFDC
- February 08, 2014
- Like
- 0
- Continue reading or reply
Error for a long text Field In javscript when trying to merge fields
Here is the code i am using.
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var c = new sforce.SObject("Lead");
c.id = "{!Lead.Id}";
c.Contact_Attempt__c = 'True';
var discription = prompt("Call Discription", "");
var notes = "{!Lead.Discussion_Notes__c}";
var note = notes + "\r" + "{!User.Alias}" + "--" + discription + "--" + "{!NOW()}" ;
c.Discussion_Notes__c = note;
result = sforce.connection.update([c]);
window.location.reload();
Discussion_notes__c is the long text area i am using.. Its working for 1st two times. After it creates two lines it gives me a error saying "A problem with the OnClick JavaScript for this button or link was encountered:unterminated string literal"
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var c = new sforce.SObject("Lead");
c.id = "{!Lead.Id}";
c.Contact_Attempt__c = 'True';
var discription = prompt("Call Discription", "");
var notes = "{!Lead.Discussion_Notes__c}";
var note = notes + "\r" + "{!User.Alias}" + "--" + discription + "--" + "{!NOW()}" ;
c.Discussion_Notes__c = note;
result = sforce.connection.update([c]);
window.location.reload();
Discussion_notes__c is the long text area i am using.. Its working for 1st two times. After it creates two lines it gives me a error saying "A problem with the OnClick JavaScript for this button or link was encountered:unterminated string literal"
- Vishnu_SFDC
- January 31, 2014
- Like
- 1
- Continue reading or reply
Error for a long text Field In javscript when trying to merge fields
Here is the code i am using.
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var c = new sforce.SObject("Lead");
c.id = "{!Lead.Id}";
c.Contact_Attempt__c = 'True';
var discription = prompt("Call Discription", "");
var notes = "{!Lead.Discussion_Notes__c}";
var note = notes + "\r" + "{!User.Alias}" + "--" + discription + "--" + "{!NOW()}" ;
c.Discussion_Notes__c = note;
result = sforce.connection.update([c]);
window.location.reload();
Discussion_notes__c is the long text area i am using.. Its working for 1st two times. After it creates two lines it gives me a error saying "A problem with the OnClick JavaScript for this button or link was encountered:unterminated string literal"
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var c = new sforce.SObject("Lead");
c.id = "{!Lead.Id}";
c.Contact_Attempt__c = 'True';
var discription = prompt("Call Discription", "");
var notes = "{!Lead.Discussion_Notes__c}";
var note = notes + "\r" + "{!User.Alias}" + "--" + discription + "--" + "{!NOW()}" ;
c.Discussion_Notes__c = note;
result = sforce.connection.update([c]);
window.location.reload();
Discussion_notes__c is the long text area i am using.. Its working for 1st two times. After it creates two lines it gives me a error saying "A problem with the OnClick JavaScript for this button or link was encountered:unterminated string literal"
- Vishnu_SFDC
- January 31, 2014
- Like
- 1
- Continue reading or reply
How can I trigger an event date to auto populate an oppportunity custom field?
I am new to Apex Coding / Triggers and I am stuck. I'm trying to create a trigger where when an event is created with a specific subject line, it automatically populates an "Appointment Date" custom field on the Opportunity object. Where do I begin? Thank you!
- Nicholas Melonas
- October 08, 2014
- Like
- 0
- Continue reading or reply
I'd like to create a validation rule that pulls from a related list to stop or allow stage progression. Possible?
We would like to limit our users from proceeding to a certain stage if no products have been selected on an opportunity. RIght now, it doesn't appear there is a way. But it's important that products be mandated and fear they won't be used if there's no trigger to ensure they're selected. Is there a way around validation rule limitations that only work on object fields?
- Be'Anka Ashaolu
- October 07, 2014
- Like
- 0
- Continue reading or reply
Cross object field update trigger
Hi - I do not have much Apex experience so please forgive me in advance.
I would like to have a cross object field update for 2 custom objects. I have a custom object called "Fund" which has a field called "service end date". Now i have another object called "Class" which is related to the Fund object. (You cannot have a class with out having a Fund"). What I would like to do is when a service end date is filled out at the fund level that it automatically updates the class end date.
Is this possible? Please let me know if I need to provide more information.
Thank you so much in advance!
I would like to have a cross object field update for 2 custom objects. I have a custom object called "Fund" which has a field called "service end date". Now i have another object called "Class" which is related to the Fund object. (You cannot have a class with out having a Fund"). What I would like to do is when a service end date is filled out at the fund level that it automatically updates the class end date.
Is this possible? Please let me know if I need to provide more information.
Thank you so much in advance!
- Jessica Pastor
- October 07, 2014
- Like
- 0
- Continue reading or reply
List Index out of bounds Error
Hello ,
Below is the code for which i am getting the error.
but i get List index out of bounds: 263 error.
can someone help me out with this.
Thanks,
Vishnu
Below is the code for which i am getting the error.
system.debug(slots.size()); for(Integer i =slots.size()-1;i>=0; i--) { system.debug(slots[i]); date d = Date.newinstance((slots[i].StartDateTime).year(),(slots[i].StartDateTime).month(),(slots[i].StartDateTime).day()); for (event__c e : event) { system.debug(e); system.debug(today2); //date d2 = Date.newinstance((e.Start_Datetime__c).year(),(e.Start_Datetime__c).month(),(e.Start_Datetime__c).day()); if(((slots[i].startDateTime<e.Start_Datetime__c && slots[i].StartDateTime.addminutes(apptmin)<e.Start_Datetime__c) || (slots[i].startDateTime>e.End_Datetime__c && slots[i].startDateTime.addminutes(apptmin)>e.End_Datetime__c)) && (e.Start_Datetime__c <=today2.addDays(6) && e.Start_DateTime__c >= today2.addDays(-1))) { } else { if(slots[i].userid == e.Event_Owner__c) { slots.remove(i); } } } }When i debug the size i get size = 264.
but i get List index out of bounds: 263 error.
can someone help me out with this.
Thanks,
Vishnu
- Vishnu_SFDC
- July 02, 2014
- Like
- 0
- Continue reading or reply
Passing value from visualforce Radio Button to Controller
Hi Everyone,
Below is my visualforce page.
<apex:column headerValue="Select" >
<apex:actionsupport event="onclick" >
<input type="radio" />
<apex:param name="RepId" value="{!Item.id}">
</apex:param></apex:actionsupport>
</apex:column>
<apex:column headervalue="Name">
<apex:outputfield style="width:2500px" value="{!Item.User__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Start DateTime">
<apex:outputfield value="{!Item.Start_DateTime__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="End DateTime">
<apex:outputfield value="{!Item.End_DateTime__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Approximate Distance To Appointment">
<apex:outputfield value="{!Item.Distance__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Number of events">
<apex:outputfield value="{!Item.Number_of_Events__c}">
How can i pass the value of of that row to the controller class.
Thanks in advance.
Below is my visualforce page.
<apex:column headerValue="Select" >
<apex:actionsupport event="onclick" >
<input type="radio" />
<apex:param name="RepId" value="{!Item.id}">
</apex:param></apex:actionsupport>
</apex:column>
<apex:column headervalue="Name">
<apex:outputfield style="width:2500px" value="{!Item.User__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Start DateTime">
<apex:outputfield value="{!Item.Start_DateTime__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="End DateTime">
<apex:outputfield value="{!Item.End_DateTime__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Approximate Distance To Appointment">
<apex:outputfield value="{!Item.Distance__c}">
</apex:outputfield></apex:column>
<apex:column headervalue="Number of events">
<apex:outputfield value="{!Item.Number_of_Events__c}">
How can i pass the value of of that row to the controller class.
Thanks in advance.
- Vishnu_SFDC
- June 06, 2014
- Like
- 0
- Continue reading or reply
batch apex class to find the current class
Hi
I have Active__C field and Expiration_Date__c field. If the active__c Flag is true, then the Expiration_Date__c must be greaterthan current date.
I need to write Batch apex class for this requirement.This Batch apex class runs on thousands of records.
Please help me any one know how to write code for this.
Thanks
Babu
I have Active__C field and Expiration_Date__c field. If the active__c Flag is true, then the Expiration_Date__c must be greaterthan current date.
I need to write Batch apex class for this requirement.This Batch apex class runs on thousands of records.
Please help me any one know how to write code for this.
Thanks
Babu
- S Babu.ax1883
- June 04, 2014
- Like
- 0
- Continue reading or reply
Can you create a custom button with javascript that is able to change the label of the button?
Hey,
I'm in the process of developing a custom button on Salesforce that is able to toggle a checkbox on and off.
At this point, I am using the Salesforce AJAX Toolkit in order to do the main backend functions of the custom button.
I have the backend working, but I was hoping I could have the custom button label toggle between "Start Process" and "End Process".
To do this, I assume I would need the custom button to change it's own label.
I attempted this by placing these lines in my code:
It's also entirely possible that I cannot change the name of the button with the AJAX Toolkit.
I am very new to Salesforce and learning about this tool, so any ideas or suggestions will be greatly appreciated!
Thanks,
TF
I'm in the process of developing a custom button on Salesforce that is able to toggle a checkbox on and off.
At this point, I am using the Salesforce AJAX Toolkit in order to do the main backend functions of the custom button.
I have the backend working, but I was hoping I could have the custom button label toggle between "Start Process" and "End Process".
To do this, I assume I would need the custom button to change it's own label.
I attempted this by placing these lines in my code:
var toggleButton = new sforce.SObject("Lead"); var toggleButtonT ="{!Lead.Begin_Touch_Process}"; //my attempt to reference the button toggleButtonT.Id = "00bc0000000QoaE"; // my attempt to reference the button id toggleButtonT.Label = "test"; // entering new value for the button label result = sforce.connection.update([toggleButton]); // updating the buttonNOTE: {!RequireScript} is already mentioned in script.
It's also entirely possible that I cannot change the name of the button with the AJAX Toolkit.
I am very new to Salesforce and learning about this tool, so any ideas or suggestions will be greatly appreciated!
Thanks,
TF
- Thomas Fuller
- June 03, 2014
- Like
- 0
- Continue reading or reply
Error on save button in Visulforce page
ERROR: Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:commandButton> in page installer_view
My Visualforce page:
<apex:page standardController="Installers__c" showHeader="true" tabStyle="Installers__c" extensions="MultiAttachmentController">
<apex:sectionHeader subtitle="{!Installers__c.Name}" title="Installer"/>
<chatter:feedWithFollowers entityId="{!Installers__c.id}"/>
<br>
</br>
<apex:form >
<apex:actionRegion >
<apex:pageblock title="Installer Detail" mode="mainDetail">
<apex:pageBlockButtons >
<apex:commandButton value="Edit" action="{!Edit}" style="display: inline;" />
<apex:commandButton value="Delete" action="{!Delete}" />
<apex:commandButton action="{!URLFOR($Action.Installers__c.Upload_Documents,Installers__c.Id)}" value="Upload Documents"/>
<apex:commandButton Action="{!save}" id="saveButton" value="Save" />
<apex:commandButton Action="{!Cancel}" id="cancelButton" value="Cancel" style="display: None;" />
........
My Component
<apex:component controller="MultiAttachmentController" allowDML="true">
<apex:attribute name="objId" type="String" description="The id of the object to manage attachments for" required="true" assignTo="{!sobjId}"/>
<apex:form id="attForm">
<apex:pageBlock title="Upload Attachments">
<apex:repeat value="{!newAttachments}" var="newAtt">
<apex:pageBlockSection columns="3">
<apex:outputLabel value="Title">
<apex:selectList id="Title" value="{!Title}" size="1">
.......................
My Controller
public with sharing class MultiAttachmentController
{
public String delet { get; set; }
id token = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');
Id attId = System.currentPageReference().getParameters().get('id');
public MultiAttachmentController(ApexPages.StandardController stdcontroller2) {
}
// the parent object it
public Id sobjId {get; set;}
// list of existing attachments - populated on demand
public List<Attachment> attachments ;
public List<Note> Notes ;
//list of picklist values
public String Title {get; set;}
// list of new attachments to add
public List<Attachment> newAttachments {get; set;}
// the number of new attachments to add to the list when the user clicks 'Add More'
public static final Integer NUM_ATTACHMENTS_TO_ADD=5;
// constructor
public MultiAttachmentController()
{
// instantiate the list with a single attachment
newAttachments=new List<Attachment>{new Attachment()};
}
....................
I get this error in only View mode(Inline Editing). When i am in Edit mode i dont get this error.
Error is in expression '{!save}' in component <apex:commandButton> in page installer_view
My Visualforce page:
<apex:page standardController="Installers__c" showHeader="true" tabStyle="Installers__c" extensions="MultiAttachmentController">
<apex:sectionHeader subtitle="{!Installers__c.Name}" title="Installer"/>
<chatter:feedWithFollowers entityId="{!Installers__c.id}"/>
<br>
</br>
<apex:form >
<apex:actionRegion >
<apex:pageblock title="Installer Detail" mode="mainDetail">
<apex:pageBlockButtons >
<apex:commandButton value="Edit" action="{!Edit}" style="display: inline;" />
<apex:commandButton value="Delete" action="{!Delete}" />
<apex:commandButton action="{!URLFOR($Action.Installers__c.Upload_Documents,Installers__c.Id)}" value="Upload Documents"/>
<apex:commandButton Action="{!save}" id="saveButton" value="Save" />
<apex:commandButton Action="{!Cancel}" id="cancelButton" value="Cancel" style="display: None;" />
........
My Component
<apex:component controller="MultiAttachmentController" allowDML="true">
<apex:attribute name="objId" type="String" description="The id of the object to manage attachments for" required="true" assignTo="{!sobjId}"/>
<apex:form id="attForm">
<apex:pageBlock title="Upload Attachments">
<apex:repeat value="{!newAttachments}" var="newAtt">
<apex:pageBlockSection columns="3">
<apex:outputLabel value="Title">
<apex:selectList id="Title" value="{!Title}" size="1">
.......................
My Controller
public with sharing class MultiAttachmentController
{
public String delet { get; set; }
id token = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');
Id attId = System.currentPageReference().getParameters().get('id');
public MultiAttachmentController(ApexPages.StandardController stdcontroller2) {
}
// the parent object it
public Id sobjId {get; set;}
// list of existing attachments - populated on demand
public List<Attachment> attachments ;
public List<Note> Notes ;
//list of picklist values
public String Title {get; set;}
// list of new attachments to add
public List<Attachment> newAttachments {get; set;}
// the number of new attachments to add to the list when the user clicks 'Add More'
public static final Integer NUM_ATTACHMENTS_TO_ADD=5;
// constructor
public MultiAttachmentController()
{
// instantiate the list with a single attachment
newAttachments=new List<Attachment>{new Attachment()};
}
....................
I get this error in only View mode(Inline Editing). When i am in Edit mode i dont get this error.
- Vishnu_SFDC
- March 20, 2014
- Like
- 0
- Continue reading or reply
Too many soql error :101 on different trigger when executing a apex class
I am trying to execute the following class from a button. when i set the limit to 9 it wors fine. When i remove limit on the 1st query it throws error on other triggers.
global class DERedistribute{
@future
webservice static void DERedistribute(){
List<Lead> l = [SELECT Name,Times_The_Lead_Is_Distributed__c,Hawaii__c,SV_Priority_Hidden__c, Id, AssignToUserId_Hidden__c FROM Lead WHERE IsConverted =false and Hawaii__c = false and To_Be_Distributed__c=true and DE_Synched__c=true and Is_Distributed__c =True];
integer x=0;
List<Team1__c> L1 = [SELECT Name,CheckIn__c From Team1__c Where CheckIn__c = True];
integer i = L1.size();
integer z=1;
for(Team1__c L2 :[SELECT Name,CheckIn__c,UserId__c From Team1__c] )
{
If(L2.CheckIn__c == True)
{
L2.UserId__c = z++;
}
else
{
L2.UserId__c =0;
}
update L2;
}
for(Lead e : l)
{
x++;
decimal y = e.Times_The_Lead_Is_Distributed__c;
e.AssignToUserId_Hidden__c = math.MOD(x, i) + 1;
e.Is_Distributed__c =True;
e.Times_The_Lead_Is_Distributed__c = y +1;
update e;
}
}
}
global class DERedistribute{
@future
webservice static void DERedistribute(){
List<Lead> l = [SELECT Name,Times_The_Lead_Is_Distributed__c,Hawaii__c,SV_Priority_Hidden__c, Id, AssignToUserId_Hidden__c FROM Lead WHERE IsConverted =false and Hawaii__c = false and To_Be_Distributed__c=true and DE_Synched__c=true and Is_Distributed__c =True];
integer x=0;
List<Team1__c> L1 = [SELECT Name,CheckIn__c From Team1__c Where CheckIn__c = True];
integer i = L1.size();
integer z=1;
for(Team1__c L2 :[SELECT Name,CheckIn__c,UserId__c From Team1__c] )
{
If(L2.CheckIn__c == True)
{
L2.UserId__c = z++;
}
else
{
L2.UserId__c =0;
}
update L2;
}
for(Lead e : l)
{
x++;
decimal y = e.Times_The_Lead_Is_Distributed__c;
e.AssignToUserId_Hidden__c = math.MOD(x, i) + 1;
e.Is_Distributed__c =True;
e.Times_The_Lead_Is_Distributed__c = y +1;
update e;
}
}
}
- Vishnu_SFDC
- February 08, 2014
- Like
- 0
- Continue reading or reply
"insufficient access rights on cross-reference id" in lead sharing
Hi,
I am getting the above error when I am sharing a lead through apex.
Scenario: I am creating a lead by logging in as Partner User. When the assignment rule checkbox is checked the created lead get assigned to another user. I wanted to share that lead with the created user ID(Partner user). For this purpose, I wrote trigger. When the trigger get fired it is throwing the above exception.
How can I resolve it??
Thanks in advance!!
- hch
- February 23, 2012
- Like
- 0
- Continue reading or reply