• Enry
  • NEWBIE
  • 40 Points
  • Member since 2013

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

I got this error when i save my test class:

Error: Compile Error: Constructor not defined: [ApexPages.StandardController].<Constructor>() 

 CLASS:

public class ContentVersionAlt {
private List<ContentVersion> ContentVersions;
public string host{get;set;}

    public ContentVersionAlt(ApexPages.StandardController controller) {
           host=URL.getSalesforceBaseUrl().toExternalForm();
    }


    public List<ContentVersion> getContentVersions() {

    ContentVersions= [Select c.id ,c.Software_Download__c,c.title,c.description,c.FileType From ContentVersion c where c.Software_Download__c=:System.currentPagereference().getParameters().get('id')];
        return ContentVersions;
    }

}

 

 

TEST CLASS:

@istest
private class ContentVersionAltTest {
 static testMethod void ContentVersionsTest(){

          PageReference pageRef = Page.SoftwareDownloadFiles;
          Test.setCurrentPageReference(pageRef);

        ApexPages.StandardController sc = new ApexPages.standardController();
        //create an instance of the controller
        ContentVersionAlt myPageCon = new ContentVersionAlt(sc);
        myPageCon.getContentVersions();       

         ContentVersion testContentInsert =new ContentVersion(); 
         testContentInsert.ContentURL='http://www.google.com/'; 
         testContentInsert.Title ='Google.com'; 

         insert testContentInsert;   


         ContentVersion testContent = [SELECT ContentDocumentId FROM ContentVersion where Id = :testContentInsert.Id]; 

         ContentWorkspace testWorkspace = [SELECT Id FROM ContentWorkspace WHERE Name='Opportunity Documents ']; 
         ContentWorkspaceDoc newWorkspaceDoc =new ContentWorkspaceDoc(); 
         newWorkspaceDoc.ContentWorkspaceId = testWorkspace.Id; 
         newWorkspaceDoc.ContentDocumentId = testContent.ContentDocumentId; 
         insert newWorkspaceDoc;

         update testContent; 



 }

}

 

 

 

How can i solve this?

Thanks in advantage for any advice.

 

 

 

 

I have a simple VF form and i would like to validate the email address field when the user click on Submit.

<apex:page id="loginPage" showHeader="false" controller="SiteRegisterController" title="{!$Label.site.site_login}">
    <apex:define name="body">  
      <center>
        <apex:panelGrid bgcolor="white" columns="1"> 
          <br/>
          <br/>
          <apex:panelGrid width="758" cellpadding="0" cellspacing="0" bgcolor="white" columns="1" styleClass="topPanelContainer"> 
            <br/>
            <apex:outputPanel layout="block" styleClass="topPanel">
              <apex:panelGrid width="758" cellpadding="0" cellspacing="0" bgcolor="white" columns="2"> 
                <apex:panelGroup >
                  <h1>Don't have an account?</h1>
                  <br/>
                  <h2>Enter your email address to register</h2>
                   <apex:form id="theForm" forceSSL="true">
                    <apex:panelGrid columns="2" style="margin-top:1em;">
                      <apex:outputLabel value="{!$Label.site.email}" for="email"/>
                      <apex:inputText required="true" id="email" value="{!email}"/>
                      <apex:outputText value=""/>
                      <apex:commandButton action="{!registerUser}" value="{!$Label.site.submit}" id="submit"/>
                    </apex:panelGrid> 
                    </apex:form>   
                </apex:panelGroup>
              </apex:panelGrid> 
             </apex:outputPanel>
          </apex:panelGrid> 
       </apex:panelGrid>
      </center>
      <br/>
    </apex:define> 
</apex:page>

 

How can i achieve this?

Thanks in advantage for any advice.

BR.

 

I'm creating a custom VF page for the registration of new users.

Page: simple form to get the user's email.

Controller:

 

public with sharing class SiteRegisterController {

    public SiteRegisterController () {
    }


public String username {get; set;}
public String email {get; set;}
public String password {get; set;}

    public PageReference registerUser() {
       user u = [select id,username from User where username = :email];
           if (u!=null) {
                  //ADD HERE CODE FOR ERROR MESSAGE IN THE PAGE FORGOTPASSWORD
                  PageReference page = System.Page.ForgotPassword;
                page.setRedirect(true);
                return page;
            }
            else {
                PageReference page = new PageReference('http://registration.com/');
                page.setRedirect(true);
                return page;
            }

        return null;
    }
}

 If the user is already registered i would like also add a message "You are already registered, Did you forget your password?" on the new page System.Page.ForgotPassword;. I know how to add an eror message in the current page

 

 

ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error Message.');
ApexPages.addMessage(myMsg); 

 

but is it also possible add it in a new page(forgotpassword) from the controller of the current page? Of course in the page forgot password there is a tag 

<apex:pageMessages id="error"/>

 

 

 

Thanks in advantage for any advice.

BR.

 

 

 

 

 

This is my trygger on Opportunity object.

 

trigger AutoProductupdate on Opportunity ( before update,after update) {
  static boolean already=false;
  if (already==false){
    for(Opportunity newOppt : Trigger.new){       
      if  (trigger.isAfter){
        if (newOppt.Pricing_Tears__c.trim()=='Gigabyte'){                                   
          SYSTEM.DEBUG('update');

          Automations.UpdateOpportunityLineItems(newOppt);
          //Action of the called function: 
          //DELETE OPPORTUNITY LINE ITEM SCHEDULES FOR ALL THE PRODUCTS
          // UPDATE OPPORTUNITY LINE ITEM
          Automations.SheduleOpportunityLineItem(newOppt);
          //Action of the called function: 
          // CREATE OPPORTUNITY LINE ITEM SCHEDULES FOR ALL THE PRODUCTS
        }
      }  
    }        

    already=true; 
   }                   
}

 

I am working with opportunity product and opportunity product schedules. In the debug log i see that the trigger is working recursively (It 's printed 15 times the string 'update' with the system.debug).

The error message:

 

execution of AfterUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00oL0000000acVqIAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoProductupdate: maximum trigger depth exceeded Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ]: []: Class.Automations.UpdateOpportunityLineItems: line 70, column 1

 

Which is the problem?

How can avoid this?

I have a simple report that shows my opportunity with different currencies.

I'm exporting the report: 

 

Currency Amount Amount 

INR    100

USD   0.00

USD   0.00

USD   0.00

USD   0.00

 

I would like to export this with just one currency.

Is it possible?

Thanks in advantage for any advice.

BR.

Hi,I want just that when a new opportunity is created, a set of opportunitylineitems will be created.

This is my code:

trigger Automations on Opportunity (before insert,after insert) {
 List<Opportunity> opptsToInsert = new List<Opportunity>();

     for(Opportunity newOppt : Trigger.new){

          newOppt.NextStep='NextStep';
          opptsToInsert.add(newOppt); 
          }


            //CREATE 1 OPPORTUNITY LINE ITEM FOR EACH NEW OPPORTUNITY WITH THE CORRECT PRODUCT
            List<OpportunityLineItem> opptLineItemsToInsert = new List<OpportunityLineItem>();



        if ((Trigger.isAfter)&&(Trigger.isInsert)){
            for(Opportunity opptInserted : [Select Id, Description from Opportunity where Id in :opptsToInsert])
            {  

                for (Integer i=0;i<4; i++) {
                     OpportunityLineItem newOpptLineItem = new OpportunityLineItem();
                     newOpptLineItem.OpportunityId=opptInserted.Id;
                     newOpptLineItem.Quantity = 1; 
                     // SET PRODUCT
                     newOpptLineItem.PricebookEntryId ='01ui0000002brJzAAI';
                     newOpptLineItem.TotalPrice=100;

                     opptLineItemsToInsert.add(newOpptLineItem);                 

                      }

              insert(opptLineItemsToInsert);
          }  
      }    

}

i get the following error:

Automations: execution of AfterInsert caused by: System.FinalException: Record is read-only

it works if a remove newOppt.NextStep='NextStep';

 

The problem is that you cannot update fields on triggered records when you are in an after trigger but i have to update information for the new opportunity.

 

Please can you help me with this?

Thank you very much for any advice.

 

 

ps:I know that it very bad use hard coded ids,but this is just a test.

Br.

in a trigger i'am going to create a new opportunitylineitem for an opportunity:

 

 

                 OpportunityLineItem newOpptLineItem = new OpportunityLineItem();
                 newOpptLineItem.OpportunityId = opptInserted.Id;
                 newOpptLineItem.=cs.OppProductCpvId__c; // FOR GIGABYTE
                 newOpptLineItem.Quantity = 1;                   
                 newOpptLineItem.PricebookEntryId = peWEBinteractive.Id;
                 opptLineItemsToInsert.add(newOpptLineItem);  .

 

I want to set up a product for this new opportunitylineitem.

newOpptLineItem.ProductId isn't available.

Thanks in advantage for any advice.

I'm creating a custom visual force page that allow users to create a new record for a custom object.

I want understand if in the custom VF page i have the standard functionality of the record type:

-see different field according to the visibility of the page layout

-have different picklist values

 

I have found this resource link:

Displaying Record Types

I have tried creating a custom visual force page and two record types.

The record types are linked to different page layout.In one of the two page layouts i have removed some fields.

Pressing the New button i can choose which of the two record types i want.

They open the same VF page,but i can see on my custom vf Page the same fields.

 

I would like to be able to show different fields on my custom VF page according to different record types. Is not possible or is there something that i don't know?

 

Thanks in advantage for any advice.

BR.

Hi,I want create a custom button that runs an apex class.

This class create a record and open the detailed page of the record created.

Do you know if is it possible?

Do you have an example code for the button that exercutes the class? javascript?

Thanks in advantage for any advice.

BR.

I'm using the data loader to export accounts.

I put the following condition in the form of the dataloader:

Select NAME FROM Account WHERE LastModifiedDate = 2013-06-11T15:54:00Z

 But i'm not able to get the account that have lastmodifiedDate equals to 2013-06-11 time 15:54 ( these value are showed by an account).

I don't know which of the following parameters is important to have success:

 

--My user has: 

Time Zone (GMT+02:00) Central European Summer Time (Europe/Paris)

 

--Dataloader setting: timezone=Europe/Paris

 

 

--with a query in the developer console i see this format: 2013-05-31T12:26:35.000+0000

 

 

Please can you help me?

Which should be the right date format in the soql query?

Thank you in adavantage.

BR.

 

 

 

I've written a class to post a happy birthday message and picture on chatter.

Now i want mention a user in the post.

I have found:http://developer.force.com/cookbook/recipe/posting-a-chatter-mention-via-apex

My code create the post but it doesn't mention the user. 

i haven't experience with HttpRequest.

 

Please can you take a look to my code?

Thank you in advantage.

 

Global class HappyBirthdayRandom implements Schedulable{


//FOR TEST METHOD
   public static String CRON_EXP = '0 0 0 3 9 ? 2022';
   
   @future(callout=true)
            public static void mention(string uid,string RecordId){
                 //INVOKE CHATTER REST API FOR MENTION
                  String salesforceHost = System.Url.getSalesforceBaseURL().toExternalForm();
                  String url =  salesforceHost + '/services/data/v26.0/chatter/feeds/record/' + RecordId + '/feed-items';
                     HttpRequest req = new HttpRequest();
                      req.setMethod('POST');
                      req.setEndpoint(url);
                      string ChatterPostText='Happy Birthday';
                        req.setHeader('Content-type', 'application/json');
                         req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
                          req.setBody('{ "body" : { "messageSegments" : [ { "type": "mention", "id" : "' + uid + '" }, { "type": "text",  "text" : "' + ' ' + ChatterPostText +  '" } ] } }');
                           Http http = new Http();
                            HTTPResponse res = http.send(req);           
                    } 
   
   
   

  Global void execute(SchedulableContext sc) 
    {

            
           // SEARCH BY STATIC RESOURCE NAME
           List<StaticResource> Pictures=[Select Name, ContentType, Body From StaticResource where Name like 'PicturehappyBirthday%'];
           List<FeedItem> posts = new List<FeedItem>();
           // IS THE USER BIRTHDAY?              
           List<user> lstu=[SELECT id,name,date_of_birth__c FROM user WHERE  CALENDAR_MONTH(date_of_birth__c)=:date.today().month() AND  DAY_IN_MONTH(date_of_birth__c)=:date.today().day()];
           CollaborationGroup fgroup=[Select id,name from CollaborationGroup where Name like 'Name%' limit 1];
       
              for(User u:lstu)
              {
                    //GENERATE A RANDOM NUMBER [0-5] TO SELECT THE PICTURE
                   Integer choice=math.mod(Integer.valueof(Math.random()*100),6);
                   Blob Decodedbody=Pictures[choice].body;
                   // CREATE POST
                   FeedItem post = new FeedItem();


                   
                   // CREATE BY
                   post.CreatedById=u.id;
                   // CREATE ON
                   post.ParentId =fgroup.id;
                   post.Type = 'ContentPost';
                   mention(u.id,post.id); 
                   post.Body = 'Happy birthday to '+u.name+' !';
                   post.ContentData = Decodedbody;
                   post.ContentFileName = 'Wishes!.jpg';
                   posts.add(post);
              }
                 insert posts;
 
        }
    }

 

 

 

Hi,

I have a doubt.

When i have to use an id which is the best way to put it in a variable.

 

user u=[Select id,name from user where... limit 1 ];
        post.CreatedById=u.id;

 

 

or

 

  post.CreatedById='005E0000003XNVp';

 

are there other way?

Which is the best practise?

 

Thanks in advantage.

BR

 

 

Hi ,

I have written a test class for a trigger on the lead object.

When i run the test class i get the following error:

 

Methods defined as TestMethod do not support Web service callouts, test skipped

 

There is an other trigger on lead that has a call to a webservice so i get this error.

I have wrapped the call with:

 

if (!Test.isRunningTest())
{
   // do callout
}

 

 But i’m still getting the same error.

Any other way to run correctly the test class?

Thank you in advantage.

BR.

 

I have written a custom visual force page to edi a custom object "Influencer__c".

I have overridden the standard button edit for this object.

 

This is my  custom page:

<apex:page Standardcontroller="Influencer__c" id="Page"  tabstyle="Contact">

  <script type="text/javascript"> 
  function openLookup(baseURL, width, modified, searchParam){
    var originalbaseURL = baseURL;
    var originalwidth = width;
    var originalmodified = modified;
    var originalsearchParam = searchParam;
 
    var lookupType = baseURL.substr(baseURL.length-3, 3);
    if (modified == '1') baseURL = baseURL + searchParam;
 
    var isCustomLookup = false;
 
    // Following "001" is the lookup type for Account object so change this as per your standard or custom object
    if(lookupType == "003"){
 
      var urlArr = baseURL.split("&");
      var txtId = '';
      if(urlArr.length > 2) {
        urlArr = urlArr[1].split('=');
        txtId = urlArr[1];
      }
 
      // Following is the url of Custom Lookup page. 
      baseURL = "/apex/CustomInfluencerLookup?accplanid={!Influencer__c.Account_Plan__c}&txt=" + txtId;
 
      // Following is the id of apex:form control "myForm". 
      baseURL = baseURL + "&frm=" + escapeUTF("{!$Component.myForm}");
      if (modified == '1') {
        baseURL = baseURL + "&lksearch=" + searchParam;
      }
 
      // Following is the ID of inputField that is the lookup to be customized as custom lookup
      if(txtId.indexOf('mycontact') > -1 ){
        isCustomLookup = true;
      }
    }
 
 
    if(isCustomLookup == true){
      openPopup(baseURL, "lookup", 350, 480, "width="+width+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
    }
    else {
      if (modified == '1') originalbaseURL = originalbaseURL + originalsearchParam;
      openPopup(originalbaseURL, "lookup", 350, 480, "width="+originalwidth+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
    } 
  }
</script>



<apex:sectionHeader title="{!$ObjectType.Influencer__c.label}" subtitle="{!Influencer__c.name}"/>
    <apex:pageBlock title="{!$ObjectType.Influencer__c.label} Detail" mode="edit">
    
        <apex:pageBlockButtons>
        <apex:form>
            
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton action="{!Cancel}" immediate="true" value="Cancel"/>
       
        </apex:form> 
        </apex:pageBlockButtons>
        
        
         <apex:form>
         <apex:pageBlock>
        <apex:pageBlockSection title="Information" columns="2"> 
         
            <apex:inputField value="{!Influencer__c.Name}"/>
          <apex:inputField value="{!Influencer__c.Account_Plan__c}" required="true"/>
          <apex:inputField id="mycontact" value="{!Influencer__c.Contact__c}" required="true"/> 
            <apex:inputField value="{!Influencer__c.Type__c}" required="false"/>
           <apex:inputField value="{!Influencer__c.CCS_Role__c}" required="false"/>
            <apex:inputField value="{!Influencer__c.IMPACT__c}" required="false"/> 
           <apex:inputField value="{!Influencer__c.Top_Goals__c}" required="false"/>
           <apex:inputField value="{!Influencer__c.Attitude_towards_QT__c}" required="false"/>
           <apex:inputField value="{!Influencer__c.Contact_Risk_Profile__c}" required="false"/>
           <apex:inputField value="{!Influencer__c.Time_Spent__c}" required="false"/>
           <apex:inputField value="{!Influencer__c.Has_Power__c}" required="false"/> 
           <apex:inputField value="{!Influencer__c.Has_Budget__c}" required="false"/>
            <apex:inputField value="{!Influencer__c.QT_Exec__c}" required="false"/>
           
        </apex:pageBlockSection>
        </apex:pageBlock>
        </apex:form>
         
        
       <apex:pageBlockSection showHeader="false" columns="2">
            <apex:outputField value="{!Influencer__c.CreatedById}"/>
            <apex:outputField value="{!Influencer__c.LastModifiedById}"/>
        </apex:pageBlockSection>
   </apex:pageBlock>
  
 </apex:page>

 When i press the button SAVE the new informations are not saved.

Where am i wrong?
have i a problem in the code's page or is it because i have overridden the button?

 

Please help me.

Thank you very much.

BR

I am setting the recordType of a newly created recorded in apex.

 

I have it inserting the new opportunity and am receiving an error on this line:

 

opportunity.recordtype = chosenRecType;

 

chosenRecType is a value passed to the controller via javascript.

 

The error is: Error: Compile Error: Illegal assignment from String to SOBJECT:RecordType

 

Is there a way to convert this string to be read properly?

 

Thanks.