• Reppin505
  • NEWBIE
  • 5 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies
Desparately need some help. I cannot get this trigger to update the related acount record fromt the opportunity object.
 
trigger updateAccountsOnChange on Opportunity (before update) {

 
  Map<Id, Opportunity> oppWithNewEndDates = new Map<Id, Opportunity>();

for (Integer i = 0; i < Trigger.new.size(); i++) {
if ( (Trigger.old[i].Name != Trigger.new[i].Name)) {
oppWithNewEndDates.put(Trigger.old[i].id,Trigger.new[i]);
}

}

List<Account> updatedAccounts = new List<Account>();

for (Account c : [SELECT ID, Name FROM Account WHERE ID in ppWithNewEndDates.keySet()]) {
Opportunity parentOpportunity = oppWithNewEndDates.get(c.Id);
c.Description = parentOpportunity.Id;
//c.Salutation_Name__c = parentOpportunity.Name;
//c.Name = parentOpportunity.Name;

     updatedAccounts.add(c);
   }
  update updatedAccounts;
}
Desparately need some help. I cannot get this trigger to update the related acount record fromt the opportunity object.
 
trigger updateAccountsOnChange on Opportunity (before update) {

 
  Map<Id, Opportunity> oppWithNewEndDates = new Map<Id, Opportunity>();

for (Integer i = 0; i < Trigger.new.size(); i++) {
if ( (Trigger.old[i].Name != Trigger.new[i].Name)) {
oppWithNewEndDates.put(Trigger.old[i].id,Trigger.new[i]);
}

}

List<Account> updatedAccounts = new List<Account>();

for (Account c : [SELECT ID, Name FROM Account WHERE ID in :oppWithNewEndDates.keySet()]) {
Opportunity parentOpportunity = oppWithNewEndDates.get(c.Id);
c.Description = parentOpportunity.Id;
//c.Salutation_Name__c = parentOpportunity.Name;
//c.Name = parentOpportunity.Name;

     updatedAccounts.add(c);
   }
  update updatedAccounts;
}
Now i thought this was easier than it actually is.
 
I would like to pass the value from an Opportunity field into an Account field.
 
Of course i cannot use a formula field to do this. I'm wondering if i can update a field with an S-Control that queries the Opportunity table.
 
I already have the query set up.
 
var SearchString="Select Type, Membership_Status__c, Membership_End_Date__c from Opportunity where AccountId = '{!Account.Id}' And Membership_Status__c = 'Active'";
 
Now this will give me a number of records. But i would like to populate a field in the Account table with a value pulled from that query.
 
Unless there is another way of doing this.
 
Please help :)
var SearchString="Select Type, Membership_End_Date__c from Opportunity where AccountId = '{!Account.Id}' And Membership_End_Date__c > {!Today}";
 
When using the above query string i get the error:
 
Malformed query
And Membership_End_Date__c > 9/2/2008
                               ^
Unexpected Token: /
 
I have tried the wrap Membership_End_Date__c with Date() and DateValue() but continue to get the same error.
 
Any help would be greatly appreciated.
 
Desparately need some help. I cannot get this trigger to update the related acount record fromt the opportunity object.
 
trigger updateAccountsOnChange on Opportunity (before update) {

 
  Map<Id, Opportunity> oppWithNewEndDates = new Map<Id, Opportunity>();

for (Integer i = 0; i < Trigger.new.size(); i++) {
if ( (Trigger.old[i].Name != Trigger.new[i].Name)) {
oppWithNewEndDates.put(Trigger.old[i].id,Trigger.new[i]);
}

}

List<Account> updatedAccounts = new List<Account>();

for (Account c : [SELECT ID, Name FROM Account WHERE ID in ppWithNewEndDates.keySet()]) {
Opportunity parentOpportunity = oppWithNewEndDates.get(c.Id);
c.Description = parentOpportunity.Id;
//c.Salutation_Name__c = parentOpportunity.Name;
//c.Name = parentOpportunity.Name;

     updatedAccounts.add(c);
   }
  update updatedAccounts;
}