• Gdev20000
  • NEWBIE
  • 4 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 8
    Replies

I'm creating a custom visual force page to download files stored in salesforce "Content".

This page will be included in the customer portal.

Do you know if the portal user (after the login) will be able to download the content's file without purchase features? i have found . http://na15.salesforce.com/help/doc/en/customer_portal_content.htm

but it isn't clear for me. I don't want all the content feautures in a tab.I want just to create links to download files stored in salesforce content.

Thanks in advantage for any advice.

BR

I'm writing a trigger for new opportunity products to populate a field Product_Category__c (on opportunity lineitem) getting the value from Product_Category_new__c (on Product).

This is my trigger:

trigger SetProductCategory on OpportunityLineItem (after insert) {

            for (OpportunityLineItem opplineitem: Trigger.new){

                         opplineitem.Product_Category__c= opplineitem.PricebookEntry.Product2.Product_Category_new__c;

              }     
}

I get this error message:

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

I have tried with before insert;in this case there aren't errors but the value Product category it's not saved on Opportunity Line item.

 

I have found that:

In a after insert trigger is not allowed change field using trigger.new

 

Please can you suggest a solution for this? i would like to copy the value Product category (Product) on Product Category (Opportunity Product) after the insert of the new opportunity products.

Thanks in advantage for any advice.

Br

I am not familiar with the test classes.Now i'm starting to learn how to test.

Please can you help me, i get 0% code coverage.

my class:

 

public with sharing class CustomInfluencerLookupController {
 
  public Contact contact {get;set;} 
  public List<Contact> results{get;set;} // search results
  public string searchString{get;set;} // search keyword
     public String accplanid {get;set;}
     public String accid {get;set;}
  public CustomInfluencerLookupController() {
    contact = new Contact();
    // get the current search string
    searchString = System.currentPageReference().getParameters().get('lksrch');
    accplanid = System.currentPageReference().getParameters().get('accplanid');
    
    accid = [SELECT Account__c FROM Account_Plan__c WHERE id = :accplanid].Account__c;
    runSearch();  
  }
 
  // performs the keyword search
  public PageReference search() {
    runSearch();
    return null;
  }
 
  // prepare the query and issue the search command
  public void runSearch() {
    // TODO prepare query string for complex serarches & prevent injections
    results = performSearch(searchString);               
  } 
 
  // run the search and return the records found. 
  public List<Contact> performSearch(string searchString) {
 
    String soql = 'SELECT Account.id, name from Contact where Account.id = \'' + accid+ '\'';
    
  //  String soql = 'SELECT Account.id,name from Contact';
    if(searchString != '' && searchString != null)
      soql = soql +  ' AND name LIKE \'%' + searchString +'%\'';
    soql = soql + ' limit 30';
    System.debug(soql);
    return database.query(soql); 
 
  }
 

  // used by the visualforce page to send the link to the right dom element
  public string getFormTag() {
    return System.currentPageReference().getParameters().get('frm');
  }
 
  // used by the visualforce page to send the link to the right dom element for the text box
  public string getTextBox() {
    return System.currentPageReference().getParameters().get('txt');
  }
 
}

 Test class:

@isTest
private class cilcTest {
    static testMethod void validate() {
    
    // Create a new account object.
    Account testAccount = new Account(Name = 'TestAccount');
    testAccount.Red_Account_End_Date__c=date.today();
    testAccount.Red_Account_Reason__c='reason';
    testAccount.Red_Account__c= true;
    insert testAccount;
  
    
    //CREATE TEST ACCOUNT PLAN
    Account_Plan__c accountplan=new Account_Plan__c ();
    accountplan.account__c=testaccount.id;
    insert accountplan;
    
      //CREATE TEST CONTACT
    Contact contact = new contact(lastname='lname');
    contact.Job_title__c='salesrep';
    insert contact; 
    Contact contact2 = new contact(lastname='lname');
    insert contact2;  
    
  

    Test.startTest();
    
    string searchString='search';
        PageReference pageRef = Page.CustomInfluencerLookup;
        Test.setCurrentPage(pageRef);

        ApexPages.currentPage().getParameters().put('accplanid', accountplan.Id);
        ApexPages.currentPage().getParameters().put('lksrch', searchString);
        CustomInfluencerLookupController controller = new CustomInfluencerLookupController();       
           controller.runSearch();
            controller.getFormTag();
             controller.getTextBox();
        
    Test.stopTest();       
         
        
   }
   }

 

 

 Thank you in advantage for any explanation.

BR

 

It's almost my first test class, please anyone can help me.

I get 0% covered by test class for my custom controller:

My class:

 

public with sharing class MyCustomLookupController {

   public Influencer__c Influencer { get; set; }

   public Id accountplanid { get; set; }
      
   public MyCustomLookupController () {
       accountplanid = System.currentPageReference().getParameters().get('id');
       Influencer = new Influencer__c(Account_Plan__c = accountplanid );
   }
    

 
 

    public PageReference save() {
      
        Contact c = [SELECT Job_title__c,name FROM Contact WHERE Id = :Influencer.Contact__c];
        
        Influencer.Title__c = c.Job_title__c;
        influencer.name=c.name;
        insert Influencer;
        PageReference acctPage = new PageReference('/' + Influencer.id);
        acctPage.setRedirect(true);
        return acctPage;
    }
    
    
       public PageReference cancel() {
      
        PageReference aPage = new PageReference('/' + accountplanid);
        aPage.setRedirect(true);
        return aPage;
    }
       
 
}

 

My test class:

@isTest 
private class MyCustomLookupControllerTestClass {
    static testMethod void validate() {


    PageReference pageRef = Page.MyCustomLookup; 
    Test.setCurrentPage(pageRef);
    
    // Create a new account object.
    Account testAccount = new Account(Name = 'TestAccount');
    testAccount.Red_Account_End_Date__c=date.today();
    testAccount.Red_Account_Reason__c='reason';
    testAccount.Red_Account__c= true;
    insert testAccount;
  
    
    //CREATE TEST ACCOUNT PLAN
     Account_Plan__c accountplan=new Account_Plan__c ();
     accountplan.account__c=testaccount.id;
     insert accountplan;
    
    //CREATE TEST CONTACT
     Contact contact = new contact(lastname='lname');
     contact.Job_title__c='salesrep';
     insert contact; 
     Contact contact2 = new contact(lastname='lname');
     insert contact2;  
    
    //CREATE TEST INFLUENCER
       Influencer__C influencertest = new Influencer__c();
       influencertest.Account_Plan__c= accountplan.id;
       Influencertest.Title__c = contact.Job_title__c;
        influencertest.contact__c=contact2.id;
       insert influencertest;     
         
        
   }

     }

 

 

Sorry, I have to learn a lots of things.

Thank you,Br.

I'm writing a trigger for new opportunity products to populate a field Product_Category__c (on opportunity lineitem) getting the value from Product_Category_new__c (on Product).

This is my trigger:

trigger SetProductCategory on OpportunityLineItem (after insert) {

            for (OpportunityLineItem opplineitem: Trigger.new){

                         opplineitem.Product_Category__c= opplineitem.PricebookEntry.Product2.Product_Category_new__c;

              }     
}

I get this error message:

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

I have tried with before insert;in this case there aren't errors but the value Product category it's not saved on Opportunity Line item.

 

I have found that:

In a after insert trigger is not allowed change field using trigger.new

 

Please can you suggest a solution for this? i would like to copy the value Product category (Product) on Product Category (Opportunity Product) after the insert of the new opportunity products.

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.

 

 

 

 

 

I'm creating a custom visual force page to download files stored in salesforce "Content".

This page will be included in the customer portal.

Do you know if the portal user (after the login) will be able to download the content's file without purchase features? i have found . http://na15.salesforce.com/help/doc/en/customer_portal_content.htm

but it isn't clear for me. I don't want all the content feautures in a tab.I want just to create links to download files stored in salesforce content.

Thanks in advantage for any advice.

BR

I'm writing a trigger for new opportunity products to populate a field Product_Category__c (on opportunity lineitem) getting the value from Product_Category_new__c (on Product).

This is my trigger:

trigger SetProductCategory on OpportunityLineItem (after insert) {

            for (OpportunityLineItem opplineitem: Trigger.new){

                         opplineitem.Product_Category__c= opplineitem.PricebookEntry.Product2.Product_Category_new__c;

              }     
}

I get this error message:

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

I have tried with before insert;in this case there aren't errors but the value Product category it's not saved on Opportunity Line item.

 

I have found that:

In a after insert trigger is not allowed change field using trigger.new

 

Please can you suggest a solution for this? i would like to copy the value Product category (Product) on Product Category (Opportunity Product) after the insert of the new opportunity products.

Thanks in advantage for any advice.

Br

I am not familiar with the test classes.Now i'm starting to learn how to test.

Please can you help me, i get 0% code coverage.

my class:

 

public with sharing class CustomInfluencerLookupController {
 
  public Contact contact {get;set;} 
  public List<Contact> results{get;set;} // search results
  public string searchString{get;set;} // search keyword
     public String accplanid {get;set;}
     public String accid {get;set;}
  public CustomInfluencerLookupController() {
    contact = new Contact();
    // get the current search string
    searchString = System.currentPageReference().getParameters().get('lksrch');
    accplanid = System.currentPageReference().getParameters().get('accplanid');
    
    accid = [SELECT Account__c FROM Account_Plan__c WHERE id = :accplanid].Account__c;
    runSearch();  
  }
 
  // performs the keyword search
  public PageReference search() {
    runSearch();
    return null;
  }
 
  // prepare the query and issue the search command
  public void runSearch() {
    // TODO prepare query string for complex serarches & prevent injections
    results = performSearch(searchString);               
  } 
 
  // run the search and return the records found. 
  public List<Contact> performSearch(string searchString) {
 
    String soql = 'SELECT Account.id, name from Contact where Account.id = \'' + accid+ '\'';
    
  //  String soql = 'SELECT Account.id,name from Contact';
    if(searchString != '' && searchString != null)
      soql = soql +  ' AND name LIKE \'%' + searchString +'%\'';
    soql = soql + ' limit 30';
    System.debug(soql);
    return database.query(soql); 
 
  }
 

  // used by the visualforce page to send the link to the right dom element
  public string getFormTag() {
    return System.currentPageReference().getParameters().get('frm');
  }
 
  // used by the visualforce page to send the link to the right dom element for the text box
  public string getTextBox() {
    return System.currentPageReference().getParameters().get('txt');
  }
 
}

 Test class:

@isTest
private class cilcTest {
    static testMethod void validate() {
    
    // Create a new account object.
    Account testAccount = new Account(Name = 'TestAccount');
    testAccount.Red_Account_End_Date__c=date.today();
    testAccount.Red_Account_Reason__c='reason';
    testAccount.Red_Account__c= true;
    insert testAccount;
  
    
    //CREATE TEST ACCOUNT PLAN
    Account_Plan__c accountplan=new Account_Plan__c ();
    accountplan.account__c=testaccount.id;
    insert accountplan;
    
      //CREATE TEST CONTACT
    Contact contact = new contact(lastname='lname');
    contact.Job_title__c='salesrep';
    insert contact; 
    Contact contact2 = new contact(lastname='lname');
    insert contact2;  
    
  

    Test.startTest();
    
    string searchString='search';
        PageReference pageRef = Page.CustomInfluencerLookup;
        Test.setCurrentPage(pageRef);

        ApexPages.currentPage().getParameters().put('accplanid', accountplan.Id);
        ApexPages.currentPage().getParameters().put('lksrch', searchString);
        CustomInfluencerLookupController controller = new CustomInfluencerLookupController();       
           controller.runSearch();
            controller.getFormTag();
             controller.getTextBox();
        
    Test.stopTest();       
         
        
   }
   }

 

 

 Thank you in advantage for any explanation.

BR

 

It's almost my first test class, please anyone can help me.

I get 0% covered by test class for my custom controller:

My class:

 

public with sharing class MyCustomLookupController {

   public Influencer__c Influencer { get; set; }

   public Id accountplanid { get; set; }
      
   public MyCustomLookupController () {
       accountplanid = System.currentPageReference().getParameters().get('id');
       Influencer = new Influencer__c(Account_Plan__c = accountplanid );
   }
    

 
 

    public PageReference save() {
      
        Contact c = [SELECT Job_title__c,name FROM Contact WHERE Id = :Influencer.Contact__c];
        
        Influencer.Title__c = c.Job_title__c;
        influencer.name=c.name;
        insert Influencer;
        PageReference acctPage = new PageReference('/' + Influencer.id);
        acctPage.setRedirect(true);
        return acctPage;
    }
    
    
       public PageReference cancel() {
      
        PageReference aPage = new PageReference('/' + accountplanid);
        aPage.setRedirect(true);
        return aPage;
    }
       
 
}

 

My test class:

@isTest 
private class MyCustomLookupControllerTestClass {
    static testMethod void validate() {


    PageReference pageRef = Page.MyCustomLookup; 
    Test.setCurrentPage(pageRef);
    
    // Create a new account object.
    Account testAccount = new Account(Name = 'TestAccount');
    testAccount.Red_Account_End_Date__c=date.today();
    testAccount.Red_Account_Reason__c='reason';
    testAccount.Red_Account__c= true;
    insert testAccount;
  
    
    //CREATE TEST ACCOUNT PLAN
     Account_Plan__c accountplan=new Account_Plan__c ();
     accountplan.account__c=testaccount.id;
     insert accountplan;
    
    //CREATE TEST CONTACT
     Contact contact = new contact(lastname='lname');
     contact.Job_title__c='salesrep';
     insert contact; 
     Contact contact2 = new contact(lastname='lname');
     insert contact2;  
    
    //CREATE TEST INFLUENCER
       Influencer__C influencertest = new Influencer__c();
       influencertest.Account_Plan__c= accountplan.id;
       Influencertest.Title__c = contact.Job_title__c;
        influencertest.contact__c=contact2.id;
       insert influencertest;     
         
        
   }

     }

 

 

Sorry, I have to learn a lots of things.

Thank you,Br.