-
ChatterFeed
-
4Best Answers
-
0Likes Received
-
0Likes Given
-
65Questions
-
59Replies
SOQL - query related contact - update field - most recent date
So here's the use case.
I have a custom object (Order__c) which has a lookup to a Contact (Vendor_Name__c, on the Order Object). Contacts do not have lookups to Order.
On the Order, there is a Valuation_Contracted_Date__c field. A contact can have multiple Orders (10, 50, 150) - and i'd like for this trigger to always set on the Contact (Last_Engaged_Date__c) to the latest Contracted Date.
So I think I have something...but it needs help. Right now the error is "Save error: Didn't understand relationship 'Order__c' in FROM part of query call."
tldr; query all orders on that contact, order by valuation contracted date descending, limit 1. take that date and update the contact with it.
trigger lastEngagedDate on Order__c (before insert, before update) { try { for(Order__c o : Trigger.new) { Contact c = [SELECT Last_Engaged_Date__c, (SELECT Valuation_Contracted_Date__c FROM Order__c WHERE c.Id = :Vendor_Name__c ORDER BY Valuation_Contracted_Date__c DESC LIMIT 1) FROM Contact WHERE Id = :o.Vendor_Name__c]; if(o.Status__c == 'Valuation Received') { c.Last_Engaged_Date__c = o.Valuation_Contracted_Date__c; update c; } } } catch(Exception e) { } }
Attempt #2 - still doesn't work?
trigger lastEngagedDate on Order__c (before insert, before update) { try { for(Order__c o : Trigger.new) { Contact c = [SELECT Id, Last_Engaged_Date__c FROM Contact WHERE Id = :o.Vendor_Name__c]; Order__c o = [SELECT Valuation_Contracted_Date__c FROM Order__c WHERE c.Id =:o.Vendor_Name__c ORDER BY Valuation_Contracted_Date__c LIMIT 1]; if(o.Status__c == 'Valuation Received') { c.Last_Engaged_Date__c = o.Valuation_Contracted_Date__c; update c; } } } catch(Exception e) { } }
- tsalb
- February 17, 2012
- Like
- 0
- Continue reading or reply
Apex Trigger Error: Record is Read-Only
I'm getting this error when I try to update a contact record:
Review all error messages below to correct your data.
Apex trigger ContactStageTrigger caused an unexpected exception, contact your administrator: ContactStageTrigger: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.ContactStageTrigger: line 6, column 1
Here is my Code:
trigger ContactStageTrigger on Contact (after insert, after update) { Contact myContact = trigger.new[0]; Account myAccount = [SELECT OwnerId FROM Account WHERE Id = :myContact.AccountId]; if(myContact.Status__c == 'Prospect'){ myContact.OwnerId = myAccount.OwnerId; update myContact; } }
- Mike @ BlackTab
- February 15, 2012
- Like
- 0
- Continue reading or reply
Help with' List has more than 1 row for assignment to SObject'
Evening World,
I am using the following Apex Trigger and Test Class:
trigger AutoAllocateDelegatesToTrainingActions on Training__c (before insert) { { List<Employee_Training_Action__c> listETA = new List<Employee_Training_Action__c> (); for (Training__C T : trigger.new) if(Trigger.isInsert) { Employees__c Emp = [SELECT Id FROM Employees__c WHERE Works_Nights_Weekdays__c = TRUE]; listETA.add(new Employee_Training_Action__c( Training_Action__c = T.id, Employee__c = Emp.id)); if(listETA.size() >0) { insert listETA; } } } }
@isTest private class Test_TA_DelegateAllocation { static testMethod void myUnitTest9() { Service_Agreement__c SA = new Service_Agreement__c (); SA.Name = 'Test SA'; insert SA; Training__c TR = new Training__c (); TR.Service_Agreement__c=SA.Id; insert TR; Employee_Training_Action__c ETA = new Employee_Training_Action__c (); ETA.Training_Action__c=TR.Id; ETA.Employee__c = 'a0l20000001IYYN'; try{ insert ETA;} catch(System.DmlException e){ System.debug('we caught a dml exception: ' + e.getDmlMessage(0)); } } }
However, when deploying to production I am getting the following error:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoAllocateDelegatesToTrainingActions: execution of BeforeInsert
caused by: System.QueryException: List has more than 1 row for assignment to SObject
Trigger.AutoAllocateDelegatesToTrainingActions: line 10, column 23: []
I understand what the error is saying, and it is correct, there will be more than one record to create, however, how do i tell the system that this is 'ok'!
Help much apprecaited.
Steve
- GRStevenBrookes
- January 28, 2012
- Like
- 0
- Continue reading or reply
SSL Issue
- tric
- November 16, 2012
- Like
- 0
- Continue reading or reply
IP Address and salesforce
- tric
- November 15, 2012
- Like
- 0
- Continue reading or reply
IP address
- tric
- November 15, 2012
- Like
- 0
- Continue reading or reply
IP whitelist
- tric
- November 14, 2012
- Like
- 0
- Continue reading or reply
Integration issue
- tric
- November 13, 2012
- Like
- 0
- Continue reading or reply
Integration issue
- tric
- November 13, 2012
- Like
- 0
- Continue reading or reply
Visual force error
- tric
- November 13, 2012
- Like
- 0
- Continue reading or reply
salesforce Licenins issue
- tric
- November 06, 2012
- Like
- 0
- Continue reading or reply
Salesforce and Remote Site settings
- tric
- October 25, 2012
- Like
- 0
- Continue reading or reply
Remote site settings problem
- tric
- October 25, 2012
- Like
- 0
- Continue reading or reply
Vidsual force and Portal
- tric
- October 24, 2012
- Like
- 0
- Continue reading or reply
Salesforce Portal and another portal
- tric
- October 24, 2012
- Like
- 0
- Continue reading or reply
Execution of Apex class
- tric
- September 05, 2012
- Like
- 0
- Continue reading or reply
Iframe applicatiion and bug in the URL
- tric
- September 05, 2012
- Like
- 0
- Continue reading or reply
Exception
- tric
- August 23, 2012
- Like
- 0
- Continue reading or reply
Rich Text field
- tric
- August 20, 2012
- Like
- 0
- Continue reading or reply
VIsual force page ,Class and IFrame
- tric
- August 20, 2012
- Like
- 0
- Continue reading or reply
Rich text field problem
- tric
- August 08, 2012
- Like
- 0
- Continue reading or reply
Flow and text at the end of the completion of the text
- tric
- August 07, 2012
- Like
- 0
- Continue reading or reply
visualforce
- tric
- August 06, 2012
- Like
- 0
- Continue reading or reply
IP Address and salesforce
- tric
- November 15, 2012
- Like
- 0
- Continue reading or reply
Integration issue
- tric
- November 13, 2012
- Like
- 0
- Continue reading or reply
Salesforce and Remote Site settings
- tric
- October 25, 2012
- Like
- 0
- Continue reading or reply
Execution of Apex class
- tric
- September 05, 2012
- Like
- 0
- Continue reading or reply
Iframe applicatiion and bug in the URL
- tric
- September 05, 2012
- Like
- 0
- Continue reading or reply
Flow and text at the end of the completion of the text
- tric
- August 07, 2012
- Like
- 0
- Continue reading or reply
visual force and sites
Hi Friends, We have customer portal and we want to capture logged in user information such as password .We are using default salesforce portal functionality. can somebody give an example of how to do it? Thanks, Trick
- trick.ax1374
- August 02, 2012
- Like
- 0
- Continue reading or reply
Visualforce and Javascript
Hi Friends,
I have visual force tab in salesforce.So when somebody navigates away from the tab ,for example,clicks on some other tab then he should see a dialog box which says that,Are u sure that you want to naviage away from this page?
Below given code does not belong to me.However,it does run and show dialog box with the message:-
This page is asking you to confirm that you want to leave - data you have entered may not be saved
How do I override this message or show my own message.
public class wrap2co {
String searchSolutionText;
List<List<sObject>> tresults;
List<Solution> results;
public String getSearchSolutionText() {
return searchSolutionText;
}
public void setSearchSolutionText(String s) {
searchSolutionText = s;
}
public List<Solution> getResults() {
return results;
}
public PageReference doSearch() {
tresults = [FIND :searchSolutionText RETURNING Solution(SolutionName, SolutionNote, CreatedDate)];
results = (List<Solution>)tresults[0];
return null;
}
}
<apex:page controller="wrap2co">
<script LANGUAGE="JavaScript1.2" TYPE="text/javascript">
function unloadMessage(){
message = "Wait! You haven't finished."
return message;
}
function setBunload(on){
window.onbeforeunload = (on)? unloadMessage : null;
}
setBunload(true);
</script>
<apex:form >
<apex:pageBlock >
<apex:pageblockButtons >
<apex:commandButton action="{!doSearch}" value="Search" rerender="output"></apex:commandButton>
</apex:pageblockButtons>
<apex:inputText value="{!SearchSolutionText}"></apex:inputText>
</apex:pageBlock>
<apex:outputPanel >
<apex:pageBlock >
<apex:pageblockTable value="{!results}" var="v">
<apex:column value="{!v.SolutionName}"/>
<apex:column value="{!v.SolutionNote}"/>
<apex:column value="{!v.CreatedDate}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>
Thanks,
Trick
- trick.ax1374
- July 20, 2012
- Like
- 0
- Continue reading or reply
Visualforce and Portal
Hi Friends,
My scenario is such that only when customer logs into the portal then tab on the portal should become visible.if he is not logged in then it should not become visible to the customer. Any idea on how we can do this.Some attributes or something else.
Any info or any example on this is highly welcome.If u can point to any link which can help me in accomplisihing this will be great.
Thanks,
Trick
- trick.ax1374
- June 15, 2012
- Like
- 0
- Continue reading or reply
Displaying website in the Iframe
- tric
- June 07, 2012
- Like
- 0
- Continue reading or reply
Hosting of application in salesforce
Hi Guys,
Can we host flex application in salesforce.If not why ,Can somebody answer.
Thanks,
Chinglish
- trick1
- May 14, 2012
- Like
- 0
- Continue reading or reply
Calendar and Events
Hi Friends,
Can we assign events to calendars in salesforce and make it vsible on the calendar.Quick response will be greatly appreciated.
Thanks,
Trick
- trick1
- May 11, 2012
- Like
- 0
- Continue reading or reply
Creation of PDF from an even object object record.
Hi Friends,
I want to create PDF file from the record of an event object.Does anyone know how to go about it?
If there is some example of how they have done it?
Thanks,
Trick
- tric
- May 07, 2012
- Like
- 0
- Continue reading or reply
Web Services
Hi Friends,
Consumer Key
Consumer Secret
I need to know,for example, when I register some website in the remote setting in salesforce in order to make callouts.
Consumer Key means what Does it belongs to salesforce or the website which was registered in salesforce.
Is it same about consumer secret.
Can somebody please explain with an example ?.
Thanks
Trick
- trick1
- March 29, 2012
- Like
- 0
- Continue reading or reply
Integration,Please help
Hi Friends,
I have customer portal and on that portal I have link which should take me to the another web site
side
Scenario:-
If somebody is on the customer portal and he is logged in the portal and then clicks on the link.It should be verified whether the customer has been logged in and if he is then he should be taken to another website without having to log into the web site.
Can somebody please tell me how to go about it.Please guide me in the right direction by giving me a start.
Basically integrating one website with another web site.
Thanks,
Trick
- trick1
- March 26, 2012
- Like
- 0
- Continue reading or reply
SOQL statement and dynamic query
Hi Friends,
I have input text field and search button next to the field. I want to generate soql query in the controller class function.
When somebody enters something in the input field and click on the search field it should assign that value to the Soql statements where clause .It should looks something like this.
database.query(select id,name from account where name=What should I be doing there And how to do that);
I knoe I have to use setter method but How do I link inputetxt field and pass its value to the soql query.
Please help.
Trick
SELECT Id, Name FROM Account WHERE Name = 'Sandy
- tric
- March 12, 2012
- Like
- 0
- Continue reading or reply
Trigger unable to update old records into custom field
Hi
I have a trigger OpenActivityCount to get the count of the open tasks created on the open activity related list. The count of the tasks appear on the No. of Open Activities field.
I am getting a problem here.
The issue is all the new tasks created after I have deployed the tigger are getting populated in the field whereas the older tasks are not being populated. I want the total count of the open tasks in the field before and after I have deployed the trigger.
Can anyone please tell me how to overcome this issue.
This is the trigger
trigger OpenActivityCount on Task(after insert,after update)
{
if(trigger.new[0].AccountId!=null)
{
Account ac=[select id, No_of_Open_Activities__c from Account where id=:trigger.new[0].AccountId];
if(ac!=null)
{
if(ac.No_of_Open_Activities__c == null)
ac.No_of_Open_Activities__c =0;
if(trigger.isinsert) {
if(trigger.new[0].status!='Completed') {
ac.No_of_Open_Activities__c +=1;
}
}
if(trigger.isupdate )
{
if(trigger.new[0].status == 'Completed')
ac.No_of_Open_Activities__c -= 0.5;
if(trigger.new[0].status != 'Completed')
ac.No_of_Open_Activities__c += 0.5;
}
update ac;
}
}
}
- Finney
- February 29, 2012
- Like
- 0
- Continue reading or reply
WSDL file User name and password.
Hi Friends,
When we buy web services from websites such as strikeiron etc then in the stub classes we have to specify user name and pasword.
My question is how do we get that username and password.?.Is there a way to generate?
Please help.
Thanks,
Trick
- tric
- February 26, 2012
- Like
- 0
- Continue reading or reply
What is Salesforce IP address range?
- MattAustin
- April 18, 2008
- Like
- 0
- Continue reading or reply