• GuanDong
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
Hi there!


I'm a newbie and I'd like to ask you if somebody could write a trigger for me that is able to change the Account owner with the User a new Event is assigned to.


Thanks a lot,


Kind Regards
Hello!

Here's my code to update a lookup field value (Campagna_Account__c) on an Account object using a trigger that update it getting the value from a custom object (Sottocampagna__c):
trigger PopolaCampagna on Account (before insert, before update) {

    Sottocampagna__c var = [

        SELECT Campagna__r.Id
        FROM Sottocampagna__c
        WHERE Name='Segugio'
   
    ];

   for (Account a: Trigger.new) {
   a.Campagna_Account__c = var.Campagna__r.Id;

}

Now my question is: how can I substitute the value 'Segugio' with a variable that pick up the value of a particular field on Account object called Sottocampagna__r.Name?

I'm a newbie, and your answer let me learn tons of things...

Thank you so much
 
I'm just trying to update a lookup field value (Campagna_Account__c) on Account object using a trigger that should update it getting the value from a custom object (Sottocampagna__c).
I think the query is right because it runs well on Force.com Explorer, so I think the problem is somewhere else.

Here's the error line displayed when trigger fires:

data changed by trigger for field Campagna: id value of incorrect type: a06250000004FDNAA2

Here's my code:
trigger PopolaCampagna on Account (before insert, before update) {

Sottocampagna__c var = [
SELECT Campagna__r.Id
FROM Sottocampagna__c
WHERE Name='Segugio'

];

for (Account a: Trigger.new) {
a.Campagna_Account__c = var.Id;
   }
}
Thank you for helping me!

 
Hi there!


I'm a newbie and I'd like to ask you if somebody could write a trigger for me that is able to change the Account owner with the User a new Event is assigned to.


Thanks a lot,


Kind Regards
Hello!

Here's my code to update a lookup field value (Campagna_Account__c) on an Account object using a trigger that update it getting the value from a custom object (Sottocampagna__c):
trigger PopolaCampagna on Account (before insert, before update) {

    Sottocampagna__c var = [

        SELECT Campagna__r.Id
        FROM Sottocampagna__c
        WHERE Name='Segugio'
   
    ];

   for (Account a: Trigger.new) {
   a.Campagna_Account__c = var.Campagna__r.Id;

}

Now my question is: how can I substitute the value 'Segugio' with a variable that pick up the value of a particular field on Account object called Sottocampagna__r.Name?

I'm a newbie, and your answer let me learn tons of things...

Thank you so much
 
I'm just trying to update a lookup field value (Campagna_Account__c) on Account object using a trigger that should update it getting the value from a custom object (Sottocampagna__c).
I think the query is right because it runs well on Force.com Explorer, so I think the problem is somewhere else.

Here's the error line displayed when trigger fires:

data changed by trigger for field Campagna: id value of incorrect type: a06250000004FDNAA2

Here's my code:
trigger PopolaCampagna on Account (before insert, before update) {

Sottocampagna__c var = [
SELECT Campagna__r.Id
FROM Sottocampagna__c
WHERE Name='Segugio'

];

for (Account a: Trigger.new) {
a.Campagna_Account__c = var.Id;
   }
}
Thank you for helping me!