• Gabe Mejia
  • NEWBIE
  • 25 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 8
    Replies
I am trying to update the following 3 custom fields under my Member_Vendor_del__c custom object:

Vendor_ID__c
Member_Account_ID__c
Member_State__c

I have created the code below to update the Vendor_ID__c and Member_Account_ID__c

trigger VendorRepUpdateTrigger on Member_Vendor_del__c (before update) {
// Update the Vendor's ID, Member's ID, and Member's Physical State into the Member Vendor Record.    
    for (Member_Vendor_del__c u : trigger.new){
          if (u.Vendor_ID__c == null)
              u.Vendor_ID__c                 = u.Vendor__c;
              u.Member_Account_ID__c = u.Member__c;
  }
}


My issue is with getting Member_State__c to populate with the Physical State(API Field Name: BillingState) from the related member account. I have createdthe SOQL query below to return the string text value on the account but I keep getting the error "Illegal assignment from List to String"

// Update the Member's Physical State onto the Member Vendor Record.                       
     for (Member_Vendor_del__c u : trigger.new)
        if (u.Member_State__c == null)
                  u.Member_State__c = [Select BillingState
                                     From Account
                                     Where Account.Name = :u.Member__c];}


I can add .Id to the query and the error goes away but then the trigger wants to return a Salesforce ID rather than the 2 letter abbreviation for the State.

Question #1: What can I do to my SOQL query to return the text value rather than an ID?

Question #2: Can I add the SOQL query to the first part of the trigger? Something like:

trigger VendorRepUpdateTrigger on Member_Vendor_del__c (before update) {
// Update the Vendor's ID, Member's ID, and Member's Physical State into the Member Vendor Record.   
    for (Member_Vendor_del__c u : trigger.new){
          if (u.Vendor_ID__c == null)
              u.Vendor_ID__c         = u.Vendor__c;
              u.Member_Account_ID__c = u.Member__c;
              u.Member_State__c      = [Select Id, Account.BillingState
                                        From Account
                                           where Account_ID__c = :u.Member__c].Id;
 }
}
i have a custom field(Vendor_Rep__c) that i am trying tp update automatically when a record(Member Vendor) is created or edited.

I have created visualforce page, which i am starting to believe that i no longer need to acheive what i need.

Also, with some help, i have created the following code for an Apex Class: 

public class contactsearch {
        public Contact searchContact(string ContactType, string MemberState, String vendorId)
    {
        return[Select Name From Contact               Where Contact_Type__c = 'Vendor Rep' AND States__c = :MemberState AND Vendor__c = :vendorId limit 1];
             }
}



Lastly, after reading several questions already posted and a few Apex Developer Guide articles, i created the trigger below.

trigger VendorRepUpdateTrigger on Member_Vendor_del__c (before insert, after update) {
         
     for (Member_Vendor_del__c u : trigger.new);{
                u.Vendor_Rep__c = null;
     }
    
}



What i want to do is only if Vendor_Rep__c is blank/null, have the trigger use the parameters from the apex class to return with the name of the contact into the Vendor_Rep__c field. I want to eventually add in an additional factor to check against, the name of the county the contact services vs. the account's county.

 
Wondering if anyone would be able to assist. I am trying to perform a contactsearch that would return the name of a contact(or Salesforce ID) based on a couple cirteria. Any help is appreaciated.

User-added image
I am trying to update the following 3 custom fields under my Member_Vendor_del__c custom object:

Vendor_ID__c
Member_Account_ID__c
Member_State__c

I have created the code below to update the Vendor_ID__c and Member_Account_ID__c

trigger VendorRepUpdateTrigger on Member_Vendor_del__c (before update) {
// Update the Vendor's ID, Member's ID, and Member's Physical State into the Member Vendor Record.    
    for (Member_Vendor_del__c u : trigger.new){
          if (u.Vendor_ID__c == null)
              u.Vendor_ID__c                 = u.Vendor__c;
              u.Member_Account_ID__c = u.Member__c;
  }
}


My issue is with getting Member_State__c to populate with the Physical State(API Field Name: BillingState) from the related member account. I have createdthe SOQL query below to return the string text value on the account but I keep getting the error "Illegal assignment from List to String"

// Update the Member's Physical State onto the Member Vendor Record.                       
     for (Member_Vendor_del__c u : trigger.new)
        if (u.Member_State__c == null)
                  u.Member_State__c = [Select BillingState
                                     From Account
                                     Where Account.Name = :u.Member__c];}


I can add .Id to the query and the error goes away but then the trigger wants to return a Salesforce ID rather than the 2 letter abbreviation for the State.

Question #1: What can I do to my SOQL query to return the text value rather than an ID?

Question #2: Can I add the SOQL query to the first part of the trigger? Something like:

trigger VendorRepUpdateTrigger on Member_Vendor_del__c (before update) {
// Update the Vendor's ID, Member's ID, and Member's Physical State into the Member Vendor Record.   
    for (Member_Vendor_del__c u : trigger.new){
          if (u.Vendor_ID__c == null)
              u.Vendor_ID__c         = u.Vendor__c;
              u.Member_Account_ID__c = u.Member__c;
              u.Member_State__c      = [Select Id, Account.BillingState
                                        From Account
                                           where Account_ID__c = :u.Member__c].Id;
 }
}
i have a custom field(Vendor_Rep__c) that i am trying tp update automatically when a record(Member Vendor) is created or edited.

I have created visualforce page, which i am starting to believe that i no longer need to acheive what i need.

Also, with some help, i have created the following code for an Apex Class: 

public class contactsearch {
        public Contact searchContact(string ContactType, string MemberState, String vendorId)
    {
        return[Select Name From Contact               Where Contact_Type__c = 'Vendor Rep' AND States__c = :MemberState AND Vendor__c = :vendorId limit 1];
             }
}



Lastly, after reading several questions already posted and a few Apex Developer Guide articles, i created the trigger below.

trigger VendorRepUpdateTrigger on Member_Vendor_del__c (before insert, after update) {
         
     for (Member_Vendor_del__c u : trigger.new);{
                u.Vendor_Rep__c = null;
     }
    
}



What i want to do is only if Vendor_Rep__c is blank/null, have the trigger use the parameters from the apex class to return with the name of the contact into the Vendor_Rep__c field. I want to eventually add in an additional factor to check against, the name of the county the contact services vs. the account's county.

 
Wondering if anyone would be able to assist. I am trying to perform a contactsearch that would return the name of a contact(or Salesforce ID) based on a couple cirteria. Any help is appreaciated.

User-added image