• RjSanchez
  • NEWBIE
  • 55 Points
  • Member since 2011

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

Can anyone tell me how I can pass a variable into a LIKE statement in a SOQL query?

 

If I hardcode the search sting I get records returned:

results = (List<Solution>)[SELECT Id, SolutionNumber, SolutionName, TimesUsed FROM Solution WHERE (SolutionName LIKE '%keywordhere%')];

 

What I need to do is pass a variable in for the keyword. I tried the following code but I get an error - Error: SolutionSearch Compile Error: unexpected token: '+'

results = (List<Solution>)[SELECT Id, SolutionNumber, SolutionName, TimesUsed FROM Solution WHERE (SolutionName LIKE '%' + searchText + '%')];

 

I have this code that works but I don't like how it imprecise the returned record are that are returned:

results = (List<Solution>)[FIND :searchText IN ALL FIELDS RETURNING Solution(Id, SolutionNumber, SolutionName, TimesUsed)] [0];

 

Thank you.

 

I have created a trigger for a new task is created. It checks the status to verify it is completed and it's status is either Call or Email:

 

Everything was working fine until I realized that the Subject field of 'Log a Call' can be typed in even though it has a selection offered as a combo box. And anything they type becomes the subject of the task created.

 

When 'Send an Email' is chosen, the subject line is a blank field as one might expect, however when it is saved it places 'Email:' at the beginning of the string.

 

What I would like to do is have the 'Log a call' action place 'Call:' in front of whatever is typed in the subject combo. But I'm not sure where to start.

 

Am I making sense? :) Is this possible?

I would appreciate any suggestions you may have.

 

  Thank you,

    Ramon

 

The idea is to Automatically follow all other chatter users when a new user is added.

 

The problem I am having is the trigger works when adding a new user as long as a Role is not specified upon creation.

When a Role is selected during creation the following error occurs.

caused by: System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): EntitySubscription, original object: User: []

 

Below is the trigger I have written:

trigger FollowAllChatterUsers on User (after insert) {
    //Create List to hold all chatterIds. they will need to be added.
    List<User> chatterIdsToAdd = new List<User>([SELECT Id from User WHERE IsActive = true]);
    Id currentUserId;
    
    //Take a count of how many users were added to fire this trigger.
    //If more than 10 then do not automatically follow.
    //The assumption is that if we batch-add more than 10 records we are probably
    //  loading saved data or backup data in which case the entitysubscriptions table
    //  will need to be loaded as well.
    Integer triggerLength = 0;
    for( User usr: Trigger.new ) {
        triggerLength++;
    }
    
    if (triggerLength <= 10) {
        // for each inserted user add all chatter ids except their own.
        for( User usr: Trigger.new ) {
            //Array of subscription records to create
            EntitySubscription[] subsToCreate = new EntitySubscription[]{};
            //Get the id of the current user.
            currentUserId = usr.Id;
            //Loop through list of users to add.
            for( User toAdd: chatterIdsToAdd ) {
                //If the id to add is our own then skip. otherwise cont..
                if ( toAdd.Id != currentUserId ) {
                    //Create the EntitySubscription record.
                    EntitySubscription follow = new EntitySubscription(
                        parentId = toAdd.Id,
                        subscriberId = currentUserId);
                    //Add new EntitySubscription to Array for insertion. 
                    subsToCreate.add(follow);
                }
            }
            //Insert the array.
            insert subsToCreate;
        }
    }
}

 

I read somewhere that within the same transaction a User record and a Role record cannot be update using DML.

I'm not sure if that the same issue I'm running into or not.

 

If anyone has any insight I would welcome your suggestions.

 

Thank You,

    Ramon

Hi

While searching for date I am getting this error 

 

no viable alternative at character ' '

 

 

the code is 

if (StartDate != null)
      soql += ' and Start_Date__c equals ' +  myDate ;

 please help me 

thanks 

anuraj

  • October 11, 2011
  • Like
  • 0

Hi Salesforce Gurus,

 

When I am opening the System Log (or Developer Console) in Sandbox and I am getting this error message:

 

Error: Open request failed

Requested entity 07LT000000DMX7L was not found.

 

~NK

 

  • October 07, 2011
  • Like
  • 0

i have a visualfoce page in dev environment with a button pointing to other visualforce page. now when i deployed the page to other environment using change set..... the link was not working in that env.

in the dev env. the link is something like: https://c.cs0.visual.force.com/apex.....

 

and in the other env. it is: https://c.cs12.visual.force.com/apex.....

 

can't i have a common link so that i dont have to manually change them while deploying?

Hi Everyone,, 

 

I'm trying to remove a lead record type that's not used any longer...but I seem to be encountering the following error:

 

"This record type RVP cannot be deleted because the following profiles use this record type as default. External Who"  

 

Can anyone PLEASE explain to me why this is the case? I don't have a profile called "External Who"!!! Thanks so much for the help! 

 

Regards, 

 

Studzey

Can anyone tell me how I can pass a variable into a LIKE statement in a SOQL query?

 

If I hardcode the search sting I get records returned:

results = (List<Solution>)[SELECT Id, SolutionNumber, SolutionName, TimesUsed FROM Solution WHERE (SolutionName LIKE '%keywordhere%')];

 

What I need to do is pass a variable in for the keyword. I tried the following code but I get an error - Error: SolutionSearch Compile Error: unexpected token: '+'

results = (List<Solution>)[SELECT Id, SolutionNumber, SolutionName, TimesUsed FROM Solution WHERE (SolutionName LIKE '%' + searchText + '%')];

 

I have this code that works but I don't like how it imprecise the returned record are that are returned:

results = (List<Solution>)[FIND :searchText IN ALL FIELDS RETURNING Solution(Id, SolutionNumber, SolutionName, TimesUsed)] [0];

 

Thank you.

 

The idea is to Automatically follow all other chatter users when a new user is added.

 

The problem I am having is the trigger works when adding a new user as long as a Role is not specified upon creation.

When a Role is selected during creation the following error occurs.

caused by: System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): EntitySubscription, original object: User: []

 

Below is the trigger I have written:

trigger FollowAllChatterUsers on User (after insert) {
    //Create List to hold all chatterIds. they will need to be added.
    List<User> chatterIdsToAdd = new List<User>([SELECT Id from User WHERE IsActive = true]);
    Id currentUserId;
    
    //Take a count of how many users were added to fire this trigger.
    //If more than 10 then do not automatically follow.
    //The assumption is that if we batch-add more than 10 records we are probably
    //  loading saved data or backup data in which case the entitysubscriptions table
    //  will need to be loaded as well.
    Integer triggerLength = 0;
    for( User usr: Trigger.new ) {
        triggerLength++;
    }
    
    if (triggerLength <= 10) {
        // for each inserted user add all chatter ids except their own.
        for( User usr: Trigger.new ) {
            //Array of subscription records to create
            EntitySubscription[] subsToCreate = new EntitySubscription[]{};
            //Get the id of the current user.
            currentUserId = usr.Id;
            //Loop through list of users to add.
            for( User toAdd: chatterIdsToAdd ) {
                //If the id to add is our own then skip. otherwise cont..
                if ( toAdd.Id != currentUserId ) {
                    //Create the EntitySubscription record.
                    EntitySubscription follow = new EntitySubscription(
                        parentId = toAdd.Id,
                        subscriberId = currentUserId);
                    //Add new EntitySubscription to Array for insertion. 
                    subsToCreate.add(follow);
                }
            }
            //Insert the array.
            insert subsToCreate;
        }
    }
}

 

I read somewhere that within the same transaction a User record and a Role record cannot be update using DML.

I'm not sure if that the same issue I'm running into or not.

 

If anyone has any insight I would welcome your suggestions.

 

Thank You,

    Ramon