• AAM
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies

I have the following QueryString:

 

String QueryString = 'SELECT Id, Name, AccountId, Account.Name, Phone, Email, OwnerId, Owner.Alias, Active__c, Broker_Number__c, Broker_Number__r.Name, Account.Firm__c FROM Contact WHERE' + QueryActive;

 

 

I need to loop through the results and populate a list:

 

for(sObject o : Database.query(QueryString))
{
	SearchContact result = new SearchContact((Id)o.get('Id'),(String)o.get('Name'),(Id)o.get('AccountId'),(String)o.get('Account.Name'),(String)o.get('Phone'),(String)o.get('Email'),(Id)o.get('OwnerId'),(String)o.get('Owner.Alias'),(Boolean)o.get('Active__c'),(Id)o.get('Broker_Number__c'),(String)o.get('Broker_Number__r.Name'),(String)o.get('Account.Firm__c'));
	ContactResults.add(result);
}

 

 

I keep getting an error that 'Account.Name' is not a valid field for Contact. How am I supposed to retrieve the Account Name, Owner Alias, etc.?

 

Thanks.

  • March 01, 2011
  • Like
  • 0

 

I've recently added a couple of lines of code to a validation script I created in a trigger so that if a field is checked, after insert/update creates an email to be sent to me notifying me of the change. In the sandbox, the trigger works great and sends the email to me just once. However, in production the same trigger causes me to receive the email twice. Any thoughts?

 

Here's the email portion of the code:

 

String userName = UserInfo.getName();
String completeUser = UserInfo.getName() + ' (' + UserInfo.getUserName() + ')';
String triggerType;
				
if(trigger.isInsert) triggerType = 'adding';
if(trigger.isUpdate) triggerType = 'updating';
				        
String subject = userName + ' has overriden the Contact Validation script in Salesforce';
String plainTextHeader = completeUser + ' has overriden the Contact Validation script when ' + triggerType + ' ' + contactName + '\'s record in Salesforce. Here are matching records:\n';
String htmlHeader = '<h3><strong>' + completeUser + ' has overriden the Contact Validation script when ' + triggerType  + ' <a href=\'salesforceOrg' + contactId + '\'>' + contactName + '\'s</a> record in Salesforce. Here are matching records:</strong></h3><ul>';
String plainTextBody = '';
String htmlBody = '';
				
List<Account> a = [SELECT ParentId FROM Account WHERE Id =: branchId AND Home_Office__c != null];
firmId = a[0].ParentId;
				        
for (Contact c : [SELECT Id, Name, Account.Name FROM Contact WHERE Id !=: contactID AND Account.ParentId =: firmID AND Name =: contactName AND Active__c = True])
{
	Id matchId = c.Id;
	String matchName = c.Name;
	String matchCompany = c.Account.Name;
					          
	plainTextBody = plainTextBody + matchName + matchCompany + '\n';
	htmlBody = htmlBody + '<li><a href=\'salesforceOrg' + matchId + '\'>' + matchName + '</a> - ' + matchCompany + '</li>';
}
			        
String htmlFooter = '</ul>';
				
String plainTextMessage = plainTextHeader + plainTextBody;
String htmlMessage = htmlHeader + htmlBody + htmlFooter;
				        
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'myemailaddress'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('myemailaddress');
mail.setSenderDisplayName('Salesforce.com Contact Validation Override');
mail.setSubject(subject);
mail.setPlainTextBody(plainTextMessage);
mail.setHtmlBody(htmlMessage);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

  • February 10, 2011
  • Like
  • 0

I have the following QueryString:

 

String QueryString = 'SELECT Id, Name, AccountId, Account.Name, Phone, Email, OwnerId, Owner.Alias, Active__c, Broker_Number__c, Broker_Number__r.Name, Account.Firm__c FROM Contact WHERE' + QueryActive;

 

 

I need to loop through the results and populate a list:

 

for(sObject o : Database.query(QueryString))
{
	SearchContact result = new SearchContact((Id)o.get('Id'),(String)o.get('Name'),(Id)o.get('AccountId'),(String)o.get('Account.Name'),(String)o.get('Phone'),(String)o.get('Email'),(Id)o.get('OwnerId'),(String)o.get('Owner.Alias'),(Boolean)o.get('Active__c'),(Id)o.get('Broker_Number__c'),(String)o.get('Broker_Number__r.Name'),(String)o.get('Account.Firm__c'));
	ContactResults.add(result);
}

 

 

I keep getting an error that 'Account.Name' is not a valid field for Contact. How am I supposed to retrieve the Account Name, Owner Alias, etc.?

 

Thanks.

  • March 01, 2011
  • Like
  • 0

 

I've recently added a couple of lines of code to a validation script I created in a trigger so that if a field is checked, after insert/update creates an email to be sent to me notifying me of the change. In the sandbox, the trigger works great and sends the email to me just once. However, in production the same trigger causes me to receive the email twice. Any thoughts?

 

Here's the email portion of the code:

 

String userName = UserInfo.getName();
String completeUser = UserInfo.getName() + ' (' + UserInfo.getUserName() + ')';
String triggerType;
				
if(trigger.isInsert) triggerType = 'adding';
if(trigger.isUpdate) triggerType = 'updating';
				        
String subject = userName + ' has overriden the Contact Validation script in Salesforce';
String plainTextHeader = completeUser + ' has overriden the Contact Validation script when ' + triggerType + ' ' + contactName + '\'s record in Salesforce. Here are matching records:\n';
String htmlHeader = '<h3><strong>' + completeUser + ' has overriden the Contact Validation script when ' + triggerType  + ' <a href=\'salesforceOrg' + contactId + '\'>' + contactName + '\'s</a> record in Salesforce. Here are matching records:</strong></h3><ul>';
String plainTextBody = '';
String htmlBody = '';
				
List<Account> a = [SELECT ParentId FROM Account WHERE Id =: branchId AND Home_Office__c != null];
firmId = a[0].ParentId;
				        
for (Contact c : [SELECT Id, Name, Account.Name FROM Contact WHERE Id !=: contactID AND Account.ParentId =: firmID AND Name =: contactName AND Active__c = True])
{
	Id matchId = c.Id;
	String matchName = c.Name;
	String matchCompany = c.Account.Name;
					          
	plainTextBody = plainTextBody + matchName + matchCompany + '\n';
	htmlBody = htmlBody + '<li><a href=\'salesforceOrg' + matchId + '\'>' + matchName + '</a> - ' + matchCompany + '</li>';
}
			        
String htmlFooter = '</ul>';
				
String plainTextMessage = plainTextHeader + plainTextBody;
String htmlMessage = htmlHeader + htmlBody + htmlFooter;
				        
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'myemailaddress'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('myemailaddress');
mail.setSenderDisplayName('Salesforce.com Contact Validation Override');
mail.setSubject(subject);
mail.setPlainTextBody(plainTextMessage);
mail.setHtmlBody(htmlMessage);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

  • February 10, 2011
  • Like
  • 0

I'm attempting to created a VF page that takes a zip (or series of zips) and create a paginated list of related Accounts. I'm having issues retrieving the data, namely receiving the Attempt to de-reference a null object error.

 

Here's my VF:

 

<apex:form >
	<apex:pageBlock title="Search by Zip">
		<apex:inputText value="{!zips}" />
		<apex:commandButton value="Search" action="{!find}" />
	</apex:pageBlock>

	<apex:pageBlock title="Nearby Company/Branch" rendered="{!zips != null}">
		<apex:pageBlockTable value="{!accounts}" var="acct" id="accountTable">
			<apex:column headerValue="Company/Branch">
				<apex:outputLink value="/{!acct.Id}" target="_top">{!acct.Name}</apex:outputLink>
			</apex:column>
			<apex:column headerValue="Address" colspan="2">
				<apex:outputText >{!acct.BillingStreet}, {!acct.BillingCity}, {!acct.BillingState}, {!acct.BillingPostalCode}</apex:outputText>
			</apex:column>
			<apex:column >
				<apex:outputLink value="http://maps.google.com/maps?f=d&source=s_d&saddr=&daddr={!acct.BillingStreet},{!acct.BillingCity},{!acct.BillingState},{!acct.BillingPostalCode}" target="_blank">Get Directions</apex:outputLink>
			</apex:column>
		</apex:pageBlockTable>
	</apex:pageBlock>

	<apex:panelGrid columns="4" style="margin-bottom: 25px;" rendered="{!zips != null}">
		<apex:commandLink action="{!first}" rendered="{!(pages > 1) && (hasPrevious)}">First</apex:commandLink>
		<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandLink>
		<apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandLink>
		<apex:commandLink action="{!last}" rendered="{!(pages > 1) && (hasNext)}">Last</apex:commandLink>
	</apex:panelGrid>
</apex:form>

 

Here's my controller class:

 

 

public with sharing class zipMap {
	
	public String zips { get; set; }
	
	public List<String> zList { get; set; }
	
	public ApexPages.StandardSetController accts { get; set; }
	
	public PageReference find() {

		zList = zips.split(',');

		String query = 'SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode FROM Account WHERE BillingPostalCode =: ' + zList + ' ORDER BY BillingPostalCode, Name';
		
		accts = new ApexPages.StandardSetController(Database.getQueryLocator(query));
		accts.setPageSize(2);
		
		return null;
	
	}
	
	public List<Account> getAccounts() {
		
		return (List<Account>) accts.getRecords();
		
	}
	
	public Boolean hasNext {
		
		get {
			
			return accts.getHasNext();
			
		}
		
		set;
		
	}
	
	public Boolean hasPrevious {
		
		get {
			
			return accts.getHasPrevious();
			
		}
		
		set;
		
	}
	
	public Integer pageNumber {
		
		get {
			
			return accts.getPageNumber();
			
		}
		
		set;
		
	}

	public Integer pages {
		
		get {
		
			pages = accts.getResultSize()/accts.getPageSize();
			
			return pages;
			
		}
		
		set;
		
	}
	
	public void first() { accts.first(); }
	
	public void last() { accts.last(); }

	public void cancel() { accts.cancel(); }
		
	public PageReference previous() {
		
		Integer p = accts.getPageNumber();
		
		if(hasPrevious) {
		
			accts.setPageNumber(p-1);
		
		}
		
		return null;
		
	}
	
	public PageReference next() {
		
		Integer p = accts.getPageNumber();
		
		if(hasNext) {
		
			accts.setPageNumber(p+1);
		
		}
		
		return null;
		
	}

}

 

 

Can someone please help? Thanks

 

Adriel

  • September 09, 2010
  • Like
  • 0