• noedskov
  • NEWBIE
  • 25 Points
  • Member since 2008

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

Hi,

 

I have a test method which tests a number of Knowledgebase related objects. In my Apex Class, I have the following code:

 

 

        String queryvar = 'FIND \'' + '*' + searchQ + '*' + '\'' + ' IN ALL FIELDS Returning ' + 'Knowledgebase__kav(Id, Title, Summary, UrlName WHERE PublishStatus =\'Online\')';
        List<List<SObject>> searchList = search.query(queryvar);
        Knowledgebase__kav [] documents = ((List<Knowledgebase__kav>)searchList[0]);
        if (!documents.isEmpty()) {
            for (Knowledgebase__kav c : documents) {
                // Do stuff...
            }   
        }  else {
            // Do different stuff...
        }

In my test method I then create a new Knowlegebase__kav object but when trying to set PublishStatus = 'Online', I'm told the field is not writeable. I need to mark it as 'Online' as that's what my Apex Class is looking for.

 

 

Any great ideas?

 

Cheers.

 

/Søren Nødskov Hansen

Hi,

 

I have an Apex Class called AjaxRespController which defines the method doSearch().

 

My test method for the class looks like this:

 

		Community community = [SELECT Id, IsActive FROM Community WHERE IsActive = true LIMIT 1];

Idea idea = new Idea();
idea.Title = 'SNH Test Idea Title';
idea.CommunityId = community.Id;
insert idea;

Test.startTest();
ApexPages.currentPage().getParameters().put('q', 'a');
AjaxRespController arc = new AjaxRespController();
arc.doSearch();
String result = arc.getResult();
System.assertNotEquals(result, null);
Test.stopTest();

In the method doSearch I have the folllowing code:

 

        String searchQ = String.escapeSingleQuotes(params.get('q'));
String query = 'FIND \'*' + searchQ + '*\' IN ALL FIELDS RETURNING Idea(Id, Title, VoteTotal)';
System.debug('Query: ' + query);
Idea myIdea = [SELECT Id, Title, VoteTotal FROM Idea WHERE Title = 'SNH Test Idea Title' LIMIT 1];
if(myIdea != null) {
System.debug('Found Idea: ' + myIdea.Title);
} else {
System.debug('No Idea Found');
}
List<List<SObject>> result = search.query(query);
List<Idea> myIdeas = (List<Idea>)result.get(0);
System.debug('Ideas found: ' + myIdeas.size());

 

Here's what the debug messages tell me:

 

13:16:38.785|USER_DEBUG|[13,3]|DEBUG|Query: FIND '*a*' IN ALL FIELDS RETURNING Idea(Id, Title, VoteTotal)

13:16:38.851|USER_DEBUG|[16,4]|DEBUG|Found Idea: SNH Test Idea Title
13:16:38.852|USER_DEBUG|[22,9]|DEBUG|Ideas found: 0

 

What puzzles me is that the FIND query doesn't find the Idea I insert in my test method but the SELECT statement does. How can that be? What am I missing?

 

All help and ideas are greatly appreciated.

 

Cheers.

 

Søren Nødskov Hansen

Hi,

 

I'm not quite sure if this falls under Apex or Java development but I decided to post it here.

 

I've created a number of Java classes and turned them into a web service using Axis2 1.4.1 and I seem to keep banging my head against the wall when trying to convert that into Apex code.

 

I go to Setup --> Develop --> Apex Classes and press the button "Generate from WSDL".

 

First I got an error message telling me that multiple bindings aren't allowed. So, I manually edit the WSDL removing the Soap11Binding and Soap12Binding, leaving only the HttpBinding.

 

Next, I get an error message that anyType isn't supported by SFDC. Scanning the Help & Training section I see that the "anyType" previously was mapped to "string". So, once again I manually edit my WSDL file and change anyType to string. Not sure if that's the right decision or not as my method returns a rather simple (Java) object with a couple of fields (a boolean and 3 Strings).

 

Now, it seems like all is well and I get to the 3rd and last step of the wizard but wrong again. On the 3rd, and final, step I'm presented with the following error:

 

Apex generation failed.


Error message:

Error: Unable to find soap 1.1 address

 

And that's where I'm at right now. Is there anyone out there who can point me in the right direction? All help and tips is appreciated.

 

I've worked a lot with axis1 but am new to axis2. My service/class is called PublicatorProTrialManager.java and when creating the client files for the WSDL I get PublicatorProTrialManager.java, PublicatorProTrialManagerLocator, PublicatorProTrialManagerPortType, PublicatorProTrialManagerPortTypeProxy, 2 binding stubs (soap 1.1 and soap 1.2) and a CreateTrialCustomerAndUserResponse.java (the method in the service is called createTrialCustomerAndUser and it returns an object called TrialResult.

 

Does that seem correct to you guys? I would have expected to also see Java files for my TrialResponse obect and the exceptions I've created as well. They would have been generated if I were to use axis1 so I'm a bit worried that I might be doing something wrong or missing some configuration.

 

Best regards,

 

Søren Nøskov Hansen

Zmags ApS

Message Edited by noedskov on 05-16-2009 05:48 PM
Message Edited by noedskov on 05-16-2009 05:58 PM
Message Edited by noedskov on 05-17-2009 02:45 AM

Hi,

 

I'm trying to create my first trigger. It seems pretty straight forward yet I seem to have a few problems/questions.

 

My trigger looks like this:

 

trigger createCase on Opportunity (after update) {
  for (Opportunity newOpp: Trigger.New) {
    if (newOpp.StageName == 'Order confirmed' && newOpp.Type == 'New Business') {
        Case newCase = new Case();
        System.debug('Account: ' + newOpp.Account);
        newCase.Account = newOpp.Account;
        insert newCase;
    }
  }
}

 

My 2 questions are:

 

  1. The new case is created but for some reason the account is not attached. Almost like the newOpp.Account is null. Which brings me to my next question...
  2. When testing the trigger in our sandbox I cannot see the debug message in the System Log. Why is that?

I'm not using the plug-in for Eclipse but simply writing the trigger directly in SFDC. I also tried running the trigger as "before update" but that didn't seem to make any difference in relation to the account not being attached to the case.

 

Cheers,

 

Søren Nødskov Hansen

Message Edited by noedskov on 02-13-2009 06:58 AM
Hi,

First, the scenario:

We want to be able to group accounts, opportunities, leads and contacts by region. For simplicity let's only focus on the account. Here is my first attempt which kept us going for some time (but will very soon not be enough):

  • Create custom region field on account of type formula
  • Create huge formula that asks if ownerid = "ukRepOwnerId" then region = "UK" or if ownerid = "usRepOwnerId" then region = "US" else region = "Scandinavia"
Now, this worked fine for some time. However, it has 2 major flaws:

  1. It needs updating every time we add a new user
  2. With enough users the formula grows too big for SFDC to handle (it basically exceeds the limit of allowed characters)
So, I thought I could just create a custom field on the user object (not remembering I had already tried this some time back :smileyindifferent). Creating the field is not a problem but accessing the field from e.g. a formula field on account seems to be a big problem. I only seem to be able to access the usual account fields and various information about the user that is currently logged in.

Is there some way for me (e.g. using triggers) to achieve this?

/Søren Nødskov Hansen
Hi all,

On our opportunity object we have a formula field called "Monthly value" which returns a currency. The formula looks like this (Contract_length_mth__c is a picklist):

Amount  /  VALUE(CASE(Contract_length_mth__c, "1", "1", "3", "3", "6", "6", "9", "9", "12", "12", "15", "15", "18", "18", "21", "21","24", "24", "36", "36", "0"))

Now, on our account object I want to create a field called "Monthly value total" which is a sum of the field above for a certain set of opportunities defined by a filter. According to SFDC's Help & Training section that should be possible:

"Roll-up summary fields can calculate the values of formula fields if they do not contain functions that automatically derive values on the fly, such as NOW or TODAY."

My formula above does not (to my knowledge) use any automatically generated values. However, when creating the roll-up summary field on account and selecting opportunity as the object to summarize (using SUM) only 4 values appear for me to select and none of them is my formula field Monthly value.

Any ideas?

Thanks.

/Søren Nødskov Hansen
Hi all,

I have the following question:

On the account object we have a customer expire date which indicates when a given customer's subscription expires and thereby no longer is a customer with us. Now, the issue is that when an opportunity is won I want to update the customer expire date on the account.

However, using workflows that doesn't seem to be possible. Is there any way for me to get this done - e.g. using apex code, triggers or something else?

Thanks.

/Søren Nødskov Hansen
Hi,

We have an approval process which in it's final approval actions performs a field update on Opportunity.Stage.

We then have a workflow rule that is triggered by a field update on Opportunity.Stage which sends out an email to certain people.

Now, if I login and update the stage of an opportunity to "Order confirmed" the workflow picks up on that and sends the email. This works fine.

However, if the stage field on the opportunity is set to the exact same "Order confirmed" the workflow does NOT pick up on the field update and NO email is being sent out.

Is this a bug or is it simply not possible to have a field update in an approval process trigger a workflow like that?

Kind regards,

Søren Nødskov Hansen
Hi all,

We use the API for various tasks and one of them is to create leads within salesforce which are generated from our website.

Now, a sub-set of these leads we want to make part of specific campaign and below I have included some example code.

Code:
String[] campaignIds = {"70120000000AFKy"}; //Campaign Id for Free Website Trial
SObject[] campaigns = stub.retrieve("Name", "Campaign ID", campaignIds); //Retrieve matching objects (should only be one)
Campaign campaign = null;
for(int x = 0; x < campaigns.length; x++) { //Loop through objects found
  campaign = (Campaign)campaigns[x];
  System.out.println("Got campaign: " + campaign.getName() + " with id: " + campaign.getId()); //Print name and id of campaign
}

No doubt I get the correct campaign but when I create a new lead and set the campaign (see code below) I get the following error message: Invalid foreign key relationship name Campaign

Code:
lead.setCampaign(campaign);

Any suggestions?

Cheers.

/Søren Nødskov Hansen

Hi,

 

I have a test method which tests a number of Knowledgebase related objects. In my Apex Class, I have the following code:

 

 

        String queryvar = 'FIND \'' + '*' + searchQ + '*' + '\'' + ' IN ALL FIELDS Returning ' + 'Knowledgebase__kav(Id, Title, Summary, UrlName WHERE PublishStatus =\'Online\')';
        List<List<SObject>> searchList = search.query(queryvar);
        Knowledgebase__kav [] documents = ((List<Knowledgebase__kav>)searchList[0]);
        if (!documents.isEmpty()) {
            for (Knowledgebase__kav c : documents) {
                // Do stuff...
            }   
        }  else {
            // Do different stuff...
        }

In my test method I then create a new Knowlegebase__kav object but when trying to set PublishStatus = 'Online', I'm told the field is not writeable. I need to mark it as 'Online' as that's what my Apex Class is looking for.

 

 

Any great ideas?

 

Cheers.

 

/Søren Nødskov Hansen

Hi,

 

I have an Apex Class called AjaxRespController which defines the method doSearch().

 

My test method for the class looks like this:

 

		Community community = [SELECT Id, IsActive FROM Community WHERE IsActive = true LIMIT 1];

Idea idea = new Idea();
idea.Title = 'SNH Test Idea Title';
idea.CommunityId = community.Id;
insert idea;

Test.startTest();
ApexPages.currentPage().getParameters().put('q', 'a');
AjaxRespController arc = new AjaxRespController();
arc.doSearch();
String result = arc.getResult();
System.assertNotEquals(result, null);
Test.stopTest();

In the method doSearch I have the folllowing code:

 

        String searchQ = String.escapeSingleQuotes(params.get('q'));
String query = 'FIND \'*' + searchQ + '*\' IN ALL FIELDS RETURNING Idea(Id, Title, VoteTotal)';
System.debug('Query: ' + query);
Idea myIdea = [SELECT Id, Title, VoteTotal FROM Idea WHERE Title = 'SNH Test Idea Title' LIMIT 1];
if(myIdea != null) {
System.debug('Found Idea: ' + myIdea.Title);
} else {
System.debug('No Idea Found');
}
List<List<SObject>> result = search.query(query);
List<Idea> myIdeas = (List<Idea>)result.get(0);
System.debug('Ideas found: ' + myIdeas.size());

 

Here's what the debug messages tell me:

 

13:16:38.785|USER_DEBUG|[13,3]|DEBUG|Query: FIND '*a*' IN ALL FIELDS RETURNING Idea(Id, Title, VoteTotal)

13:16:38.851|USER_DEBUG|[16,4]|DEBUG|Found Idea: SNH Test Idea Title
13:16:38.852|USER_DEBUG|[22,9]|DEBUG|Ideas found: 0

 

What puzzles me is that the FIND query doesn't find the Idea I insert in my test method but the SELECT statement does. How can that be? What am I missing?

 

All help and ideas are greatly appreciated.

 

Cheers.

 

Søren Nødskov Hansen

Hi,

 

I'm trying to create my first trigger. It seems pretty straight forward yet I seem to have a few problems/questions.

 

My trigger looks like this:

 

trigger createCase on Opportunity (after update) {
  for (Opportunity newOpp: Trigger.New) {
    if (newOpp.StageName == 'Order confirmed' && newOpp.Type == 'New Business') {
        Case newCase = new Case();
        System.debug('Account: ' + newOpp.Account);
        newCase.Account = newOpp.Account;
        insert newCase;
    }
  }
}

 

My 2 questions are:

 

  1. The new case is created but for some reason the account is not attached. Almost like the newOpp.Account is null. Which brings me to my next question...
  2. When testing the trigger in our sandbox I cannot see the debug message in the System Log. Why is that?

I'm not using the plug-in for Eclipse but simply writing the trigger directly in SFDC. I also tried running the trigger as "before update" but that didn't seem to make any difference in relation to the account not being attached to the case.

 

Cheers,

 

Søren Nødskov Hansen

Message Edited by noedskov on 02-13-2009 06:58 AM
Hi,

First, the scenario:

We want to be able to group accounts, opportunities, leads and contacts by region. For simplicity let's only focus on the account. Here is my first attempt which kept us going for some time (but will very soon not be enough):

  • Create custom region field on account of type formula
  • Create huge formula that asks if ownerid = "ukRepOwnerId" then region = "UK" or if ownerid = "usRepOwnerId" then region = "US" else region = "Scandinavia"
Now, this worked fine for some time. However, it has 2 major flaws:

  1. It needs updating every time we add a new user
  2. With enough users the formula grows too big for SFDC to handle (it basically exceeds the limit of allowed characters)
So, I thought I could just create a custom field on the user object (not remembering I had already tried this some time back :smileyindifferent). Creating the field is not a problem but accessing the field from e.g. a formula field on account seems to be a big problem. I only seem to be able to access the usual account fields and various information about the user that is currently logged in.

Is there some way for me (e.g. using triggers) to achieve this?

/Søren Nødskov Hansen
Hi all,

On our opportunity object we have a formula field called "Monthly value" which returns a currency. The formula looks like this (Contract_length_mth__c is a picklist):

Amount  /  VALUE(CASE(Contract_length_mth__c, "1", "1", "3", "3", "6", "6", "9", "9", "12", "12", "15", "15", "18", "18", "21", "21","24", "24", "36", "36", "0"))

Now, on our account object I want to create a field called "Monthly value total" which is a sum of the field above for a certain set of opportunities defined by a filter. According to SFDC's Help & Training section that should be possible:

"Roll-up summary fields can calculate the values of formula fields if they do not contain functions that automatically derive values on the fly, such as NOW or TODAY."

My formula above does not (to my knowledge) use any automatically generated values. However, when creating the roll-up summary field on account and selecting opportunity as the object to summarize (using SUM) only 4 values appear for me to select and none of them is my formula field Monthly value.

Any ideas?

Thanks.

/Søren Nødskov Hansen
Hi all,

I have the following question:

On the account object we have a customer expire date which indicates when a given customer's subscription expires and thereby no longer is a customer with us. Now, the issue is that when an opportunity is won I want to update the customer expire date on the account.

However, using workflows that doesn't seem to be possible. Is there any way for me to get this done - e.g. using apex code, triggers or something else?

Thanks.

/Søren Nødskov Hansen
Hi,

We have an approval process which in it's final approval actions performs a field update on Opportunity.Stage.

We then have a workflow rule that is triggered by a field update on Opportunity.Stage which sends out an email to certain people.

Now, if I login and update the stage of an opportunity to "Order confirmed" the workflow picks up on that and sends the email. This works fine.

However, if the stage field on the opportunity is set to the exact same "Order confirmed" the workflow does NOT pick up on the field update and NO email is being sent out.

Is this a bug or is it simply not possible to have a field update in an approval process trigger a workflow like that?

Kind regards,

Søren Nødskov Hansen
Hi all,

We use the API for various tasks and one of them is to create leads within salesforce which are generated from our website.

Now, a sub-set of these leads we want to make part of specific campaign and below I have included some example code.

Code:
String[] campaignIds = {"70120000000AFKy"}; //Campaign Id for Free Website Trial
SObject[] campaigns = stub.retrieve("Name", "Campaign ID", campaignIds); //Retrieve matching objects (should only be one)
Campaign campaign = null;
for(int x = 0; x < campaigns.length; x++) { //Loop through objects found
  campaign = (Campaign)campaigns[x];
  System.out.println("Got campaign: " + campaign.getName() + " with id: " + campaign.getId()); //Print name and id of campaign
}

No doubt I get the correct campaign but when I create a new lead and set the campaign (see code below) I get the following error message: Invalid foreign key relationship name Campaign

Code:
lead.setCampaign(campaign);

Any suggestions?

Cheers.

/Søren Nødskov Hansen
I am quite new to salesforce development.  I wonder if salesforce provides API for java ?  Namely, it provides some jar files which I can add them into project build path, and then  I can call some method by this API ?  
  • June 02, 2008
  • Like
  • 0