• Dream_weaver
  • NEWBIE
  • 25 Points
  • Member since 2012

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

I created a custom object called Feature.  For each Feature, I've added multiple Products.  On an Opportunity, I made a lookup field to the Feature object.

When I add a Feature, the trigger should add all the Products associated to that Feature as product line items into the Opportunity. 

The code works for After Insert, but will not work for After Update.  I get the error if I try to do an update.  Is there something I can do to my code to get this trigger to work after an update?

trigger OpportunityTrigger2 on Opportunity (after insert, after update) {
// List containing each Opportunity being processed
list<Opportunity> OppId = new list<Opportunity>();
// Go through each opportunity and add it to the OppId list 
for(Opportunity l:trigger.new) {
//Now add them to the list
OppId.add(l); 
}

// Now for each Opportunity in the list
for (Opportunity l:OppId) {
// Get the ID for the Feature of that Opportunity
Id FeatureId = l.Feature__c;
// Now I have the Id of the feature, create a list of the products for that feature
list<Product2> theprod = [SELECT Id, Name FROM Product2 WHERE Features__c = :FeatureId ];  

// Now lets go through each of these products
for (Product2 p:theprod) {
// Now lets get the details we need from the price book entry to insert our Opportunity line item
list<PricebookEntry> TheEntry = [SELECT Id, UnitPrice, Name, Product2Id FROM PricebookEntry where Product2id = :p.id and Pricebook2Id = '01sA00000001tiRIAQ'];
// For each of these pricebook entries
for (PricebookEntry e:TheEntry) {
// Create a new opportunity line item
OpportunityLineItem newoppprod = new OpportunityLineItem(
    // This tells the line item which opportunity to link it to
    opportunityId = l.id,
    // Add the quantity, which is usually always 1
    Quantity = 1,
    // Add the Price
    UnitPrice = e.UnitPrice,
    // Add the pricebook entry ID to tell it what the line item links to in the pricebook entry
    PricebookEntryId = e.id
);
// and now insert that line item
insert newoppprod;
}

}
}
}

 

 

  • November 05, 2012
  • Like
  • 0

Hi ,

 

I tried to connect 2 DEV orgs, using SAML using the steps given the following link

http://wiki.developerforce.com/page/Implementing_Single_Sign-On_Across_Multiple_Organizations

 

Has anyone ever tried it ?

 

I am not able to access the Identity Provider Login URL for SP account's SSO settings..It shows "Insufficient priviledge".

So I am not able to login using my domain(https://domainname.my.salesforce.com/)...It displays the following error...

 

"

Error: Unable to resolve request into a Service Provider

"

Any Idea how can I resolve this?

can I access change set through Apex code /metadata?

I tried to set up facebook authentication provider using the steps mentioned in the link below

 

http://help.salesforce.com/HTViewHelpDoc?id=sso_provider_facebook.htm&language=en_US#facebook_define

 

used the follwing apex class as Registration Handler  class

 

global class StandardUserRegistrationHandler implements Auth.RegistrationHandler{
global User createUser(Id portalId, Auth.UserData data){
    User u = new User();
    system.debug('Auth.UserData :'+ data);
    Profile p = [SELECT Id FROM profile WHERE name='Customer Portal User'];
    u.username = data.username + '@salesforce.com';
    u.email = data.email;
    u.lastName = data.lastName;
    u.firstName = data.firstName;
    String alias = data.username;
    if(alias.length() > 8) {
        alias = alias.substring(0, 8);
    }
    u.alias = alias;
    u.languagelocalekey = data.locale;
    u.localesidkey = data.locale;
    u.emailEncodingKey = 'UTF-8';
    u.timeZoneSidKey = 'America/Los_Angeles';
    u.profileId = p.Id;
    return u;
}

global void updateUser(Id userId, Id portalId, Auth.UserData data){
    User u = new User(id=userId);
    u.username = data.username + '@salesforce.com';
    u.email = data.email;
    u.lastName = data.lastName;
    u.firstName = data.firstName;
    String alias = data.username;
    if(alias.length() > 8) {
        alias = alias.substring(0, 8);
    }
    u.alias = alias;
    u.languagelocalekey = data.locale;
    u.localesidkey = data.locale;
    update(u);
}
}

 

but the functionality is not working..Infact nothing is coming in debug log also..Has any one ever tried the example ??

<apex:outputPanel id="thevotepanel">
<apex:vote id="thevote" objectId="{!article.id}" rerender="thevotepanel" />
</apex:outputPanel>

 

it is showing insufficient priviledge..I am working as Sysadmin user...I tried even removing rerender option...still not working...

when I am displaying only {!article.id}---it is showing the Id in VF page.

 

Any one knows how to handle???

 

Is it possible? It would have saved a lot of effort of writing  similer VF pages of different  controller..

Can we use----var x={!method} ?? in javascript...not working for me..

 

Using <action function >we can access controller method but the method is 'pagereferece' type so it will return null...I want to return a value from controller method to javascript.....How to do?

 

 

 

Workflow rules are not firing on idea merge...Pls suggest Is it possible?????

For displaying an PDF I used <object type='application/pdf' but it only opens PDF article..How to open a word doc? what is the object type format of word doc? is there any master object type that will allow any type of document..!!! please help!!

Can we get Portal-ID of a customer portal for a user by code? It there any field which relates to specific CP ,the user belongs from user record or from user profile.....

 

Requirement is to identify the specific customer portal in which the user belongs...I will render a VF page based on the customer portal....

I have the following VF page...

 

<apex:pageBlock title="SearchArticle" id="SearchArticle">

  <apex:outputLabel value="MagaZine" for="MagaZine"/>
                    <apex:selectList value="{!selectedMagaZine}" multiselect="false" size="1" id="selecMagaZine">
                        <apex:selectOptions value="{!soMagaZine}"/>
                    </apex:selectList>

   </apex:pageBlock>

 

Where from Controller I am getting the Dropdown List...Requirement doesnot allow me to change controller....

I have to sort the dropdown values in VF page level using Jscipt on Window.Onload...Please help me to write the JS.....

I have created a CSV file and using Test.Load data I am able to get the corresponding record of the object.But my question is When I will require to insert a record of a object which is related to the earlier inserted object, how will I use Test.load data...Exmp

 

I have inserted Account object related data using Test.Load data.But in the same test method I need to insert Contact object related record.How will I do it?

 

I have tried in the following way....

List<sObject> ls = Test.loadData(Account.sObjectType, 'testAccounts');
  Account a1 = (Account)ls[0];
 List<sObject> con = Test.loadData(Contact.sObjectType, 'TestContacts');
   Contact newContact=(Contact)con[0];
   newContact.accountid=a1.id;
 update newContact; 

 

  Any way around??????????????

I tried the following way but only one contact is getting updated.....

 
   if(trigger.isUpdate)
   {
      list<id> ids=new list<id>();
      for(account ac:trigger.new)
      {
        ids.add(ac.id);
      }
      list<contact> con=new list<contact>();
      list<contact> updtcont=new list<contact>();
      map<id,contact> map1=new map<id,contact>();
      con=[select accountid,MailingStreet,MailingCity,MailingState,MailingCountry from contact where accountid in:ids ];
      
      for(contact cont:con)
      {
         map1.put(cont.accountid,cont);
      }
     for(account ac:trigger.new)
      {
             if(map1.containsKey(ac.id))
       {
                 map1.get(ac.id). MailingStreet=ac.BillingStreet;
                 updtcont.add(map1.get(ac.id));
       }
      }
      try
      {
        if(!updtcont.isEmpty())
       {
       
        update updtcont;
       
        }
      }
     
      catch(Exception e)
   {
      Error_Reporting__c err= new Error_Reporting__c();
      err.Reason__c=e.getMessage();
      err.Record_Id__c=updtcont.get(0).id;
       insert(err);
   
   }

I have a custom object which will capture error logs..Custom validation errors are listed in the object successfully..but standard errors are not listed..I have used Try catch block...Any suggestion  please!!!!!!!..It is possible in Salesforce at all ????

I have a input field--  <apex:inputField value="{!Registration__c.Event__c}" label="Event" id="Event" />

Now i want to fetch the field value before saving the data into database..

I have called a JScript on clicking of save button..

function Check()
{
var data=document.getElementById('page:form:block:section:Event');-->differenrt page level ids
alert("Do you want to register for "+data.value.name+"?");
}

But it is returning "Undefined" !!! I think it is because the data is not saved yet! Please guide...

 

Is it possible? It would have saved a lot of effort of writing  similer VF pages of different  controller..

Does anybody knows how to change the AXIS title font size???


<apex:axis title="Opps" fields="data" type="Category" position="bottom" grid="true" minimum="0" dashSize="1">
    <apex:chartLabel font="10px Helvetica, sans-serif" "/>
</apex:axis>

the above syntax is only changing the font size for each value in the DATA COLLECTION of my chart, but I want to set the "Opps" title to 10px font size....

I have written a trigger to fill some lookup fields depending on a given number

it worked fine until you try to mass update.

here is the trigger

trigger getTradingAccountUPD on Case (before update) {
List<Contract> abc = new List<Contract>();
List<Account> mta = new List<Account>();

for(Case oldCase :trigger.old){
    if(oldCase.Trading_Account__c == null && oldCase.Master_trading_Account__c == null && oldCase.Customer__c == null){

for(Case nCase :trigger.new){
    if(nCase.Legacy_Account_Number__c != null){
        nCase.System_Notification__c ='';
        abc = [SELECT Id,AccountId FROM Contract WHERE Legacy_Account_Number__c =: nCase.Legacy_Account_Number__c LIMIT 1];
        if(abc.size()>0){
           
              nCase.Trading_Account__c = abc[0].Id;
              nCase.Master_Trading_Account__c = abc[0].AccountId;
              mta = [SELECT ID,ParentId FROM Account WHERE Id =: abc[0].AccountId LIMIT 1];
              if(mta[0].Id != null) {
                  nCase.Customer__c = mta[0].ParentId;    
                  }  
            }
         if(abc.size() == 0) {
             mta = [SELECT Id,ParentId FROM Account WHERE Legacy_Account_Number__c =: nCase.Legacy_Account_Number__c LIMIT 1];
             if(mta.size() >0) {
             nCase.Master_Trading_Account__c = mta[0].Id;
             if(mta[0].ParentId != null) {
                 nCase.Customer__c = mta[0].ParentId;
                 }
             }    
          }
          if((abc.size()==0) && (mta.size()==0)){
              nCase.System_Notification__c = '(NOT FOUND IN DATABASE)';
              }
        }
     }
   }
  }
}

 Okay I saw that the select query is in the loop so i moved my head around and came up with the following

 

 

trigger getTradingAccountUPD on Case (before update) {

List<Account> cus = new List<Account>();

Set<id> mta = new Set<id>();
Map<id,String> cases = new Map<id,String>();

 for(Case oldCase :trigger.old){
    if(oldCase.Trading_Account__c == null && oldCase.Master_Trading_Account__c == null && oldCase.Customer__c == null){
       for(Case ncase :trigger.New){
          cases.put(ncase.Id,ncase.Legacy_Account_Number__c);
          ncase.System_Notification__c = '';
       }
    }
 }
Set<Contract> ta = new Set<Contract>([SELECT Id,AccountId,Legacy_Account_Number__c FROM Contract WHERE Legacy_Account_Number__c IN : cases.values() Limit 1]);
If(!ta.isEmpty()){
  for(Case ncase :trigger.New){
    if(ncase.Legacy_Account_Number__c != null){
        for(Contract lan : ta){
            if(ncase.Legacy_Account_Number__c.equals(lan.Legacy_Account_Number__c)){
                ncase.Trading_Account__c = lan.id;
                mta.add(lan.AccountId);
            }
        }
    }
   }
 }
 if(!mta.isEmpty()){
     List<Account> acc = new List<Account>([SELECT Id,ParentId FROM Account WHERE Id IN : mta]);
     for(Case ncase :trigger.New){
       ncase.Master_Trading_Account__c = acc[0].Id;
       if(acc[0].ParentId != null){
           ncase.Customer__c = acc[0].ParentId;
           }
       }
  }      
 if(ta.isEmpty() && mta.isEmpty()){
     List<Account> amaster = new List<Account>([SELECT Id,ParentId,Legacy_Account_Number__c FROM Account WHERE Legacy_Account_Number__c IN : cases.values()]);
        if(!amaster.isEmpty()){
          for(Case ncase :trigger.New){
            ncase.Master_Trading_Account__c = amaster[0].Id;
            if(amaster[0].ParentId != null){
              ncase.Customer__c = amaster[0].ParentId;
            }
          }
        } 
        else if ((amaster.isEmpty()) &&(ta.isEmpty() && mta.isEmpty()) ){
          for(Case oldCase :trigger.old){
              if(oldCase.Trading_Account__c == null && oldCase.Master_Trading_Account__c == null && oldCase.Customer__c == null){
                 for(Case ncase :trigger.New){
                    ncase.System_Notification__c = 'NOT FOUND';
                 }
               }  
           } 
         }    
 }
    
           
}

 but now my test class runs into the same System.LimitException: Too many SOQL queries: 101 issue at

Set<Contract> ta = new Set<Contract>([SELECT Id,AccountId,Legacy_Account_Number__c FROM Contract WHERE Legacy_Account_Number__c IN : cases.values() Limit 1]);

 

Any Idea how can I avoid that issue, because there are regular updates with the data loader

 

some backgroud

the account number is an external id which will be pulled into the legacy_account_number_ c

 

this number is pointing to a Contract object ( unique ), depending on that contract I need to pull the

ID of the related Account Object from that Contract and if any the parent account of that account.

 

I just wonder if there is anything else I could render to avoid the SQL limits

 

Thanks in advance

 

my testclass looks like that

@isTest(SeeAllData=true) 
public class getTradingAccountTest {
static testMethod void test_getTradingAccount(){
 Test.startTest();
        Case cs = new Case();
        cs.email__c = 'test.test@gmail.com';
        cs.Preferred_Reply_Method__c = 'Letter';
        cs.Post_Code__c = '95050';
        cs.Phone__c = '408123123';
        cs.First_Line_of_Address__c = 'test address';
        cs.Tracking_Job_Number__c = '1234567';
        cs.Consignment_Number__c = '24242323';
        cs.description= 'test';
        cs.Account_Number__c = '38J010W';
        insert cs;
        
        Case ds = new Case();
        ds.email__c = 'test.test@gmail.com';
        ds.Preferred_Reply_Method__c = 'Letter';
        ds.Post_Code__c = '95050';
        ds.Phone__c = '408123123';
        ds.First_Line_of_Address__c = 'test address';
        ds.Tracking_Job_Number__c = '1234567';
        ds.Consignment_Number__c = '24242323';
        ds.description= 'test';
        ds.Account_Number__c = 'test0001';
        insert ds;
        
        Case es = new Case();
        es.email__c = 'test.test@gmail.com';
        es.Preferred_Reply_Method__c = 'Letter';
        es.Post_Code__c = '95050';
        es.Phone__c = '408123123';
        es.First_Line_of_Address__c = 'test address';
        es.Tracking_Job_Number__c = '1234567';
        es.Consignment_Number__c = '24242323';
        es.description= 'test';
        es.Account_Number__c = 'rolle roe';
        insert es;
        
        //for code coverage in the controller
        NewCaseController x = new NewCaseController();
        x.trackAccount(cs);
        x.trackAccount(ds);
        x.trackAccount(es);
        //end of code coverage in controller
        
        es.Legacy_Account_Number__c = '38J010W';
        update es;
        es.Legacy_Account_Number__c=null;
        es.Trading_Account__c=null;
        es.Master_Trading_Account__c=null;
        es.Customer__c=null;
        update es;
        es.Legacy_Account_Number__c='test0001';
        update es;
        es.Legacy_Account_Number__c=null;
        es.Trading_Account__c=null;
        es.Master_Trading_Account__c=null;
        es.Customer__c=null;
        update es;
        es.Legacy_Account_Number__c='nope';
        update es;
        
        Test.stopTest();
}
}

 

 

  • March 27, 2013
  • Like
  • 0

Can we use----var x={!method} ?? in javascript...not working for me..

 

Using <action function >we can access controller method but the method is 'pagereferece' type so it will return null...I want to return a value from controller method to javascript.....How to do?

 

 

 

Workflow rules are not firing on idea merge...Pls suggest Is it possible?????

For displaying an PDF I used <object type='application/pdf' but it only opens PDF article..How to open a word doc? what is the object type format of word doc? is there any master object type that will allow any type of document..!!! please help!!

what is the use of  DML  operations and select statements in triggers??

  • December 12, 2012
  • Like
  • 0

can we perform two different actions like send email & feild update in workflows?

  • December 12, 2012
  • Like
  • 0

I have the following VF page...

 

<apex:pageBlock title="SearchArticle" id="SearchArticle">

  <apex:outputLabel value="MagaZine" for="MagaZine"/>
                    <apex:selectList value="{!selectedMagaZine}" multiselect="false" size="1" id="selecMagaZine">
                        <apex:selectOptions value="{!soMagaZine}"/>
                    </apex:selectList>

   </apex:pageBlock>

 

Where from Controller I am getting the Dropdown List...Requirement doesnot allow me to change controller....

I have to sort the dropdown values in VF page level using Jscipt on Window.Onload...Please help me to write the JS.....

I tried the following way but only one contact is getting updated.....

 
   if(trigger.isUpdate)
   {
      list<id> ids=new list<id>();
      for(account ac:trigger.new)
      {
        ids.add(ac.id);
      }
      list<contact> con=new list<contact>();
      list<contact> updtcont=new list<contact>();
      map<id,contact> map1=new map<id,contact>();
      con=[select accountid,MailingStreet,MailingCity,MailingState,MailingCountry from contact where accountid in:ids ];
      
      for(contact cont:con)
      {
         map1.put(cont.accountid,cont);
      }
     for(account ac:trigger.new)
      {
             if(map1.containsKey(ac.id))
       {
                 map1.get(ac.id). MailingStreet=ac.BillingStreet;
                 updtcont.add(map1.get(ac.id));
       }
      }
      try
      {
        if(!updtcont.isEmpty())
       {
       
        update updtcont;
       
        }
      }
     
      catch(Exception e)
   {
      Error_Reporting__c err= new Error_Reporting__c();
      err.Reason__c=e.getMessage();
      err.Record_Id__c=updtcont.get(0).id;
       insert(err);
   
   }

I created a custom object called Feature.  For each Feature, I've added multiple Products.  On an Opportunity, I made a lookup field to the Feature object.

When I add a Feature, the trigger should add all the Products associated to that Feature as product line items into the Opportunity. 

The code works for After Insert, but will not work for After Update.  I get the error if I try to do an update.  Is there something I can do to my code to get this trigger to work after an update?

trigger OpportunityTrigger2 on Opportunity (after insert, after update) {
// List containing each Opportunity being processed
list<Opportunity> OppId = new list<Opportunity>();
// Go through each opportunity and add it to the OppId list 
for(Opportunity l:trigger.new) {
//Now add them to the list
OppId.add(l); 
}

// Now for each Opportunity in the list
for (Opportunity l:OppId) {
// Get the ID for the Feature of that Opportunity
Id FeatureId = l.Feature__c;
// Now I have the Id of the feature, create a list of the products for that feature
list<Product2> theprod = [SELECT Id, Name FROM Product2 WHERE Features__c = :FeatureId ];  

// Now lets go through each of these products
for (Product2 p:theprod) {
// Now lets get the details we need from the price book entry to insert our Opportunity line item
list<PricebookEntry> TheEntry = [SELECT Id, UnitPrice, Name, Product2Id FROM PricebookEntry where Product2id = :p.id and Pricebook2Id = '01sA00000001tiRIAQ'];
// For each of these pricebook entries
for (PricebookEntry e:TheEntry) {
// Create a new opportunity line item
OpportunityLineItem newoppprod = new OpportunityLineItem(
    // This tells the line item which opportunity to link it to
    opportunityId = l.id,
    // Add the quantity, which is usually always 1
    Quantity = 1,
    // Add the Price
    UnitPrice = e.UnitPrice,
    // Add the pricebook entry ID to tell it what the line item links to in the pricebook entry
    PricebookEntryId = e.id
);
// and now insert that line item
insert newoppprod;
}

}
}
}

 

 

  • November 05, 2012
  • Like
  • 0

I have a input field--  <apex:inputField value="{!Registration__c.Event__c}" label="Event" id="Event" />

Now i want to fetch the field value before saving the data into database..

I have called a JScript on clicking of save button..

function Check()
{
var data=document.getElementById('page:form:block:section:Event');-->differenrt page level ids
alert("Do you want to register for "+data.value.name+"?");
}

But it is returning "Undefined" !!! I think it is because the data is not saved yet! Please guide...

 

I cannot get the hover lists to work for a visualforce page for the account object. I have a visualforce page with built to simply show the detail page of the Account object, within an iframe. I know iframes are not recommended, but it is entirely necessary for this project. The detail page is working fine, however the hover lists and when drilling into the account record, the related lists of related records are not working just showing a forever running spinner.

 

Here is the code for this page:

 

<apex:page standardController="Account" sidebar="false">
<apex:detail subject="{!Account.Id}" relatedList="true" relatedListHover="true" />
</apex:page>

 

The hover lists work when viewing the Account in the visual force page. However when housed in an iframe those hover lists do not work.

 

This issue is only true for Chrome, the hover lists do work for Firefox. 

 

Any ideas or help would be much appreciated.

 

Thanks.

 

Hi,

 

Can we have capture Merge operationfor Ideas? According to Apex guide, when merge occurs trigger for after and before delete will be called. I tried with a trigger having all the events, but it does not fire on the click of Merge button for Ideas.

Please help.

  • August 04, 2011
  • Like
  • 0

I am having the enterprise.wsdl file and i am trying to create a jar file using command 

 

java -classpath wsc-20.jar com.sforce.ws.tools.wsdlc enterprise.wsdl enterprise.jar

 

but getting an error "Error: Unable to find compiler. Make sure that tools.jar is in your classpath:

java.lang.ClassNotFoundException: com/sun/tools/javac/Main.class"

 

can anyone help me..............

 

thank you.......................

I am trying to add a comment on the idea(auto-comment), which is getting merged with a master idea.

I am planning to do this using  a trigger, can anyone help with how to write the trigger?

  • July 22, 2009
  • Like
  • 0
There are acutally two parts to this question.

The first is that I have command button that should call a javascript function. This javascript function would then call a method in the controller that returns a boolean.

Code:
Part 1:

Here is my button and the JS function, I think my syntax is messed up as I am not getting a popup alert when clicking the button:
<apex:commandButton onclick="submit()" value="Overwrite Reseller Data & Abandon Opportunity" styleClass="btn"/>

<script language="JavaScript">

function submit(){
    alert('test');
}

</script>

Part 2:
In the JS function I need to call a method in the controller that returns a boolean value that indicates if the action was successful.

function submit(){
boolean result = {!submit};
}

But this tells me a getter method is not defined. In the controller I have this:

public
boolean submit() {
boolean result = true;
do some stuff
return result;
}


Before someone says use the action attribute of the command button here is how everything ties together. This page is actually being called from a formula field hyper link as we can place this anywhere on a page layout, unlike custom links (feature request). So when using a formula field link the window is a popup that displays the VF page. In this page the user will hit submit and this will execute the logic. The reason I need to call this from javascript is that I need to add some nice JS functions. If the logic in the controller method is a success I need to close the popup window (window.close) but if it fails I need to keep it open so that the error message can be displayed.

Thanks for the help!


Message Edited by TehNrd on 04-15-2008 02:53 PM
  • April 15, 2008
  • Like
  • 0