• Ross Hopkins 8
  • NEWBIE
  • 10 Points
  • Member since 2017
  • Digital Solution Architect
  • Silver Chef Limited


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 7
    Replies
Hi,
I'm trying to lookup an Account ID based on a text value.

Visitors who submit a form on our website can provide a "Dealer Name" value in a free text field. I want to use that value to search for an AccountID based on if the web visitor provided text is LIKE an Account.Trading_Name__c.

The code is as follows:
trigger Shopify_Set_Dealer_Account on Opportunity (before insert) {
    for(Opportunity o: trigger.new){
    
        /* 
            Only look up and set a Dealer_Account__c Id value if a Dealer Name text value is present, 
            this is a CUE Rental Opp and we haven't somehow set an Id before.
            Oppty_Dealer_Name__c is a Dealer Name text value provided in forms by visitors to SC websites
        */
        
        if((o.Oppty_Dealer_Name__c != NULL) && (o.Name.contains('CUE Rental') && (o.Dealer_Account__c == NULL))){
        
            // Construct SOQL query as a string variable first, as Apex doesn't make it easy to use LIKE %<variable>% syntax
            string Query = 'SELECT Id from Account WHERE Trading_Name__c LIKE' + '/%' + o.Oppty_Dealer_Name__c+ '/%' + 'LIMIT 1';
            
            // Execute the query
            Account[] DealerAccount = Database.query(Query); 
            
            /* 
                Only assign the found Dealer Account Id if we were able to match the website-provided Dealer Name value to a Dealer Account 
                Trading Name value, otherwise we'll get an error when we try to access the array element
            */
            if (DealerAccount.size() == 1) {
                o.Dealer_Account__c = DealerAccount[0].Id;
            }
            
        }
    }
}
However, I get the following error when this trigger is executed:
Shopify_Set_Dealer_Account: execution of BeforeInsert caused by: System.QueryException: line 1:49 no viable alternative at character '%' ().
I'm assuming this relates to lines 13 or 16.
I've searched online a lot for this problem and followed advice I'd seen about constructing the query first, but I'm having no joy.
Any advice?
Thanks,
Ross
 
Hi,
I have written a trigger that runs on Product2 Before Insert. The outcome is that a set of comma delimited key:value pairs stored in a text field are copied into their respective custom fields.

In the most part this is working, however peridoically I receive the following error:
Sandbox

Apex script unhandled trigger exception by user/organization: 0055xxxxxxxwzY/00Dxxxxxx8W
Source organization: xxxxxxxxteA (null)
Shopify_Split_Tags_Field_v1: execution of BeforeInsert

caused by: System.ListException: List index out of bounds: 1

()
The code is:
trigger Shopify_Split_Tags_Field_v1 on Product2 (before insert) {
    for(Product2 p: trigger.new){
        if(p.wk_shopify__Shopify_Tag__c != null){
            List<string>tags = p.wk_shopify__Shopify_Tag__c.split(',');
            
            if(tags.size() > 0) {
                for(string t: tags){
                    if(t.contains('age')){
                        p.Asset_Age__c = t.split(':')[1];
                    }
            
                    if(t.contains('assetcondition')){
                        p.Asset_Condition__c = t.split(':')[1];
                    }
            
                    if(t.contains('location')){
                        p.Asset_Location__c = t.split(':')[1];
                    }
            
                    if(t.contains('manufacturer')){
                        p.Asset_Manufacturer__c = t.split(':')[1];
                    }
                    
                    if(t.contains('make')){
                        p.Asset_Make__c = t.split(':')[1];
                    }
            
                    if(t.contains('model')){
                        p.Asset_Model__c = t.split(':')[1];
                    }
                    
                    if(t.contains('shipping')){
                        p.Shipping_Code__c = t.split(':')[1];
                    }
                
                    if(t.contains('power')){
                        p.Asset_Power__c = t.split(':')[1];
                    }
            
                    if(t.contains('rentalstatus')){
                        p.Asset_Rental_Status__c = t.split(':')[1];
                    }
            
                    if(t.contains('serial')){
                        p.Asset_Serial__c = t.split(':')[1];
                    }
            
                    if(t.contains('subcatcode')){
                        p.Asset_Subcatcode__c = t.split(':')[1];
                    }
                }
            }
        }    
    }
}
I've been reading about what the error means, and it would seemingly be that I'm trying to read an array element that doesn't exist. I added the size check of tags to try and avoid this, but that hasn't worked.

What am I missing?

Thanks,
Ross
 
Hi all, 
I have a text field against the Opportunity object that sometimes contains data such as:

0123456,0234567,0345678 etc

There could sometimes only be one value and on other occasions there might be 10 or so.

When this field is populated I'd like to use these IDs to lookup a Product record (via a custom SKU field) and subsequently create an OpportunityProduct record linked to the Opportunity.

What is the best approach here? I'm not an Apex developer although I have written simple triggers after gaining advice and examples from the community previously. I started to experiment in Flow, but stumbled early on when I couldn't see a way to split the comma seperated text value

Looking forward to your advice.
Thanks,
Ross
Hi!

I have a field against the Product object, Tags, which contains data such as the following, imported from a thrid-party system:
age:< 12 Months, assetcondition:BRONZE, location:LAVERTON, make:POS SYSTEM, model:3212, power:SIN10AMP, rentalstatus:AVAIL-W, serial:100285954, subcatcode:Swift Assets
When these Product records are created I want to use formulas in a Process Builder Workflow action to extract each "key:<value>" pair, storing all <value>'s in custom fields.

As an example based on the above, one of the formulas would search for "location:" and store "LAVERTON" as the value in a "location__c" field against the Product record. I'd want to do this for age, assetcondition, assetlocation, make etc etc.

I can see lots of examples of using LEFT and MID but haven't been able to create a dynamic enough formula - data in this tags field will vary a lot, so I can't specifiy exact start and end text positions.

Any advice appreciated!

Thanks
Hi,
I'm having an issue inserting into OpportunityContactRole from another custom object in Flow Designer. This is required to link Opportunities in Salesforce to related Prospect records in Pardot.

The data objects involved in this scenario are Opportunity and a related custom object called Applicant. There may be 1 or more Applicants related to one Opportunity. My objective is to insert a row into OpportunityContactRole for each Applicant.

Applicant is setup as follows:
Applicant Custom Object

I have a Process Builder Workflow that calls a flow depending on a criteria. This step is working as expected. I pass an OpportunityID parameter into the flow.
In the flow, the first thing I do is perform a Fast Lookup to retrieve all Applicants linked to an Opportunity. This lookup looks like this:

User-added image
Before I go into more detail, is this correct? I have assumed the Application__c variable is an OpportunityID but I have my doubts whether this is the case?
Subsequent steps loop through the retrieved array (sobject variable) of Applicants and insert a record into OpportunityContactRole. However, that will not work if I'm not looking up the Opportunity correctly.
Any advice appreciated. I appreciate that rather than having the Applicant custom object in the first place it would've been easier to soley use OpportunityContactRole with a new role of Applicant but I'm not permitted to make that change.
Thanks,
Ross
Hi all,

We have a Drupal website making use of the SalesForce Suite (https://www.drupal.org/project/salesforce) and SalesForce Webforms (https://www.drupal.org/node/2298941) modules to transmit webform submissions into SalesForce. They've been working well for over a year now.

However, we're about to launch a French site and are having difficulties with any value that contains accents. A quick Google tells me so do many other people, regardless of implementation, but I can't find a solution.

Does anyone have any experience of this or advice?

Thanks,

Ross
Pardot will only list Opportunities against a Prospect if the Prospect is present in the Contact Roles related list.

I have a SF Process Builder Workflow successfully creating Opportunities when a specific Contact custom field is updated by the Pardot Connector. But it isn't possible to set or create a Contact Role record in the Process Builder.

So is there a way around this? I'm pretty good with creating workflows but apex code would be beyond me.

Thanks,
Ross
Hi,
I'm trying to lookup an Account ID based on a text value.

Visitors who submit a form on our website can provide a "Dealer Name" value in a free text field. I want to use that value to search for an AccountID based on if the web visitor provided text is LIKE an Account.Trading_Name__c.

The code is as follows:
trigger Shopify_Set_Dealer_Account on Opportunity (before insert) {
    for(Opportunity o: trigger.new){
    
        /* 
            Only look up and set a Dealer_Account__c Id value if a Dealer Name text value is present, 
            this is a CUE Rental Opp and we haven't somehow set an Id before.
            Oppty_Dealer_Name__c is a Dealer Name text value provided in forms by visitors to SC websites
        */
        
        if((o.Oppty_Dealer_Name__c != NULL) && (o.Name.contains('CUE Rental') && (o.Dealer_Account__c == NULL))){
        
            // Construct SOQL query as a string variable first, as Apex doesn't make it easy to use LIKE %<variable>% syntax
            string Query = 'SELECT Id from Account WHERE Trading_Name__c LIKE' + '/%' + o.Oppty_Dealer_Name__c+ '/%' + 'LIMIT 1';
            
            // Execute the query
            Account[] DealerAccount = Database.query(Query); 
            
            /* 
                Only assign the found Dealer Account Id if we were able to match the website-provided Dealer Name value to a Dealer Account 
                Trading Name value, otherwise we'll get an error when we try to access the array element
            */
            if (DealerAccount.size() == 1) {
                o.Dealer_Account__c = DealerAccount[0].Id;
            }
            
        }
    }
}
However, I get the following error when this trigger is executed:
Shopify_Set_Dealer_Account: execution of BeforeInsert caused by: System.QueryException: line 1:49 no viable alternative at character '%' ().
I'm assuming this relates to lines 13 or 16.
I've searched online a lot for this problem and followed advice I'd seen about constructing the query first, but I'm having no joy.
Any advice?
Thanks,
Ross
 
Hi,
I have written a trigger that runs on Product2 Before Insert. The outcome is that a set of comma delimited key:value pairs stored in a text field are copied into their respective custom fields.

In the most part this is working, however peridoically I receive the following error:
Sandbox

Apex script unhandled trigger exception by user/organization: 0055xxxxxxxwzY/00Dxxxxxx8W
Source organization: xxxxxxxxteA (null)
Shopify_Split_Tags_Field_v1: execution of BeforeInsert

caused by: System.ListException: List index out of bounds: 1

()
The code is:
trigger Shopify_Split_Tags_Field_v1 on Product2 (before insert) {
    for(Product2 p: trigger.new){
        if(p.wk_shopify__Shopify_Tag__c != null){
            List<string>tags = p.wk_shopify__Shopify_Tag__c.split(',');
            
            if(tags.size() > 0) {
                for(string t: tags){
                    if(t.contains('age')){
                        p.Asset_Age__c = t.split(':')[1];
                    }
            
                    if(t.contains('assetcondition')){
                        p.Asset_Condition__c = t.split(':')[1];
                    }
            
                    if(t.contains('location')){
                        p.Asset_Location__c = t.split(':')[1];
                    }
            
                    if(t.contains('manufacturer')){
                        p.Asset_Manufacturer__c = t.split(':')[1];
                    }
                    
                    if(t.contains('make')){
                        p.Asset_Make__c = t.split(':')[1];
                    }
            
                    if(t.contains('model')){
                        p.Asset_Model__c = t.split(':')[1];
                    }
                    
                    if(t.contains('shipping')){
                        p.Shipping_Code__c = t.split(':')[1];
                    }
                
                    if(t.contains('power')){
                        p.Asset_Power__c = t.split(':')[1];
                    }
            
                    if(t.contains('rentalstatus')){
                        p.Asset_Rental_Status__c = t.split(':')[1];
                    }
            
                    if(t.contains('serial')){
                        p.Asset_Serial__c = t.split(':')[1];
                    }
            
                    if(t.contains('subcatcode')){
                        p.Asset_Subcatcode__c = t.split(':')[1];
                    }
                }
            }
        }    
    }
}
I've been reading about what the error means, and it would seemingly be that I'm trying to read an array element that doesn't exist. I added the size check of tags to try and avoid this, but that hasn't worked.

What am I missing?

Thanks,
Ross
 
Hi all, 
I have a text field against the Opportunity object that sometimes contains data such as:

0123456,0234567,0345678 etc

There could sometimes only be one value and on other occasions there might be 10 or so.

When this field is populated I'd like to use these IDs to lookup a Product record (via a custom SKU field) and subsequently create an OpportunityProduct record linked to the Opportunity.

What is the best approach here? I'm not an Apex developer although I have written simple triggers after gaining advice and examples from the community previously. I started to experiment in Flow, but stumbled early on when I couldn't see a way to split the comma seperated text value

Looking forward to your advice.
Thanks,
Ross
Hi!

I have a field against the Product object, Tags, which contains data such as the following, imported from a thrid-party system:
age:< 12 Months, assetcondition:BRONZE, location:LAVERTON, make:POS SYSTEM, model:3212, power:SIN10AMP, rentalstatus:AVAIL-W, serial:100285954, subcatcode:Swift Assets
When these Product records are created I want to use formulas in a Process Builder Workflow action to extract each "key:<value>" pair, storing all <value>'s in custom fields.

As an example based on the above, one of the formulas would search for "location:" and store "LAVERTON" as the value in a "location__c" field against the Product record. I'd want to do this for age, assetcondition, assetlocation, make etc etc.

I can see lots of examples of using LEFT and MID but haven't been able to create a dynamic enough formula - data in this tags field will vary a lot, so I can't specifiy exact start and end text positions.

Any advice appreciated!

Thanks
Hi all,

We have a Drupal website making use of the SalesForce Suite (https://www.drupal.org/project/salesforce) and SalesForce Webforms (https://www.drupal.org/node/2298941) modules to transmit webform submissions into SalesForce. They've been working well for over a year now.

However, we're about to launch a French site and are having difficulties with any value that contains accents. A quick Google tells me so do many other people, regardless of implementation, but I can't find a solution.

Does anyone have any experience of this or advice?

Thanks,

Ross