• Dorian Sutton 9
  • NEWBIE
  • 55 Points
  • Member since 2015
  • Desynit


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 22
    Replies

Hi guys,

I'm trying to auto-populate the lookup field for a custom child object, which is called Purchase Item, with the same lookup field that its parent custom object, Purchase Order, has. The lookup field is called Supplier which is the standard object Account. 

I had a few goes in trying to create a trigger to auto-populate the supplier lookup field that would activate each time a new purchase item on a purchase order is created.

 

I'm not getting any errors with the following code but it does not seem to do what I want:

 

trigger populateSupplier on Purchase_Item__c (before insert , before update){
    
    Set<ID> setPIIds = new Set<ID>();
    for(Purchase_Item__c obj : trigger.new){
        if(obj.Supplier__c == null)
        setPIIds.add(obj.Supplier__c);
    }
    
     MAP<ID , Purchase_Order__c> mapPO = new MAP<ID , Purchase_Order__c>([Select Supplier__c from Purchase_Order__c where id in: setPIIds]);
     for(Purchase_Item__c obj : trigger.new)
       {
        if(obj.Supplier__c == null)
          {
            Purchase_Order__c c = mapPO.get(obj.Supplier__c);
            obj.Supplier__c = c.Supplier__c;
            //Similarly you can assign Address fields as well, just add those field in Contact SOQL as well
          }
       
       }
}

Thanks so much in advance!

I've been working on an Org where a very large number (over 20,000) of Contacts have been deleted, then emptied from the Recycle Bin.

The Recycle Bin was emptied several days ago, but the Contacts are still visible with IsDeleted = true with an ALL ROWS SOQL query.

All the Salesforce documentation says is that the time to permanently delete emptied recycle bin records will be 'usually 24 hours but may be longer or shorter'. 

We have raised a Case with Salesforce Support, who suggested using the emptyRecycleBin method, but this has not worked as the Recycle Bin no longer contains the records in question.

Because we are using an ALL ROWS query in another part of our application these deleted records are causing problems - does anybody have any suggestions about how I can remove them?
Hi,

I have created a custom record page which shows multiple action buttons in the hightlights panel. Is it possible to to disable or hide some of these buttons, e.g. depending on the contents of the record?
Hi, I am trying to a field from the active user in a component and use it in an if statement.

 <aura:if isTrue="{!$User.IsActive}">
    <td class="button"><a href="#" target="_blank">
               <lightning:button label="Join"/></a></td>
    <aura:set attribute="else">
        <td class="button"><a href="#" target="_blank">
               <lightning:button label="Renew Membership"/></a></td>
    </aura:set>
</aura:if>


I assume I am using the wrong syntax for {!$User.IsActive} as it always throws up the else and IsActive is definitely TRUE for the current user.

Thanks for any help
When i have workfloew and Process builder for field updates, why should i use apex tirggers for field updates? 
Hi, I have one question,

whithout using data loder how to insert 60000 records into salesfore.

Please let me if there have any way to overcome this

Thanks in advance
Hi,

I have a website in php. If any order place on my website then I want to save all order related information to salesforce account. What is the best way to do this ?  How to avoid governer limits for this also?

Thanks,
Rohitash

 

Hi guys,

I'm trying to auto-populate the lookup field for a custom child object, which is called Purchase Item, with the same lookup field that its parent custom object, Purchase Order, has. The lookup field is called Supplier which is the standard object Account. 

I had a few goes in trying to create a trigger to auto-populate the supplier lookup field that would activate each time a new purchase item on a purchase order is created.

 

I'm not getting any errors with the following code but it does not seem to do what I want:

 

trigger populateSupplier on Purchase_Item__c (before insert , before update){
    
    Set<ID> setPIIds = new Set<ID>();
    for(Purchase_Item__c obj : trigger.new){
        if(obj.Supplier__c == null)
        setPIIds.add(obj.Supplier__c);
    }
    
     MAP<ID , Purchase_Order__c> mapPO = new MAP<ID , Purchase_Order__c>([Select Supplier__c from Purchase_Order__c where id in: setPIIds]);
     for(Purchase_Item__c obj : trigger.new)
       {
        if(obj.Supplier__c == null)
          {
            Purchase_Order__c c = mapPO.get(obj.Supplier__c);
            obj.Supplier__c = c.Supplier__c;
            //Similarly you can assign Address fields as well, just add those field in Contact SOQL as well
          }
       
       }
}

Thanks so much in advance!

I've been working on an Org where a very large number (over 20,000) of Contacts have been deleted, then emptied from the Recycle Bin.

The Recycle Bin was emptied several days ago, but the Contacts are still visible with IsDeleted = true with an ALL ROWS SOQL query.

All the Salesforce documentation says is that the time to permanently delete emptied recycle bin records will be 'usually 24 hours but may be longer or shorter'. 

We have raised a Case with Salesforce Support, who suggested using the emptyRecycleBin method, but this has not worked as the Recycle Bin no longer contains the records in question.

Because we are using an ALL ROWS query in another part of our application these deleted records are causing problems - does anybody have any suggestions about how I can remove them?
I don't seem to be able to call the following class from the Process Builder:

I know this could be written as a trigger, but I would prefer to do this from the Process Builder if that is possible as it is easier to manage all the Process flows from here.  Does this makes sense?

How can I modify this code to allow it to be called from the Process Builder?
 
public class POContactsController{
@InvocableMethod(Label='Insert PO Contacts')


    string poid;
    string vendorId;
    string contactid;
    
    public pageReference POContacts()
    {
       //Ensures that there is a Vendor on the PO or returns an error
       
        if (string.IsBlank(vendorid))
        {
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No Vendor selected on the Work Order'));
            return null;
        }
        
        //Deletes any items if they already exist
        
          List<unifize__PO_Contact__c> existingpocontacts = [select ID from unifize__PO_Contact__c where unifize__Purchase_Order__c = :poid];
        if(existingpocontacts.size() != 0)
        {
        delete existingpocontacts;
        }
        
        //Checks that there are Contacts assigned to POs on the related Contacts and returns error if not
        
        List<Contact> Contactlist = [select ID, Email, MobilePhone, Phone, Name FROM Contact where unifize__Purchase_Orders__c=TRUE AND Accountid = :VendorId];
        if (Contactlist.size() == 0)
        {
        ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No Contacts assigned to receive POs for this Vendor'));
        System.debug('Contact List Size' + Contactlist.size());
        return null;
        }
         
        List<unifize__PO_Contact__c> POContactList = new List<unifize__PO_Contact__c>();
        
        for (Contact POContactItem : ContactList)
        {
        
        unifize__PO_Contact__c newpocontact = new unifize__PO_Contact__c();
        newpocontact.unifize__Contact__c=contactid;
     
            POContactList.add(newpocontact);
            
        }
        if (POContactList.size() > 0)
        {
            insert POContactList;
        }
        return new PageReference('/' + poId);
    }
}