• Azeddine
  • NEWBIE
  • 0 Points
  • Member since 2013

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

trigger campaign_update on Opportunity (after insert,after update) {

//This trigger looks for the first contact in Account, then adds a campaignmember to the proper campaign

Opportunity[] opportunities = Trigger.new;
for (Integer i = 0; i < opportunities .size(); i++) {
Contact contact;
boolean foundContactId = false;
boolean respondedtocampaign = false;

//Verifiy that this record has a related account and a priamry campaign
if (opportunities[i].AccountId != null && opportunities[i].campaign != null) {
//Get related contactID (one and only one contact per account)
try {
contact = [SELECT Id FROM Contact WHERE AccountId = :opportunities[i].AccountId limit 1];
foundContactId = true;
} catch (Exception e){
//Found no contact on this account
}

//Check if related contact already has a a primary campaign
if (foundContactId) {
try {
Campaignmember c = [SELECT campaignID FROM campaignmember WHERE ContactID = : contact.Id AND
CampaignID = :opportunities[i].campaign limit 1];

} catch (Exception e){
//Found no primary campaign
respondedtocampaign = true;
}
}
//If reservation exists for this contact then book it
if (foundContactId && respondedtocampaign) {
// Add a new reservation to related seminar
CampaignMember cm= new CampaignMember(CampaignID = opportunities[i].Campaign,
ContactID=contact.Id,
Status='Responded');
//Insert the new reservation
insert cm;
}
}
}


}

 

 

The error is the following :

 

Error: Compile Error: Invalid bind expression type of SOBJECT:Campaign for column of type Id at line 25 column 117

 

Any idea why is this error happening ?

I am trying to update the account phone based on the contact phone. See tigger below.

 

trigger UpdatePhone on Contact (after insert, after update) {
List<id> Accountids = new List<id>
list<Account> Accounts = new List<Account>
List <Contact> Contacts = new List <contact>
for(contact c:Trigger.new){
if(c.accountid!=Null){
Accountids.add(c.accountid);
}
}
Accounts=[select Id,Phone from Account where Id in:accountids]
for (contact c:Trigger.new) {
for (Account Acc in:Accounts){
if(c.accountid==acc.id){
acc.phone=c.phone;
}
}
update(acc);
}

 

I am getting the following eror

Error: Compile Error: unexpected token: 'list' at line 3 column 4

 

 

Can anyone help ?

trigger campaign_update on Opportunity (after insert,after update) {

//This trigger looks for the first contact in Account, then adds a campaignmember to the proper campaign

Opportunity[] opportunities = Trigger.new;
for (Integer i = 0; i < opportunities .size(); i++) {
Contact contact;
boolean foundContactId = false;
boolean respondedtocampaign = false;

//Verifiy that this record has a related account and a priamry campaign
if (opportunities[i].AccountId != null && opportunities[i].campaign != null) {
//Get related contactID (one and only one contact per account)
try {
contact = [SELECT Id FROM Contact WHERE AccountId = :opportunities[i].AccountId limit 1];
foundContactId = true;
} catch (Exception e){
//Found no contact on this account
}

//Check if related contact already has a a primary campaign
if (foundContactId) {
try {
Campaignmember c = [SELECT campaignID FROM campaignmember WHERE ContactID = : contact.Id AND
CampaignID = :opportunities[i].campaign limit 1];

} catch (Exception e){
//Found no primary campaign
respondedtocampaign = true;
}
}
//If reservation exists for this contact then book it
if (foundContactId && respondedtocampaign) {
// Add a new reservation to related seminar
CampaignMember cm= new CampaignMember(CampaignID = opportunities[i].Campaign,
ContactID=contact.Id,
Status='Responded');
//Insert the new reservation
insert cm;
}
}
}


}

 

 

The error is the following :

 

Error: Compile Error: Invalid bind expression type of SOBJECT:Campaign for column of type Id at line 25 column 117

 

Any idea why is this error happening ?

I am trying to update the account phone based on the contact phone. See tigger below.

 

trigger UpdatePhone on Contact (after insert, after update) {
List<id> Accountids = new List<id>
list<Account> Accounts = new List<Account>
List <Contact> Contacts = new List <contact>
for(contact c:Trigger.new){
if(c.accountid!=Null){
Accountids.add(c.accountid);
}
}
Accounts=[select Id,Phone from Account where Id in:accountids]
for (contact c:Trigger.new) {
for (Account Acc in:Accounts){
if(c.accountid==acc.id){
acc.phone=c.phone;
}
}
update(acc);
}

 

I am getting the following eror

Error: Compile Error: unexpected token: 'list' at line 3 column 4

 

 

Can anyone help ?