• PXForce
  • NEWBIE
  • 25 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 9
    Replies

Hi, 

 

I am having trouble getting this query working in a batchable class. 

 

In my start method when I use the following query : 

 

 

String query = 'Select a.Id, a.Name, a.OwnerId ,(Select Id, OwnerId From Contacts) from Account a Where a.Type IN: '+ accTypesToInclude ;
 return Database.getQueryLocator(query);

 

 

I am getting the error :

 

System.QueryException: unexpected token: '(' 

 

Any ideas whats wrong

 

Thanks

I am having an trouble with redirecting the user to the right URL (page) based on different actions. It seems that the returnURL is different for different actions. Heres my problem:

 

When I create new task on Contact /Account and then Save it  , it returns me to the Contact/Account page

Also 

If I click on Edit in the Edit/Del link under Open Activities on the Contact/Account page , it again returns me to the Contact/Account page.

BUT

When I click on a task in the Open Activity section and then click on edit and then save it , it returns me to the task page (in read mode) - THATS WHAT I WANT

 

What I want is to return to the task page (read mode) even when i create a new task or edit the task using the edit link.I am stuck with this and any help would be really appreciated. 

 

 

 

Hi,

 

I have hit yet another roadblock while developing an app in flex thats calling a webservice method in my apex class.

 

In my webservice method I am 

- getting unique ids for contacts. and

- based on those ids getting contacts and accounts and opps

 

I am hitting the limit for too many script statements executed and over here my date params are just for 3 months.

Is there a way to overcome this limit or can this be further refactored (if possible - just point me in the right direction) or if theres another alternative way to appraoch this.

 

Any help would be greatly appreciated

 

 

heres my code for the webservice method :

 

Webservice static List<GenericObject> getConAccOpps(String startDateString , String startMonthString , String startYearString,
															String endDateString , String endMonthString , String endYearString , String scoreThreshold)
	{
		List<GenericObject> result = new List<GenericObject>();
		
		setDates(startDateString , startMonthString , startYearString,
				endDateString , endMonthString , endYearString);
				
		//List<Key_Event__c> conKEs = new List<Key_Event__c>();
					
		List<String> contactIds = getUniqueContactIds();	
		
		List<String> accountIds = new List<String>();
		
		Map<String , Account> accMap = new Map<String , Account>();
		
		For(Contact con : [Select c.Appt_Scheduled_Date__c, c.OwnerId,c.AccountId, c.Email, c.Phone, c.HasOptedOutOfEmail, c.Account.Name, c.Contact_Status__c,c.Title_type__c , c.Id, c.Key_Events_Total_Score__c,c.Title, c.MailingPostalCode, 
						 c.Webinar_Date__c, c.Account.Annual_Revenue_Range__c, c.Webinar_Status__c ,c.Account.Type,c.MailingState, c.Name from Contact c Where c.Id IN : contactIds And c.Key_Events_Total_Score__c >=: Integer.valueOf(scoreThreshold) Order by Contact_Status__c])
						 
		{
			if(accMap.get(con.AccountId) == null)
			{
				accMap.put(con.AccountId, con.Account);
				accountIds.add(con.AccountId);
			}
			
			result.add(new GenericObject(con,null,null));
		}
		
		System.debug('DML statements ' + Limits.getDmlStatements());
		
		if(accountIds.size() > 0)
		{
			System.debug('num of acc ids :' + accountIds.size());
			For(Account acc : [Select a.OwnerId,a.Owner.Name, a.Second_Account_Owner__c, a.Second_Account_Owner__r.Name, a.Id, a.Annual_Revenue_Range__c,a.Key_Event_Score__c,a.BillingPostalCode, a.BillingState, a.Industry, a.Name, a.Type, 
							(Select AccountId, CreatedDate, Field, NewValue, OldValue From Histories Where CreatedDate >=: startDate And CreatedDate <=: endDate And Field =: 'Type' Order By CreatedDate DESC)  
							from Account a where a.Id IN : accountIds])
			{
				result.add(new GenericObject(null,acc,null));
			}
			
			For(Opportunity oppObject : [Select o.AccountId,o.Account.Name, o.RecordTypeId,o.RecordType.Name, o.Name, o.Total_Amount__c,o.Amount, o.License_Amount__c, o.Maintenance_Amount__c,o.Professional_Services_Amount__c, 
									o.Total_Licence_Amount__c, o.Total_Maintenance_Amount__c, o.Total_Services_Amount__c, o.Type ,o.Account.Type,o.OwnerId,o.Owner.Name,o.PROPHIX_Stage__c,o.StageName,o.CloseDate,o.CreatedDate
									from Opportunity o where o.AccountId IN : accountIds])
			{
				result.add(new GenericObject(null,null,oppObject));
			}
		}
		
		return result;
	}

private static List<String> getUniqueContactIds()
	{
		List<String> uniqueIds = new List<String>();
		
		Map<String,Key_Event__c> uniqueContactsMap = new Map<String , Key_Event__c>();
		
		For(Key_Event__c obj :[Select k.Contact__c, k.CreatedDate, k.Id, k.Lead_Created_Date__c, k.Name
					 			from Key_Event__c k Where k.Lead_Created_Date__c >= : startDate And k.Lead_Created_Date__c <= : endDate])
		{
			
			//keyEvents.add(obj);
			
			if(uniqueContactsMap.get(obj.Contact__c) == null)
	    	{
	    		uniqueContactsMap.put(obj.Contact__c, obj);
	    		uniqueIds.add(obj.Contact__c);
	    	}
			
		}
		
		return uniqueIds;
	}

 

 

  • September 25, 2010
  • Like
  • 0

I have a flex object thats embedded in a visualforce page as the <apex:flash/> tag.

 

I have downloaded the salesforce library (with the latest end point url) and included it in my flex project .

 

I am logging into SFDC with the connection object from the library , in flex, using the $Api.sessionId and $Api.surl parmas passed in from the visualforce page. 

 

In my SFDC environment I have set up 2 custom objects. 

 

My Problem is that when I try and query the first custom object , i am getting back the results as expected but when i try and query the second custom object i am getting an error , INVALID_TYPE , sobject type not supported. This doesnt make any sense. 

 

I am setup as the administrator and both the objects are setup in the same way.

 

Any ideas on why this might be happening?...I am badly stuck.

  • September 20, 2010
  • Like
  • 0

I have an apex web service in an apex class that is called from the flex front end . The Flex is embedded in a VF page as a flash object <apex:flash> and I am logging into salesforce.com using the session Id (grabbing it from the controller using UserInfo.getSessionId()) and session URL = $Api.Partner_Server_URL_90.

 

I am developing in my sandbox.

 

The code for the apex class holding the webservice is as follows.

 

global class MyWebService 
{
	private static Datetime startDate {get; set;}
	private static Datetime endDate {get; set;}
	
	
	global class LeadObject
	{
		public String name {get; set;}
		public String Id {get; set;}
		public String country {get; set;}
		public String city {get; set;}
		public String status {get; set;}
		public String annual_Rev_Range {get; set;}
		public String score {get; set;}
		public String company {get; set;}
		
		public LeadObject(Lead lead)
		{
			name = lead.Name;
			Id = lead.Id;
			country = lead.Country;
			city = lead.City;
			status = lead.Status;
			annual_Rev_Range = lead.Annual_Revenue_Range__c;
			company = lead.Company;
			score = lead.Score__c.format();
		} 
	}
	
	Webservice static List<LeadObject> getLeads(String startDateString , String startMonthString , String startYearString,
															String endDateString , String endMonthString , String endYearString)
	{
		List<LeadObject> result = new List<LeadObject>();
		
		//set the start and the end dates
		setDates(startDateString , startMonthString , startYearString,
				endDateString , endMonthString , endYearString);
		
		//get Leads Data
		List<Lead_Key_Event__c> leadKEs;
		leadKEs = new List<Lead_Key_Event__c>();
		
		List<String> leadIds = getLeadIds(leadKEs); 
		
		result = new List<LeadObject>();
		
		For(Lead l : [Select l.Annual_Revenue_Range__c, l.City, l.Company, l.Country, l.FirstName,l.Name, l.Id, l.LastName, l.Score__c, l.Status 
					  from Lead l where l.Id IN : leadIds])
		{
			result.add(new LeadObject(l));
		}
		
		return result;
	}
	
	private static List<String> getLeadIds(List<Lead_Key_Event__c> leadKeyEvents)
	{
		List<String> uniqueIds = new List<String>();
		
		System.debug('Start date : ' + startDate.date().format() + ' End Date : ' + endDate.date().format());
		
		
		Map<String,Lead_Key_Event__c> uniqueLeadsMap = new Map<String , Lead_Key_Event__c>();
		
		For(Lead_Key_Event__c obj : [Select l.Id, l.Lead__c, l.Lead__r.Name , l.Name, l.Lead_Created_Date__c, l.Score__c from Lead_Key_Event__c l
					    			Where l.Lead__c != null And l.Lead_Created_Date__c >= : startDate And l.Lead_Created_Date__c <= : endDate])
	    {
	    	leadKeyEvents.add(obj);
	    	
	    	if(uniqueLeadsMap.get(obj.Lead__c) == null)
	    	{
	    		uniqueLeadsMap.put(obj.Lead__c, obj);
	    		uniqueIds.add(obj.Lead__c);
	    	}
	    }
	    
	    return uniqueIds;
	}
	
	private static void setDates(String startDateString , String startMonthString , String startYearString,
							String endDateString , String endMonthString , String endYearString)
	{
		startDate = Datetime.newInstance(Integer.valueOf(startYearString),Integer.valueOf(startMonthString),Integer.valueOf(startDateString));
		endDate = DateTime.newInstance(Integer.valueOf(endYearString),Integer.valueOf(endMonthString),Integer.valueOf(endDateString));
	}
}

 The code for the flex front end thats calling the webservice menthod getLeads() is as follows:

 

 

package Controller
{
	import Model.Model;
	
	import com.salesforce.AsyncResponder;
	import com.salesforce.Connection;
	import com.salesforce.objects.Parameter;
	import com.salesforce.results.Fault;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;

	public class WebServiceClient
	{
		public var results:ArrayCollection;
		
		public var binding:Connection;
		
		public function WebServiceClient(sfdcConnection:Connection)
		{
			this.binding = sfdcConnection;
			
			if (!this.binding.IsLoggedIn)
				throw new Error("Connection to the server is not available.");	
		}
		
		public function execute(startDate:Date , endDate:Date): void
		{
			Alert.show("executing web service client");
			
			//preparing the parameters of the web service method
			var params : Array = new Array(6);
			
			var stDateStringParam:Parameter = new Parameter("startDateString",startDate.date.toString());
			params[0] = stDateStringParam;
			//params.push(stDateStringParam);
			var stMonthStringParam:Parameter = new Parameter("startMonthString",startDate.month.toString());
			params[1] = stMonthStringParam;
			//params.push(stMonthStringParam);
			var stYearStringParam:Parameter = new Parameter("startYearString",startDate.fullYear.toString());
			params[2] = stYearStringParam;
			//params.push(stYearStringParam);
			var endDateStringParam:Parameter = new Parameter("endDateString",endDate.date.toString());
			params[3] = endDateStringParam;
			//params.push(endDateStringParam);
			var endMonthStringParam:Parameter = new Parameter("endMonthString",endDate.month.toString());
			params[4] = endMonthStringParam;
			//params.push(endMonthStringParam);
			var endYearStringParam:Parameter = new Parameter("endYearString",endDate.fullYear.toString());
			params[5] = endYearStringParam;
			//params.push(endYearStringParam);
			
			getLeads(params);
			
		}
		
		private function getLeads(params:Array):void
		{
			try
			{
			// using SFDC Aysync Responder to get the results in flex
			var tempCallBack: AsyncResponder = new AsyncResponder(
				function(result:Object):void 
				{
					try
					{
						if (result != null)
						{
							var reportsDataController:ReportsDataController = new ReportsDataController();
							reportsDataController.setLeadsData(result);
						}
						else
							Alert.show("Leads are empty.", "Info");
					}
					catch(err:Error)
					{
						Alert.show("error in result handler : " + err.message);
					}
				},
				function(result: Fault):void { Alert.show("Operation failed", "Error");  }
			);
			
			// call the execute method of the SFDC connection object to reach out the web service
			Alert.show("Invokin SOAP");
			binding.execute("MyWebService", "getLeads", params, tempCallBack);
			}
			catch(err:Error)
			{
				Alert.show("error in getLeads : " + err.message);	
			}
		}

	}
}

if I look in the Debug logs , I know i am invoking the webservice and querying for the data , my problem is that the data is not being passed back to flex . i.e. the result object in my asyncresponder is coming back as null.

 

Any help would be greatly appreciated.

 

Thanks 

 

 

 

 

  • September 14, 2010
  • Like
  • 0

I am not sure if its possible without making things ugly and unecessary painful.

 

When we create a new Task/Activity from Account or Contact page and then Save it , it returns us to the Account or the Contact page associated with the task.

 

 What I want to do is to pop up a dialogue when user clicks save on a task/activity OR atleast redirect the user to the task detail section (view mode) and not to the account/contact page.

 

Is this possible without going the visualforce way? (I cant find a way to override the functionality of save button under buttons and links etc). It would be great if I could just resolve it without creating a VF page.

 

If NOT then:

 

I am not sure if i can just have a visualforce page for the EDIT button for task/activity and just say <detail mode='Edit'>.

 

If thats not possible is there an easy way to just ready the layout and set the UI through code in visualforce. Basically i just want to recreate the edit page for task/activity for different scenarios e.g log a call  etc.

 

Any examples would be helpful.

 

All I want to do is pop up a message based on a field set while creating a task/activity and its just getting uglier and uglier to accomplish something simple as that. 

  • September 10, 2010
  • Like
  • 0

When I pass this query in the start ethod of batch process it works fine

 

Database.getQueryLocator([Select Id From Lead Where Isconverted  = : false And Company =: 'ABC' ]);

 

Now if I want to pass it as a string like below then it doesnt work

 

Boolean f = false;

 

String query = 'Select Id,Name From Lead Where IsConverted =\'' + f + '\' And Company =\'' + 'ABC' + '\'';

 

I know i am making some mistake in formatting the string. Please guide me to some documentation that can help resolve this. (format queries as string)

I have a trigger that runs on lead update (when a lead is converted to a contact.) . We use demand tools to dedupe leads to leads and then leads to contacts. When we run demand tools its giving me this error

 

UpdateContactOnLeadUpdate: execution of AfterUpdate

 

caused by: System.Exception: Too many SOQL queries: 101

 

Trigger.UpdateContactOnLeadUpdate: line 13, column 25

 

I am pasting the code for my trigger below. Line 13 is where I am getting the recordTypes . Its a single query. I am not sure why its causing this error. 

 

 

trigger UpdateContactOnLeadUpdate on Lead (after Update)
{
  List<String> conIds = new List<String>();
  List<String> leadIds = new List<String>();
  
  Map<String,Lead> leadMap = new map<String,Lead>();
  Map<String,Contact> contactMap = new map<String,Contact>();
  List<Key_Event__c> keyEventsToInsert = new List<Key_Event__c>();
  List<Lead_Key_Event__c> keyEventsToDelete = new List<Lead_Key_Event__c>();
  
  List<Contact> consToUpdate = new List<Contact>();
  
  RecordType[] recType = [Select Id, Name, SobjectType from RecordType 
                                            Where SOBjectType =: 'Key_Event__c'];line13
  
    For(Lead lead : Trigger.new)
    {
        //the lead is just converted
        if(lead.IsConverted == true && Trigger.oldMap.get(lead.Id).IsConverted == false)
        {
          leadIds.add(lead.Id);
          
          leadMap.put(lead.Id,lead);
          
          conIds.Add(lead.ConvertedContactId);
        }
    }
    
    //get the key events for the leads
    List<Lead_Key_Event__c> leadKeyEvents = [Select k.Auto_Demo_Field_1__c,k.Appt_Scheduled_Date__c, k.Auto_demo_Field_2__c,k.Lead_Confirmed_by_RM_NAM__c, 
                      k.Best_time_to_contact_prospects__c,k.Contact_Sales_Comments__c, 
                      k.CreatedById, k.CreatedDate, k.Id, k.IsDeleted, k.Key_Event_Type__c, 
                      k.LastModifiedById, k.LastModifiedDate, k.Lead__c, k.Lead_Created_Date__c, k.Name, 
                      k.Primary_Business_Pain__c, k.Purchase_decision_timeframe__c, 
                      k.Score__c, k.SystemModstamp, k.Trade_Show_Comments__c, k.Webinar_date__c, 
                      k.Webinar_request_date__c, k.Webinar_status__c from Lead_Key_Event__c k where Lead__c IN: leadIds Order By k.CreatedDate ASC];   
    
    
    
    
            //get the contact associated with the lead
    Contact[] contacts = [select Id , Last_KE_Date__c , CPM_Autodemo__c , White_Paper_Download__c,
              Contact_Sales_Request_Form__c,Purchase_Decision_Pending__c ,Recorded_Webinar__c,
              Webcast__c,Webinar__c, AccountId,pi__score__c
                         from Contact Where Id IN :conIds ];
                         
    //set the contact map                     
    For(Contact con : contacts)
    {
      contactMap.put(con.Id,con);
    }
    
    //run through all the lead key events and create corresponding key events for contacts/accounts
    For(Lead_Key_Event__c ke : leadKeyEvents)
    {
      Lead leadObject = leadMap.get(ke.Lead__c);
      Contact contactObject = contactMap.get(leadObject.ConvertedContactId);
    
      Key_Event__c keyEvent = new Key_Event__c();
      keyEvent.Contact__c = contactObject.Id;
      keyEvent.Account__c = contactObject.AccountId;
      keyEvent.Auto_Demo_Field_1__c = ke.Auto_Demo_Field_1__c;
      keyEvent.Auto_demo_Field_2__c = ke.Auto_demo_Field_2__c;
      keyEvent.Best_time_to_contact_prospects__c = ke.Best_time_to_contact_prospects__c;
      keyEvent.Contact_Sales_Comments__c = ke.Contact_Sales_Comments__c;
      keyEvent.Key_Event_Type__c = ke.Key_Event_Type__c;
      keyEvent.Lead_Created_Date__c = ke.Lead_Created_Date__c;
      keyEvent.Name = ke.Name;
      keyEvent.Primary_Business_Pain__c = ke.Primary_Business_Pain__c;
      keyEvent.Purchase_decision_timeframe__c = ke.Purchase_decision_timeframe__c;
      keyEvent.Score__c = ke.Score__c;
      keyEvent.Trade_Show_Comments__c = ke.Trade_Show_Comments__c;
      keyEvent.Webinar_date__c = ke.Webinar_date__c;
      keyEvent.Webinar_request_date__c = ke.Webinar_request_date__c;
      keyEvent.Webinar_status__c = ke.Webinar_status__c;
      keyEvent.Appt_Scheduled_Date__c = ke.Appt_Scheduled_Date__c;
      keyEvent.Lead_Confirmed_by_RM_NAM__c = ke.Lead_Confirmed_by_RM_NAM__c;
      
      String recTypeToSearch;
      
      if(keyEvent.Name == 'Auto Demo')
        recTypeToSearch = 'Key Event Auto Demo';
      if(keyEvent.Name == 'Auto Demo Click Through')
        recTypeToSearch = 'Key Event Auto Demo';
      if(keyEvent.Name == 'White Paper Download')
        recTypeToSearch = 'Key Event White Paper Download';
      if(keyEvent.Name == 'Contact Sales request form')
        recTypeToSearch = 'Contact Sales Request form layout';
      if(keyEvent.Name == 'Purchase Decision pending')
        recTypeToSearch = 'Purchase decision pending';
      if(keyEvent.Name == 'Recorded Webinar')
        recTypeToSearch = 'Recorded webinar';
      if(keyEvent.Name == 'Webcast Attendence')
        recTypeToSearch = 'Webcast attendence';
      if(keyEvent.Name == 'Webinar Request')
        recTypeToSearch = 'Webinar Request';
      if(keyEvent.Name == 'Trade Show')
        recTypeToSearch = 'TradeShow';
      if(keyEvent.Name == 'Webinar Attendence')
        recTypeToSearch = 'Webinar Attendence';
      if(keyEvent.Name == 'Webinar Registration')
        recTypeToSearch = 'Webinar Registration';
      if(keyEvent.Name == 'Appointment Scheduled')
        recTypeToSearch = 'Appointment Scheduled';
      if(keyEvent.Name == 'Appointment Attended')
        recTypeToSearch = 'Appointment Attended';
        
      
      For(RecordType rec : recType)
        {
            if(rec.Name == recTypeToSearch)
                keyEvent.RecordTypeId = rec.Id;
        }
  
      if(contactObject.Last_KE_Date__c == null || (contactObject.Last_KE_Date__c < keyEvent.Lead_Created_Date__c))
        contactObject.Last_KE_Date__c = keyEvent.Lead_Created_Date__c;
      
      if(leadObject.pi__score__c != null)
        {
          if(contactObject.pi__score__c == null)
            contactObject.pi__score__c = leadObject.pi__score__c;
          else
            contactObject.pi__score__c += leadObject.pi__score__c;
        }
      
      List<Contact> refinedContacts = new List<Contact>();
      For(Integer i = 0 ; i < consToUpdate.size() ; i++)
      {
        if(consToUpdate[i].Id != contactObject.id)
        {
          refinedContacts.add(consToUpdate[i]);
        }
      }
      consToUpdate = refinedContacts;
      
      consToUpdate.add(contactObject);
      keyEventsToInsert.add(keyEvent);
      keyEventsToDelete.add(ke);
      
    }
      
    if(keyEventsToInsert.size() > 0)
      insert keyEventsToInsert;  
      
    if(consToUpdate.size() > 0)
      update consToUpdate;
      
    if(keyEventsToDelete.size() > 0)
      delete keyEventsToDelete;
}

 

 

 

 

I have a simple batch job (the code is pasted below.) and a test method for the job. My class is not getting the coverage that s required (I am only getting 13%). Could anyone please tell me whats wrong with the code or if i am missing something. Its preventing me from moving stuff into production through ecllipse as its bringin down the average test coverage to 72% (75% required) on all classes and triggers.

global class UpdateAccounts implements Database.Batchable<sobject>  
{
	global Database.QueryLocator start(Database.BatchableContext BC)
	{
		return Database.getQueryLocator([Select Id,Name from Account]);
	}
	
	global void execute(Database.BatchableContext BC , List<sobject> scope)
	{
		List<Account> accsToUpdate = new List<Account>();
			
		For(sobject s : scope)
		{
			Account acc  = (Account)s;
			
			accsToUpdate.add(acc);
			
		}
		
		update accsToUpdate;
	}
	
	global void finish(Database.BatchableContext BC)
	{
		Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

		mail.setToAddresses(new String[] {'abakshi@prophix.com'});
		mail.setReplyTo('abakshi@prophix.com');
		mail.setSenderDisplayName('UpdateAccounts Event Batch Processing');
		mail.setSubject('UpdateAccounts Batch Process Completed');
		mail.setPlainTextBody('UpdateAccounts Batch Process has completed');

		Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
	}

	private static testMethod void testUpdateAccounts()
	{
		User user = [Select Id , Name from User where Id = '00530000003oM6i'];
		
		List <Account> accns = new List<Account>();
      	for(integer i = 0; i<200; i++)
      	{
         Account a = new Account(name='testAccount'+'i', 
                     Ownerid = user.ID); 
         accns.add(a);
      	}
   
   		insert accns;
		
		Test.startTest();
		UpdateAccounts batchProcess = new UpdateAccounts();
		ID batchProcessId = Database.executeBatch(batchProcess,90);
		Test.stopTest();
		
		System.assertEquals(0,0);
	}
}

 

 

How do I include AccountId (lookup field on Contact) from mergefields in my javascript onclick code for a button.

I have a relted list of 'LeadKeyEvents' (Custom Object) on Leads . I want to have a button that would add another LeadKeyEvent (of a certain recordType based on some info on leads). I know i can add a new button but am not sure how to pass in the curr leadID to it. Any helo would be great

 

 

I have a pageBlockTable and some columns . I would want the title value for a column to be set (so that i can show a custom tool tip) based on the item in the table. for this i need to pass in the Id of that particual item in the table to mouse over property of column through java script function. 

 

Heres the code for column , javascript and action function :

I have no clue if i missing the syntax or is there another way to accomplish this as its not working..

 

 

<apex:column id="colLeadName" headerValue="Lead Name" title="{!leadKEs}" onmouseover="showKE({!row.lead.Id});">
					<apex:commandLink id="cmdLnkLeadName" action="{!LeadPage}" value="{!row.lead.Name}" reRender="form" >
						<apex:param name="linkParam" value="{!row.lead.Id}" assignTo="{!leadIdToView}"/>
					</apex:commandLink>
				</apex:column>

javascript

<script type="text/javascript">
				function showKE(String Id)
				{
					showLeadKE(Id);
				}
			</script>

action function
<apex:actionFunction action="{!showLeadKE}" name="showLeadKE" rerender="form">
        	<apex:param name="firstParam" value="" assignTo="{!leadIdToView}"/>
	    </apex:actionFunction>

 

 

Is there a way that I can have Customized tool tip in a visualforce page.

I have a pageBlock table and I want to display info in a tooltip based on the Id on each row of the table. 

e.g i have a table displaying a list contacts. now when I mouse over each contact I want to show some account info in a tool tip / hover on that table. 

Is there a way to accomplish that in visualforce.

 

Also Is there a way we can have floating pop ups. I can have a pop up as in this example

http://community.salesforce.com/t5/Visualforce-Development/Best-way-to-show-Pop-up-in-a-visual-force-page/m-p/145439?jump=true#M16568 

 

But its position is absolute , i want the pop up to float as I scroll up and down the page.

I am trying to create a standard functionality where we move items from one list to the other using buttons inbetween the lists. I am placing my lists in a pageblock and by default the components in a pageblock are alligned horizontally.

 

I would want the buttons between the lists to be alligned vertically and also at a certain height . I am not sure how to do that (the height might be fixed using css but still not sure).

 

If someone can point me in the right direction on how to achieve that , it would be great. Any example on the above mentioned feature (moving items from one list to the other with buttons inbetween) would be cool too.

 

Thanks 

While doing a mass insert using a batch process. If I get an error on a record , would it not insert the other records.

 

For example:

 

If I have to insert a list of Leads and a couple of leads in the list throw some errors , would it stop the operation for the whole list or just those records.

 

Is there a way to add customized 'help' documents or text in the 'help and training' link on both standard and visualforce pages?

I have a batch apex job and the code is as follows

 

 

global Database.QueryLocator start(Database.BatchableContext BC)
	{
		return Database.getQueryLocator(query);
	}
	
	global void execute(Database.BatchableContext BC , List<sobject> scope)
	{
		List<Test_Key_Event__c> keyEventsToInsert = new List<Test_Key_Event__c>();
		
		List<RecordType> recordTypes = [Select r.Id, r.Name, r.SobjectType from RecordType r Where r.SobjectType = 'Test_Key_Event__c' ];
		
		For(sobject s : scope)
		{
			Contact con = (Contact)s;
			
			For(ActivityHistory task : [Select c.AccountId, c.Id, (Select AccountId, CreatedById, CreatedDate, WhoId, Id, OwnerId, Subject 
										From ActivityHistories Where Subject like '%KE: Autodemo%') 
										from Contact c Where c.Id =: con.Id ].ActivityHistories)
			{
				//if(task.OwnerId == '00530000001rFmIAAU' || task.OwnerId == '00530000001tz0yAAA')
				if(task.CreatedById == '00530000001rFmIAAU' && task.CreatedById == '00530000001tz0yAAA')
				{
					Test_Key_Event__c keyEvent = new Test_Key_Event__c();
					keyEvent.Account__c = task.AccountId;
					keyEvent.Contact__c = task.WhoId;
					keyEvent.Name = 'AutoDemo';
					keyEvent.Score__c = 50;
					keyEvent.Test_Key_Event_Date__c = task.CreatedDate;
					keyEvent.Test_Key_Event_Type__c = 'KE:Autodemo';
					
					for(RecordType rec : recordTypes)
					{
						if(rec.Name == 'default')
							keyEvent.RecordTypeId = rec.Id;
					}
					
					keyEventsToInsert.add(keyEvent);
					//insert keyEvent;
				}
				
			}
		}
		
		insert keyEventsToInsert;
	}

 

I am running into the governor limits in the execute (Too many SOQL queries: 201). I am assuming its because I have a subQuery in the for loop and because I am using Database.QueryLocator its allowing only processing data in atches of 200 but subquery is counted as another query.

 

My questions are :

Am I right in my presumption with the governor limits?

 

if yes

What is the possible solution . I am guessing using the scope param in execute batch but wont that limit the num of records queried in the start method query. I have around 500000 records returned in that query.

 

Whats the possible workaround solution.?

 

 

 

Hi, 

 

I am having trouble getting this query working in a batchable class. 

 

In my start method when I use the following query : 

 

 

String query = 'Select a.Id, a.Name, a.OwnerId ,(Select Id, OwnerId From Contacts) from Account a Where a.Type IN: '+ accTypesToInclude ;
 return Database.getQueryLocator(query);

 

 

I am getting the error :

 

System.QueryException: unexpected token: '(' 

 

Any ideas whats wrong

 

Thanks

I am having an trouble with redirecting the user to the right URL (page) based on different actions. It seems that the returnURL is different for different actions. Heres my problem:

 

When I create new task on Contact /Account and then Save it  , it returns me to the Contact/Account page

Also 

If I click on Edit in the Edit/Del link under Open Activities on the Contact/Account page , it again returns me to the Contact/Account page.

BUT

When I click on a task in the Open Activity section and then click on edit and then save it , it returns me to the task page (in read mode) - THATS WHAT I WANT

 

What I want is to return to the task page (read mode) even when i create a new task or edit the task using the edit link.I am stuck with this and any help would be really appreciated. 

 

 

 

I have an apex web service in an apex class that is called from the flex front end . The Flex is embedded in a VF page as a flash object <apex:flash> and I am logging into salesforce.com using the session Id (grabbing it from the controller using UserInfo.getSessionId()) and session URL = $Api.Partner_Server_URL_90.

 

I am developing in my sandbox.

 

The code for the apex class holding the webservice is as follows.

 

global class MyWebService 
{
	private static Datetime startDate {get; set;}
	private static Datetime endDate {get; set;}
	
	
	global class LeadObject
	{
		public String name {get; set;}
		public String Id {get; set;}
		public String country {get; set;}
		public String city {get; set;}
		public String status {get; set;}
		public String annual_Rev_Range {get; set;}
		public String score {get; set;}
		public String company {get; set;}
		
		public LeadObject(Lead lead)
		{
			name = lead.Name;
			Id = lead.Id;
			country = lead.Country;
			city = lead.City;
			status = lead.Status;
			annual_Rev_Range = lead.Annual_Revenue_Range__c;
			company = lead.Company;
			score = lead.Score__c.format();
		} 
	}
	
	Webservice static List<LeadObject> getLeads(String startDateString , String startMonthString , String startYearString,
															String endDateString , String endMonthString , String endYearString)
	{
		List<LeadObject> result = new List<LeadObject>();
		
		//set the start and the end dates
		setDates(startDateString , startMonthString , startYearString,
				endDateString , endMonthString , endYearString);
		
		//get Leads Data
		List<Lead_Key_Event__c> leadKEs;
		leadKEs = new List<Lead_Key_Event__c>();
		
		List<String> leadIds = getLeadIds(leadKEs); 
		
		result = new List<LeadObject>();
		
		For(Lead l : [Select l.Annual_Revenue_Range__c, l.City, l.Company, l.Country, l.FirstName,l.Name, l.Id, l.LastName, l.Score__c, l.Status 
					  from Lead l where l.Id IN : leadIds])
		{
			result.add(new LeadObject(l));
		}
		
		return result;
	}
	
	private static List<String> getLeadIds(List<Lead_Key_Event__c> leadKeyEvents)
	{
		List<String> uniqueIds = new List<String>();
		
		System.debug('Start date : ' + startDate.date().format() + ' End Date : ' + endDate.date().format());
		
		
		Map<String,Lead_Key_Event__c> uniqueLeadsMap = new Map<String , Lead_Key_Event__c>();
		
		For(Lead_Key_Event__c obj : [Select l.Id, l.Lead__c, l.Lead__r.Name , l.Name, l.Lead_Created_Date__c, l.Score__c from Lead_Key_Event__c l
					    			Where l.Lead__c != null And l.Lead_Created_Date__c >= : startDate And l.Lead_Created_Date__c <= : endDate])
	    {
	    	leadKeyEvents.add(obj);
	    	
	    	if(uniqueLeadsMap.get(obj.Lead__c) == null)
	    	{
	    		uniqueLeadsMap.put(obj.Lead__c, obj);
	    		uniqueIds.add(obj.Lead__c);
	    	}
	    }
	    
	    return uniqueIds;
	}
	
	private static void setDates(String startDateString , String startMonthString , String startYearString,
							String endDateString , String endMonthString , String endYearString)
	{
		startDate = Datetime.newInstance(Integer.valueOf(startYearString),Integer.valueOf(startMonthString),Integer.valueOf(startDateString));
		endDate = DateTime.newInstance(Integer.valueOf(endYearString),Integer.valueOf(endMonthString),Integer.valueOf(endDateString));
	}
}

 The code for the flex front end thats calling the webservice menthod getLeads() is as follows:

 

 

package Controller
{
	import Model.Model;
	
	import com.salesforce.AsyncResponder;
	import com.salesforce.Connection;
	import com.salesforce.objects.Parameter;
	import com.salesforce.results.Fault;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;

	public class WebServiceClient
	{
		public var results:ArrayCollection;
		
		public var binding:Connection;
		
		public function WebServiceClient(sfdcConnection:Connection)
		{
			this.binding = sfdcConnection;
			
			if (!this.binding.IsLoggedIn)
				throw new Error("Connection to the server is not available.");	
		}
		
		public function execute(startDate:Date , endDate:Date): void
		{
			Alert.show("executing web service client");
			
			//preparing the parameters of the web service method
			var params : Array = new Array(6);
			
			var stDateStringParam:Parameter = new Parameter("startDateString",startDate.date.toString());
			params[0] = stDateStringParam;
			//params.push(stDateStringParam);
			var stMonthStringParam:Parameter = new Parameter("startMonthString",startDate.month.toString());
			params[1] = stMonthStringParam;
			//params.push(stMonthStringParam);
			var stYearStringParam:Parameter = new Parameter("startYearString",startDate.fullYear.toString());
			params[2] = stYearStringParam;
			//params.push(stYearStringParam);
			var endDateStringParam:Parameter = new Parameter("endDateString",endDate.date.toString());
			params[3] = endDateStringParam;
			//params.push(endDateStringParam);
			var endMonthStringParam:Parameter = new Parameter("endMonthString",endDate.month.toString());
			params[4] = endMonthStringParam;
			//params.push(endMonthStringParam);
			var endYearStringParam:Parameter = new Parameter("endYearString",endDate.fullYear.toString());
			params[5] = endYearStringParam;
			//params.push(endYearStringParam);
			
			getLeads(params);
			
		}
		
		private function getLeads(params:Array):void
		{
			try
			{
			// using SFDC Aysync Responder to get the results in flex
			var tempCallBack: AsyncResponder = new AsyncResponder(
				function(result:Object):void 
				{
					try
					{
						if (result != null)
						{
							var reportsDataController:ReportsDataController = new ReportsDataController();
							reportsDataController.setLeadsData(result);
						}
						else
							Alert.show("Leads are empty.", "Info");
					}
					catch(err:Error)
					{
						Alert.show("error in result handler : " + err.message);
					}
				},
				function(result: Fault):void { Alert.show("Operation failed", "Error");  }
			);
			
			// call the execute method of the SFDC connection object to reach out the web service
			Alert.show("Invokin SOAP");
			binding.execute("MyWebService", "getLeads", params, tempCallBack);
			}
			catch(err:Error)
			{
				Alert.show("error in getLeads : " + err.message);	
			}
		}

	}
}

if I look in the Debug logs , I know i am invoking the webservice and querying for the data , my problem is that the data is not being passed back to flex . i.e. the result object in my asyncresponder is coming back as null.

 

Any help would be greatly appreciated.

 

Thanks 

 

 

 

 

  • September 14, 2010
  • Like
  • 0

When I pass this query in the start ethod of batch process it works fine

 

Database.getQueryLocator([Select Id From Lead Where Isconverted  = : false And Company =: 'ABC' ]);

 

Now if I want to pass it as a string like below then it doesnt work

 

Boolean f = false;

 

String query = 'Select Id,Name From Lead Where IsConverted =\'' + f + '\' And Company =\'' + 'ABC' + '\'';

 

I know i am making some mistake in formatting the string. Please guide me to some documentation that can help resolve this. (format queries as string)

I have a trigger that runs on lead update (when a lead is converted to a contact.) . We use demand tools to dedupe leads to leads and then leads to contacts. When we run demand tools its giving me this error

 

UpdateContactOnLeadUpdate: execution of AfterUpdate

 

caused by: System.Exception: Too many SOQL queries: 101

 

Trigger.UpdateContactOnLeadUpdate: line 13, column 25

 

I am pasting the code for my trigger below. Line 13 is where I am getting the recordTypes . Its a single query. I am not sure why its causing this error. 

 

 

trigger UpdateContactOnLeadUpdate on Lead (after Update)
{
  List<String> conIds = new List<String>();
  List<String> leadIds = new List<String>();
  
  Map<String,Lead> leadMap = new map<String,Lead>();
  Map<String,Contact> contactMap = new map<String,Contact>();
  List<Key_Event__c> keyEventsToInsert = new List<Key_Event__c>();
  List<Lead_Key_Event__c> keyEventsToDelete = new List<Lead_Key_Event__c>();
  
  List<Contact> consToUpdate = new List<Contact>();
  
  RecordType[] recType = [Select Id, Name, SobjectType from RecordType 
                                            Where SOBjectType =: 'Key_Event__c'];line13
  
    For(Lead lead : Trigger.new)
    {
        //the lead is just converted
        if(lead.IsConverted == true && Trigger.oldMap.get(lead.Id).IsConverted == false)
        {
          leadIds.add(lead.Id);
          
          leadMap.put(lead.Id,lead);
          
          conIds.Add(lead.ConvertedContactId);
        }
    }
    
    //get the key events for the leads
    List<Lead_Key_Event__c> leadKeyEvents = [Select k.Auto_Demo_Field_1__c,k.Appt_Scheduled_Date__c, k.Auto_demo_Field_2__c,k.Lead_Confirmed_by_RM_NAM__c, 
                      k.Best_time_to_contact_prospects__c,k.Contact_Sales_Comments__c, 
                      k.CreatedById, k.CreatedDate, k.Id, k.IsDeleted, k.Key_Event_Type__c, 
                      k.LastModifiedById, k.LastModifiedDate, k.Lead__c, k.Lead_Created_Date__c, k.Name, 
                      k.Primary_Business_Pain__c, k.Purchase_decision_timeframe__c, 
                      k.Score__c, k.SystemModstamp, k.Trade_Show_Comments__c, k.Webinar_date__c, 
                      k.Webinar_request_date__c, k.Webinar_status__c from Lead_Key_Event__c k where Lead__c IN: leadIds Order By k.CreatedDate ASC];   
    
    
    
    
            //get the contact associated with the lead
    Contact[] contacts = [select Id , Last_KE_Date__c , CPM_Autodemo__c , White_Paper_Download__c,
              Contact_Sales_Request_Form__c,Purchase_Decision_Pending__c ,Recorded_Webinar__c,
              Webcast__c,Webinar__c, AccountId,pi__score__c
                         from Contact Where Id IN :conIds ];
                         
    //set the contact map                     
    For(Contact con : contacts)
    {
      contactMap.put(con.Id,con);
    }
    
    //run through all the lead key events and create corresponding key events for contacts/accounts
    For(Lead_Key_Event__c ke : leadKeyEvents)
    {
      Lead leadObject = leadMap.get(ke.Lead__c);
      Contact contactObject = contactMap.get(leadObject.ConvertedContactId);
    
      Key_Event__c keyEvent = new Key_Event__c();
      keyEvent.Contact__c = contactObject.Id;
      keyEvent.Account__c = contactObject.AccountId;
      keyEvent.Auto_Demo_Field_1__c = ke.Auto_Demo_Field_1__c;
      keyEvent.Auto_demo_Field_2__c = ke.Auto_demo_Field_2__c;
      keyEvent.Best_time_to_contact_prospects__c = ke.Best_time_to_contact_prospects__c;
      keyEvent.Contact_Sales_Comments__c = ke.Contact_Sales_Comments__c;
      keyEvent.Key_Event_Type__c = ke.Key_Event_Type__c;
      keyEvent.Lead_Created_Date__c = ke.Lead_Created_Date__c;
      keyEvent.Name = ke.Name;
      keyEvent.Primary_Business_Pain__c = ke.Primary_Business_Pain__c;
      keyEvent.Purchase_decision_timeframe__c = ke.Purchase_decision_timeframe__c;
      keyEvent.Score__c = ke.Score__c;
      keyEvent.Trade_Show_Comments__c = ke.Trade_Show_Comments__c;
      keyEvent.Webinar_date__c = ke.Webinar_date__c;
      keyEvent.Webinar_request_date__c = ke.Webinar_request_date__c;
      keyEvent.Webinar_status__c = ke.Webinar_status__c;
      keyEvent.Appt_Scheduled_Date__c = ke.Appt_Scheduled_Date__c;
      keyEvent.Lead_Confirmed_by_RM_NAM__c = ke.Lead_Confirmed_by_RM_NAM__c;
      
      String recTypeToSearch;
      
      if(keyEvent.Name == 'Auto Demo')
        recTypeToSearch = 'Key Event Auto Demo';
      if(keyEvent.Name == 'Auto Demo Click Through')
        recTypeToSearch = 'Key Event Auto Demo';
      if(keyEvent.Name == 'White Paper Download')
        recTypeToSearch = 'Key Event White Paper Download';
      if(keyEvent.Name == 'Contact Sales request form')
        recTypeToSearch = 'Contact Sales Request form layout';
      if(keyEvent.Name == 'Purchase Decision pending')
        recTypeToSearch = 'Purchase decision pending';
      if(keyEvent.Name == 'Recorded Webinar')
        recTypeToSearch = 'Recorded webinar';
      if(keyEvent.Name == 'Webcast Attendence')
        recTypeToSearch = 'Webcast attendence';
      if(keyEvent.Name == 'Webinar Request')
        recTypeToSearch = 'Webinar Request';
      if(keyEvent.Name == 'Trade Show')
        recTypeToSearch = 'TradeShow';
      if(keyEvent.Name == 'Webinar Attendence')
        recTypeToSearch = 'Webinar Attendence';
      if(keyEvent.Name == 'Webinar Registration')
        recTypeToSearch = 'Webinar Registration';
      if(keyEvent.Name == 'Appointment Scheduled')
        recTypeToSearch = 'Appointment Scheduled';
      if(keyEvent.Name == 'Appointment Attended')
        recTypeToSearch = 'Appointment Attended';
        
      
      For(RecordType rec : recType)
        {
            if(rec.Name == recTypeToSearch)
                keyEvent.RecordTypeId = rec.Id;
        }
  
      if(contactObject.Last_KE_Date__c == null || (contactObject.Last_KE_Date__c < keyEvent.Lead_Created_Date__c))
        contactObject.Last_KE_Date__c = keyEvent.Lead_Created_Date__c;
      
      if(leadObject.pi__score__c != null)
        {
          if(contactObject.pi__score__c == null)
            contactObject.pi__score__c = leadObject.pi__score__c;
          else
            contactObject.pi__score__c += leadObject.pi__score__c;
        }
      
      List<Contact> refinedContacts = new List<Contact>();
      For(Integer i = 0 ; i < consToUpdate.size() ; i++)
      {
        if(consToUpdate[i].Id != contactObject.id)
        {
          refinedContacts.add(consToUpdate[i]);
        }
      }
      consToUpdate = refinedContacts;
      
      consToUpdate.add(contactObject);
      keyEventsToInsert.add(keyEvent);
      keyEventsToDelete.add(ke);
      
    }
      
    if(keyEventsToInsert.size() > 0)
      insert keyEventsToInsert;  
      
    if(consToUpdate.size() > 0)
      update consToUpdate;
      
    if(keyEventsToDelete.size() > 0)
      delete keyEventsToDelete;
}

 

 

 

 

How do I include AccountId (lookup field on Contact) from mergefields in my javascript onclick code for a button.

I have a batch apex job and the code is as follows

 

 

global Database.QueryLocator start(Database.BatchableContext BC)
	{
		return Database.getQueryLocator(query);
	}
	
	global void execute(Database.BatchableContext BC , List<sobject> scope)
	{
		List<Test_Key_Event__c> keyEventsToInsert = new List<Test_Key_Event__c>();
		
		List<RecordType> recordTypes = [Select r.Id, r.Name, r.SobjectType from RecordType r Where r.SobjectType = 'Test_Key_Event__c' ];
		
		For(sobject s : scope)
		{
			Contact con = (Contact)s;
			
			For(ActivityHistory task : [Select c.AccountId, c.Id, (Select AccountId, CreatedById, CreatedDate, WhoId, Id, OwnerId, Subject 
										From ActivityHistories Where Subject like '%KE: Autodemo%') 
										from Contact c Where c.Id =: con.Id ].ActivityHistories)
			{
				//if(task.OwnerId == '00530000001rFmIAAU' || task.OwnerId == '00530000001tz0yAAA')
				if(task.CreatedById == '00530000001rFmIAAU' && task.CreatedById == '00530000001tz0yAAA')
				{
					Test_Key_Event__c keyEvent = new Test_Key_Event__c();
					keyEvent.Account__c = task.AccountId;
					keyEvent.Contact__c = task.WhoId;
					keyEvent.Name = 'AutoDemo';
					keyEvent.Score__c = 50;
					keyEvent.Test_Key_Event_Date__c = task.CreatedDate;
					keyEvent.Test_Key_Event_Type__c = 'KE:Autodemo';
					
					for(RecordType rec : recordTypes)
					{
						if(rec.Name == 'default')
							keyEvent.RecordTypeId = rec.Id;
					}
					
					keyEventsToInsert.add(keyEvent);
					//insert keyEvent;
				}
				
			}
		}
		
		insert keyEventsToInsert;
	}

 

I am running into the governor limits in the execute (Too many SOQL queries: 201). I am assuming its because I have a subQuery in the for loop and because I am using Database.QueryLocator its allowing only processing data in atches of 200 but subquery is counted as another query.

 

My questions are :

Am I right in my presumption with the governor limits?

 

if yes

What is the possible solution . I am guessing using the scope param in execute batch but wont that limit the num of records queried in the start method query. I have around 500000 records returned in that query.

 

Whats the possible workaround solution.?

 

 

 

Running into a few issues with the Apex Flex library and Apex Code web services.

1) If you attempt to call an Apex web service via Connection.execute() that has no arguments you'll get one of several error messages back depending on how you attempt to call the web service.  Is there a correct method for doing this with the latest Flex library?  It currently won't allow you to pass a null, an empty array or an array containing a null as the argument list for the WS.

2) If you attempt to call an Apex web service that returns no results, you'll get a null value exception when the WS returns.

3) Exceptions thrown by Apex Code don't appear to be coming back to Flex in any manner.  If Apex Code throws an exception  the callback is never called and no Flex exception is thrown, so the application basically sits in limbo.

Has any one else experienced this?  Are these known issues?
  • November 06, 2007
  • Like
  • 0