function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lingannalinganna 

trigger on opportunity

hi

 

iam getting the below error   please suggest me.

thanks

 

Error: Compile Error: Invalid bind expression type of SOBJECT:Account for column of type Id at line 5 column 56

 

 

trigger score on Opportunity (after insert) {

for(Opportunity op:trigger.new)
{
account acc=[select id,score__c from account where id=:op.Account];
acc.score+=2;
update acc;
}
}

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,


Try the below code:


trigger score on Opportunity (after insert)
{
for(Opportunity op:trigger.new)
{
account acc=[select id,score__c from account where id=:op.Accountid];
acc.score__c+=2;
update acc;
}
}


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,


Try the below code:


trigger score on Opportunity (after insert)
{
for(Opportunity op:trigger.new)
{
account acc=[select id,score__c from account where id=:op.Accountid];
acc.score__c+=2;
update acc;
}
}


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer
RATNA BUJJI PRATTIPATIRATNA BUJJI PRATTIPATI
TRIGGER ON CONTACT


ERROR:Variable does not exist: OpportunityId at line 9 column 21
trigger UpdateContactProductLabel on Opportunity (after insert, after update) {
    List<Contact> contactsToUpdate = new List<Contact>();
    
    for (Opportunity opp : Trigger.new) {
        // Check if the Opportunity has a ContactId associated with it
        if (opp.ContactId != null) {
            // Retrieve the Contact related to the Opportunity
            Contact contact = [SELECT Id, Product_Label__c FROM Contact WHERE Id = :opp.ContactId LIMIT 1];
            
            // Update the Contact's field with the product label from the Opportunity
            contact.Product_Label__c = opp.Product_Label__c;
            
            contactsToUpdate.add(contact);
        }
    }
    
    if (!contactsToUpdate.isEmpty()) {
        update contactsToUpdate;
    }
}