• Moggy
  • NEWBIE
  • 128 Points
  • Member since 2012

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 72
    Replies
I am working on trying to have a field be requiered on a VF page while not being so in Salesforce. There are flows and process buidler applications that are preventing this so here is what I have:

<td><apex:inputfield value="{!ClientProfile__c.Primary_Parts_Supplier__c}" required="true" id="PrimaryPartsSupplier" /></td>

It does show as requiered but still allow me to save the page w/o a value.

Once I can get this to work, is there a way to set it so that one of 3 fields need to be completed prirot be being saves?

Thanks
Hi All,

I want to update the few fields of converted leads. So can you guys please help me and let me know how can update it. 

Thanks in advance

Hi,

 

The trigger below was created to update all records on the Opportunity when Field_1__c on Object__c is updated.  The trigger works fine when updates are done on the detail page but fails when updating more than 1value using data loader.  I receive the error:  List index out of bounds.  Any help would be greatly appreciated.  Code copied below.

 

Thank you,

 

trigger EstimatedUpdateOnOpp on Estimated_Capital_Adder__c (before update)
{


     list<Opportunity> listUpdate = new list<Opportunity>();
     list<Opportunity> listOppUpdate = new list<Opportunity>();
     Integer j = 0;
     Integer i = 0;

     for(Object__c obj : Trigger.new)
     {
         if (trigger.new[j].Field_1__c != trigger.old[j].Field_1__c)
         {
            set<string> setI = new set<string>();
            set<Decimal> setM = new set<Decimal>();
            set<string> setP = new set<string>();

            

                    setI.add(obj.Field_I__c);
             setM.add(obj.Field_M__c);
             setP.add(obj.Field_P__c);

         
             listOppUpdate = [SELECT id,
                                     Field_I_2__c,
                                     Field_M_2__c,
                                     Field_P_2__c,
                                     Field_E__c,
                                     StageName
                               FROM Opportunity
                              WHERE Field_I_2__c IN :setI
                                AND Field_M_2__c IN :setM
                                AND Field_P_2__c IN :setP
                                AND (StageName != 'Won' AND StageName != 'Lost' AND StageName != 'Terminated')
                                AND Field_Co__c = 'Prod'];
            
            

        
            for(Opportunity opp : listOppUpdate)
            {
      
                Opportunity Updates = new Opportunity (Id = listOppUpdate[i].Id,
                                                       Field_E__c = trigger.new[j].Field_1__c
                                                       );
                listUpdate.add(Updates);
            i++;         
            } // for(Opportunity opp : listOppUpdate)
            
           update listUpdate;    
           system.debug('listUpdate:  '+listUpdate);
           
           
                          
         }
             
    j++;
     }

}

 

  • January 28, 2013
  • Like
  • 0

Hey all,

is there anybody who could post a sample code for a lightning component and controller to integrate with WorldPay's 3ds secure payment gateway if that is possible at all.

I have read all about their API's but it is all based on standard web not Salesforce.

For Salesforce there is an appExchange pack but that requires the commerce cloud , so this is not applicable 

The Chargent package is also not applicable as it does not support Wordlpay UK only US

So I wonder , there must be someone out there who did this integration and might like to share some insight ( code sample) please

I have a payment form for the inputs, and works well with the standard https://api.worldpay.com/v1/tokens and orders but this is deemd not to be 3Ds

Any help wuld be appreciated

  • February 12, 2021
  • Like
  • 0

HI All,

is there a way to activate a community via apex code.

The requirement is after a sandbox refresh, we run a class which creates all data needed for succesful testing , only bit left is the activation of the community , it would be nice to remove the needed admin step to login and activate the community, as contact, user and account are all there, its just the community is not active

Anyone has anything to share which works?

I know the workaround is to log in and do the setup bit, but i like to remove this administration step

  • November 15, 2020
  • Like
  • 0

We all know how to use an image inside a formula field

(IMAGE(URL, Alternate Text, H,W)

In Lightning we can use <img src=..... onError....

My question is prteey simple:

is there any way to figure out (system) not by viewing if the formula is actually displaying an image.

Or differently phrased is there a way to find out if the image url will return nothing and therefoe display the alternate text / show an on error image which might be there or not, hence my question 

Sure we use the formula to display images we know about but what if the image is sitting in the cloud and someone deleted it

a formula or img src tag does not do a http callout, so how to find out if its a shown image in that field or not??

  • August 14, 2020
  • Like
  • 0
I am tasked to force a product onto an opportunity while lead conversion, and in standard environment its an easy go, but with multi currency this seems to be a no go as it looks like that Salesforce internal referencing is at random.

I have created a map ( found something similar in the net ) where I hold the pricbookentry by isocode 
once a currency is chosen in the page , the product slection will be populated
that all works fine and i get only those products shwon which are available at a certain currency but if i then start the convert it throws at 98% the time the above error and if I system.debug i get show that 
Lead Currency equals the opportunity currency and also the pricebookentry currency but not the product currency
I also exported the pricebookentry and observed that the ID of the entry is unique against product pricebook and currency but the product id is for all currencies the same that is why i think that it might be an server interanl issue but who knows maybe i just misssed something
Can you have a look if i miss something here

here the piece where i collect all Pricebookentries  PBID is [select Id from Pricebook2 where isStandard=true]
private void popPBE(){
        PBISO = new Map<Id,Map<String,Map<Id,PriceBookEntry>>>();
        List<PriceBookEntry> opal = new List<PriceBookEntry>([SELECT Id, Name,PriceBook2Id, Product2Id, CurrencyIsoCode FROM PriceBookEntry WHERE
                                        PriceBook2Id =: PBID AND IsActive =: True AND IsDeleted =:False]);
        for(PriceBookEntry pri: opal)
        {
            if(!PBISO.containsKey(pri.PriceBook2Id))
            {
                PBISO.put(pri.PriceBook2Id,new Map<String,Map<Id,PriceBookEntry>>());
             }
            if(!PBISO.get(pri.PriceBook2Id).containsKey(pri.CurrencyIsoCode))
            {
              
               PBISO.get(pri.PriceBook2Id).put(pri.CurrencyIsoCode,new Map<Id,PriceBookEntry>());
             }
          
            PBISO.get(pri.PriceBook2Id).get(pri.CurrencyIsoCode).put(pri.Id,pri);
          
        }                               
    }

This seems to be ok as the products are correct populated in the selectOption as below

public void populateProducts() {
        products = new List<selectOption>();
        products.add(new SelectOption('None',' ',false));
        System.Debug('######## PBID=' + PBID + ' ##### ISOC=' + isoc + ' ##### ');  // this showed the correct Pricebook ID and the correct CurrencyIsoCode
        for(PriceBookEntry x: PBISO.get(PBID).get(isoc).values())
       {
           products.add(new SelectOption(x.id,x.Name));
          
       }
       
    }

Now when the product gets selected in the page, I do the following (as you can see  I tried 2 way, without success)

public PageReference productChanged() {
      //List<PriceBookEntry> priceBookList = [SELECT Id,Name, PriceBook2Id, Product2Id, CurrencyIsoCode FROM PriceBookEntry  
      //          WHERE     Id =: selectedProduct LIMIT 1];
     //OppItemID.PricebookEntryId = priceBookList[0].Id;
    OppItemID.PricebookEntryId = selectedProduct;
    
     return null;
     }

the currency selection is as follows and alredy needed a nasty trick to get this in the right direction
( I needed to update the lead record wth the selected currency if it was different to the original )

populate the diff currencies

private void popcurrency(){
        curre = new List<selectOption>();
        curre.add(new SelectOption('none','-NONE-',true));
        if(curren == null){
        curren = new List<CurrencyType>([SELECT Id, ISOCode FROM CurrencyType WHERE IsActive=:true]);
        }
        for(CurrencyType x: curren)
        {
          
            curre.add(new SelectOption(x.id,x.ISOCode));
        }
      }

change of the currency via page

public PageReference curreChanged() {  
     
  
   List<CurrencyType> ex = [SELECT ISOCode FROM CurrencyType WHERE Id=: Currencyselected LIMIT 1];
     this.Currencyselected = Currencyselected ;
     isoc =ex[0].ISOCode;
     leadConvert.CurrencyIsoCode=isoc;
    
     opportunityId.CurrencyIsoCode=isoc;
     system.debug('iso: ' + isoc);
    
     populateProducts();
     return null;
     }

this works all fine beside the fact the the final Product is not in the correct currency ???
and strange on this is theat the WHERE  Id =: selectedProduct within the productChange()
holds the correct ID of the correct PriceBookEntry record, I am a bit confused why the product then is not

Please help
  • August 08, 2014
  • Like
  • 0

Hi , we have a good hierarchy from account which can have multiple childs and these

child can have multiple opportuniies and contracts, and the contracts can also have multiple cases

 

AS requested I made an over view of that all on the TOP level ( Account) , depending on the data involved

the loading time takes, I have around 6 or 7 VF elements in the Account standard layout.

Is there a way to load the standard page , showing these VF pages "Loading.." and refreshing itself once

the controller is done? either all at once or every single VF element .

It is one controller, no Page references just {!get something} embedded within HTML tables

as sample would be

<apex:page standardController="Account" extensions="relatedListsController"> 
 
<apex:form >
     
    <apex:pageBlock title="Case's" tabStyle="Account">
        <apex:pageBlockSection title="Case's last 30 Days: {!ccc3} record(s) - Open Case's: {!casecount2}  - Total {!casecount} record(s) " >
        <apex:outputPanel id="rowArea" layout="inline">
      <table id="conTable" cellspacing="10" style="border:0px !important;border-bottom:2px;">
                     <thead>
                          <tr>
                              <th>Case Number</th>
                              <th>Consignment Number</th>
                              <th>Type</th>
                              <th>Reason</th>
                              <th>Depot</th>
                              <th>Status</th>
                              <th>Created Date</th>
                              <th>Closing Comments</th>
                              
                            <!--  <th>Region</th>
                             <th>Postcode</th>
                              <th>Address Lookup</th>-->
                          </tr>
                      </thead>
      <tbody id="clist">
      <apex:repeat value="{!mycas3}" var="visicc" id="reptabl">
                 <tr>
                   <td style="border-top:0px;border-bottom:0px;padding-left:10px;">
                    
                      <apex:outputLink target="_blank" value="/{!visicc.Id}">{!visicc.CaseNumber}</apex:outputLink>  
                    
                 </td>
                 <td style="border-top:0px;border-bottom:0px;">
                       <apex:outputField value="{!visicc.Tracking_Job_Number__c}" id="tj"/>
                </td>
                <td style="border-top:0px;border-bottom:0px;">
                    <apex:outputField value="{!visicc.Type}" id="ty"/>
                 </td>
                <td style="border-top:0px;border-bottom:0px;">
                    <apex:outputField value="{!visicc.Reason}" id="rea"/>
                 </td>
                 <td style="border-top:0px;border-bottom:0px;">
                    <apex:outputField value="{!visicc.Depot_Number__c}" id="dp"/>
                 </td>
                 <td style="border-top:0px;border-bottom:0px;">
                    <apex:outputField value="{!visicc.Status}" id="st"/>
                 </td>
                 <td style="border-top:0px;border-bottom:0px;">
                    <apex:outputField value="{!visicc.CreatedDate}" id="cd"/>
                 </td>
                 <td style="border-top:0px;border-bottom:0px;">
                    <apex:outputField value="{!visicc.Comments__c}" id="cc"/>
                 </td>
                 
              </tr>
              <tr style="background-color:gray;border-top:2px;border-bottom:2px;">
              <span>_________________________________________________________</span>
              </tr>
          </apex:repeat> 
        </tbody>
      </table>  
      </apex:outputPanel>      
     </apex:pageBlockSection>
    </apex:pageBlock>

</apex:form>

</apex:page>

 the Cases are already reduced to 100 records and all varibles used by the controller are transient.

I don't mind the loading time itself , it would be just nice to have the standard page loaded and showing all VF elements that they are loading, so that the user knows something is happen.( on big accounts this controller nearly empties the DB )
so you can imagine that it takes a while but it loads...And yes , it only necessary data is loaded no null no archived records

 

I would have tried rerender, but tbh , i have no clue how i should get this into it 5 elements look like the above sample and one is a summarizing (below)

 

<apex:page standardController="Account" extensions="relatedListsController" sidebar="false">

<apex:form >
    <apex:variable value="{!$CurrentPage.parameters.id}" var="cp"/>
    <apex:pageBlock title="Customer summary  " tabStyle="Account" >
    
       <table id="oview" cellspacing="10" style="border:1px !important;border-bottom:2px;">
       <tbody>
       <tr>
           <td> 
           <span>  <b>Status</b> &nbsp;&nbsp; </span><apex:outputText value="   {!sflag}" escape="false"/>
        </td>
        <td> 
           <span>  <b>Financial Indication</b> &nbsp;&nbsp; </span><apex:outputText value="{!fflag}" escape="false"/>
           <span> {!FI}</span>
        </td>
        </tr>
         <tr>
           <td> 
                
                <span><b>Opportunities: </b>{!oppcount} record(s) - Forecast Annual £ {!OppForAn} - Actual Weekly £ {!OppForWe} </span>
            </td>
            <td>
            <span><b>Trading: </b> {!oppcw} &nbsp;&nbsp;&nbsp;<b>Close Lost: </B>{!oppcl}&nbsp;&nbsp;&nbsp;<b>pot. Value other stage's from today:&nbsp; </B>£{!oppiyv}</span>
            </td>
        </tr>
        <tr>
            <td>
                <span><b>Contacts</b> {!pplcount} record(s) </span>
            </td>
            <td>
                <span><b>Master Trading Account(s)</b> {!acccount} record(s)</span>
           </td>
        </tr>
        <tr>
            <td>
                <span><b>Activities</b> {!tascount} record(s) <b>Last Week</b> {!tascountlw} record(s)</span><br></br>
            </td>
            <td>
                <span><b>Trading Account(s)</b> {!tacount} record(s) </span><br></br>
            </td>
            </tr>
        <tr>
            <td>
                <span><b>Competitor held Products</b>: {!compProsize}</span>
            </td>
            <td>
                <span><b>Case's</b> last 60 Days: {!ccc3} record(s) - Open Case's: {!casecount2}  - Total {!casecount} record(s)  </span>
            </td>
        </tr>
        
       </tbody>
      </table> 
      
    </apex:pageBlock>
    
</apex:form>

</apex:page>

 Any idea, help would be nice thanks

 

  • June 11, 2013
  • Like
  • 0

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

Hey all,

is there anybody who could post a sample code for a lightning component and controller to integrate with WorldPay's 3ds secure payment gateway if that is possible at all.

I have read all about their API's but it is all based on standard web not Salesforce.

For Salesforce there is an appExchange pack but that requires the commerce cloud , so this is not applicable 

The Chargent package is also not applicable as it does not support Wordlpay UK only US

So I wonder , there must be someone out there who did this integration and might like to share some insight ( code sample) please

I have a payment form for the inputs, and works well with the standard https://api.worldpay.com/v1/tokens and orders but this is deemd not to be 3Ds

Any help wuld be appreciated

  • February 12, 2021
  • Like
  • 0
Hello,

As I understand, Process Builder runs under the system mode and if the running user doesn't have permission, the user still able to perform the operation due to system mode. I tried to create a chatter post on a case object using Process Builder, by running as a user who has implicit permission on the case. When I looked at the log, it still runs under the user mode (I can see as Current User) and got the following error while creating a chatter post

Error Occurred: You don't have permission to do this. 
________________________________________
________________________________________
Salesforce Error ID: 157378386-59592 (1177104658)

Thanks,
Hi all, I am trying to create a trigger that will autopopulate my lookup field when a value is selected from the picklist however I am getting these errors and I don't know why.

My lookup field is to contact (which is filtered).

User-added image

We all know how to use an image inside a formula field

(IMAGE(URL, Alternate Text, H,W)

In Lightning we can use <img src=..... onError....

My question is prteey simple:

is there any way to figure out (system) not by viewing if the formula is actually displaying an image.

Or differently phrased is there a way to find out if the image url will return nothing and therefoe display the alternate text / show an on error image which might be there or not, hence my question 

Sure we use the formula to display images we know about but what if the image is sitting in the cloud and someone deleted it

a formula or img src tag does not do a http callout, so how to find out if its a shown image in that field or not??

  • August 14, 2020
  • Like
  • 0
Hi Experts,

i have two Picklist .Two pick list are TO and casereason.
whenever user a selected a vlaue with (Com Apg )from To Picklist then (PO Bokeed) with value dispaly in Casereason picklist .
How to we can achive in visualforce page.below i have attached my screen shatUser-added image

Thanks,
VIswa.
Hi there, I am using the following code in visualforce to generate an invoice datew: <apex:repeat value="{!Opportunity.Invoices__r}" var="line2">    {!line2.Invoice_Date__c} but when I click on generate invoice the invoice date shows the time as well 00:00:00 GMT - how do I remove that so it only shows me the date as Day Month Date Year - currently shows me Thu Oct 27 00:00:00 GMT 2016

Please help its taken me 3 days of searching without any success
Our users are receiving the following error when attempting to convert a lead, and SF support has told us it is due to a managed package yet could not identify which. Does anyone have any insight into what package may be causing this, and how to resolve? 

'Error: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, null: [] Class.leadconvert.BulkLeadConvert.handleRegularContactInserts: line 326, column 1 ' 

Any help is much appreciated.

Best,
Julian
HI,

I am trying to check the chkbox on oppty if their are atleast one child record (Lookup relationship to custom object) , If all records attached to Oppty are deleted, this box should be unchecked.

Any suggestions?
I am working on trying to have a field be requiered on a VF page while not being so in Salesforce. There are flows and process buidler applications that are preventing this so here is what I have:

<td><apex:inputfield value="{!ClientProfile__c.Primary_Parts_Supplier__c}" required="true" id="PrimaryPartsSupplier" /></td>

It does show as requiered but still allow me to save the page w/o a value.

Once I can get this to work, is there a way to set it so that one of 3 fields need to be completed prirot be being saves?

Thanks
Hi guys I will appreciate help with this. We use email to case alot in my company. We have a queue A with many cases in it and we have another different queue B.

I want people who work in queue A to be able to send n email from a case in queue A and therefore generate a new case in queue B. We have the email thread on our templates and email subject at the moment and that prevents this from happening.

It will be great if anyone can help.
I have to write test class for this apex code:

public static void CreaEventoCorrispondente() {


        if (trigger.isInsert) {

            Map<Integer, Event> EventstoUpsert1 = new Map<Integer, Event> ();
            Map<Integer, Event> EventstoUpsert2 = new Map<Integer, Event> ();
            List<Schema.PicklistEntry> ple = Edizione__c.Lead_Tutor__c.getDescribe().getPicklistValues();
            List<String> cognomiTutor = new List<String> ();
            for (Schema.PicklistEntry p : ple) {
                cognomiTutor.add(p.getLabel());
            }
            Map<String, Id> CognomiIds = new Map<String, Id> ();
            for (User u :[SELECT Id, LastName FROM User WHERE LastName IN :cognomiTutor]) {
                CognomiIds.put(u.LastName, u.Id);
            }

            integer pos = 0;

        
            for (Edizione__c e : (List<Edizione__c>) trigger.new) {

                if (e.Lead_Tutor__c != NULL && CognomiIds.keySet().contains(e.Lead_Tutor__c)) {
                    Event newEvent1 = new Event(isAllDayEvent = TRUE, Location=e.Sede__c, Subject = e.Name, StartDateTime = (DateTime.newInstance(e.Data_inizio__c , (DateTime.newInstance(e.Data_inizio__c, Time.newInstance(0,0,0,0))).timeGMT())), EndDateTime = (DateTime.newInstance(e.Data_fine__c, (DateTime.newInstance(e.Data_fine__c, Time.newInstance(0,0,0,0))).timeGMT())), OwnerId = CognomiIds.get(e.Lead_Tutor__c));
                    EventstoUpsert1.put(pos, newEvent1);
                }
                if (e.Lead_Tutor__c != NULL && CognomiIds.keySet().contains(e.Second_Tutor__c)) {
                    Event newEvent2 = new Event(isAllDayEvent = TRUE, Location=e.Sede__c, Subject = e.Name, StartDateTime = (DateTime.newInstance(e.Data_inizio__c, (DateTime.newInstance(e.Data_inizio__c, Time.newInstance(0,0,0,0))).timeGMT())), EndDateTime = (DateTime.newInstance(e.Data_fine__c, (DateTime.newInstance(e.Data_fine__c, Time.newInstance(0,0,0,0))).timeGMT())), OwnerId = CognomiIds.get(e.Second_Tutor__c));
                    EventstoUpsert2.put(pos, newEvent2);
                }
                pos++;
            }
            if (!EventstoUpsert1.isEmpty()) {
                insert EventstoUpsert1.values();
                for (Integer i : EventstoUpsert1.keySet()) {
                    Edizione__c ed = ((Edizione__c) trigger.new[i]);
                    ed.IdEventoLeadTutor__c = EventstoUpsert1.get(i).Id;
                }

            }
            if (!EventstoUpsert2.isEmpty()) {
                insert EventstoUpsert2.values();
                for (Integer i : EventstoUpsert2.keySet()) {
                    Edizione__c ed = ((Edizione__c) trigger.new[i]);
                    ed.IdEventoSecondTutor__c = EventstoUpsert2.get(i).Id;
                }

            }

        } else if (trigger.isUpdate) {

            Map<Id, Event> EventstoUpsert1 = new Map<Id, Event> ();
            Map<Id, Event> EventstoUpsert2 = new Map<Id, Event> ();
            List<Schema.PicklistEntry> ple = Edizione__c.Lead_Tutor__c.getDescribe().getPicklistValues();
            List<String> cognomiTutor = new List<String> ();
            List<Id> EventstoDelete = new List<Id>();
            for (Schema.PicklistEntry p : ple) {
                cognomiTutor.add(p.getLabel());
            }
            Map<String, Id> CognomiIds = new Map<String, Id> ();
            for (User u :[SELECT Id, LastName FROM User WHERE LastName IN :cognomiTutor]) {
                CognomiIds.put(u.LastName, u.Id);
            }

            for (Edizione__c e : (List<Edizione__c>) trigger.new) {
                if (e.Lead_Tutor__c != ((Edizione__c) trigger.oldMap.get(e.Id)).Lead_Tutor__c) {
                    if (((Edizione__c) trigger.oldMap.get(e.Id)).Lead_Tutor__c == NULL){
                        Event ev = new Event();
                        ev = new Event(isAllDayEvent = TRUE, Subject = e.Name, Location=e.Sede__c, StartDateTime = (DateTime.newInstance(e.Data_inizio__c, (DateTime.newInstance(e.Data_inizio__c, Time.newInstance(0,0,0,0))).timeGMT())), EndDateTime = (DateTime.newInstance(e.Data_fine__c, (DateTime.newInstance(e.Data_fine__c, Time.newInstance(0,0,0,0))).timeGMT())), OwnerId = CognomiIds.get(e.Lead_Tutor__c));
                        EventstoUpsert1.put(e.Id, ev);
                    } else if (e.Lead_tutor__c == NULL) {
                        EventstoDelete.add(e.IdEventoLeadTutor__c);
                        e.IdEventoLeadTutor__c = NULL;
                    } else {
                        if (((Edizione__c) trigger.oldMap.get(e.Id)).IdEventoLeadTutor__c != NULL) {
                            EventstoUpsert1.put(e.Id, new Event(Id = ((Edizione__c) trigger.oldMap.get(e.Id)).IdEventoLeadTutor__c, OwnerId = CognomiIds.get(e.Lead_Tutor__c)));
                        }
                    }
                }
                if (e.Second_Tutor__c != ((Edizione__c) trigger.oldMap.get(e.Id)).Second_Tutor__c) {
                    if (((Edizione__c) trigger.oldMap.get(e.Id)).Second_Tutor__c == NULL){
                        Event ev = new Event();
                        ev = new Event(isAllDayEvent = TRUE, Subject = e.Name, Location=e.Sede__c, StartDateTime = (DateTime.newInstance(e.Data_inizio__c, (DateTime.newInstance(e.Data_inizio__c, Time.newInstance(0,0,0,0))).timeGMT())), EndDateTime = (DateTime.newInstance(e.Data_fine__c, (DateTime.newInstance(e.Data_fine__c, Time.newInstance(0,0,0,0))).timeGMT())), OwnerId = CognomiIds.get(e.Second_Tutor__c));
                        EventstoUpsert2.put(e.Id, ev);
                    } else if (e.Second_tutor__c == NULL) {
                        EventstoDelete.add(e.IdEventoSecondTutor__c);
                        e.IdEventoSecondTutor__c = NULL;
                    } else {
                        if (((Edizione__c) trigger.oldMap.get(e.Id)).IdEventoSecondTutor__c != NULL) {
                            EventstoUpsert2.put(e.Id, new Event(Id = ((Edizione__c) trigger.oldMap.get(e.Id)).IdEventoSecondTutor__c, OwnerId =  CognomiIds.get(e.Second_Tutor__c)));
                        }
                    }
                }
            }

            if (!EventstoUpsert1.isEmpty()) {
                upsert EventstoUpsert1.values();
                for (Id i : EventstoUpsert1.keySet()) {
                    Edizione__c ed = ((Edizione__c) trigger.newMap.get(i));
                    ed.IdEventoSecondTutor__c = EventstoUpsert1.get(i).Id;
                }
            }
            if (!EventstoUpsert2.isEmpty()) {
                upsert EventstoUpsert2.values();
                for (Id i : EventstoUpsert2.keySet()) {
                    Edizione__c ed = ((Edizione__c) trigger.newMap.get(i));
                    ed.IdEventoSecondTutor__c = EventstoUpsert2.get(i).Id;
                }
            }
            if (!EventstoDelete.isEmpty()){
                List<Event> ETDL = new List<Event>();
                for (Id i : EventstoDelete){
                    ETDL.add(new Event(Id = i));
                }
                delete ETDL;
            }

        }

    }

This class retrive an apex trigger :

trigger Trigger_Edizione on Edizione__c (before update, before insert, after update, before delete) {
if (trigger.isBefore){
        if (!trigger.isDelete){
            EdizioneHelper.CreaEventoCorrispondente();
        } else {
            EdizioneHelper.CancellaEventoCorrispondente();
        }
    } 




The test class that I have writed is :

static testMethod void TestCreaEventoCorrispondente() {
     
     Map<Integer, Event> Events1 = new Map<Integer, Event> ();
      Map<Integer, Event> Events2 = new Map<Integer, Event> ();
     List <Schema.PicklistEntry> l_picklist = new List <Schema.PicklistEntry>();
     List <Id>l_Ids= new List <Id>();
     Map<String,Id> S_Ids = new Map <String,Id> ();
       
List <Edizione__c> l_ed= new List <Edizione__c>();
     Edizione__c edizione = new Edizione__c(Data_inizio__c=date.valueof('2016-09-07'),Data_fine__c=date.valueof('2016-09-07'),motivo_stato__c='edizione confermata', Codice_piattaforma__c='edizione',Sede__c='Milano',Name='ciccio',Data_Invio_al_Sito__c=date.valueof('2016-09-15'),Lead_Tutor__c='Colonna');
        insert edizione;
     l_ed.add(edizione);
   
       
        List <Event> l_ev = new List <Event>(); 
        Event ev = new Event (Location=edizione.Sede__c,Subject=edizione.name, IsAllDayEvent=false, StartDateTime = datetime.newInstance(2014, 11, 13, 16, 30, 0), EndDateTime = datetime.newInstance(2014, 11, 13, 18, 30, 0));
         l_ev.add(ev); 
        insert ev;
        
      
         User us = new User (Username='d.pippo@bridgepartners.it.dev',LastName='Pugliese',FirstName='Domenico', Email='d.pugliese@bridgepartners.it', Alias='dpugl', CommunityNickname='d.pippo', TimeZoneSidKey='Europe/Rome', LocaleSidKey='it_IT', EmailEncodingKey='ISO-8859-1', ProfileId='00e58000000ZU0WAAW', LanguageLocaleKey='it');
        insert us;
         update us;
    
     EdizioneHelper.CreaEventoCorrispondente();
     
     update ev;
     EdizioneHelper.CreaEventoCorrispondente();
     
     delete ev;
     EdizioneHelper.CreaEventoCorrispondente();
     
     delete l_ev;
     EdizioneHelper.CreaEventoCorrispondente();
   
         
     ev.IsAllDayEvent=true;
     update ev;
     EdizioneHelper.CreaEventoCorrispondente();
     
     edizione.Second_Tutor__c='Fioretti';
     update edizione;
     EdizioneHelper.CreaEventoCorrispondente();
     
 }
   

The result of run test  is :


System.NullPointerException: Attempt to de-reference a null object, when I write in the test class
EdizioneHelper.CreaEventoCorrispondente(); 
and when I write   if (trigger.isInsert)  in the apex class


 
Hi guys,

Can anyone help me with a test class for the below trigger?

trigger defaultEntitlement on Case (Before Insert, Before Update) {
   /*
   If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement
    and select the first one.  If not then check to see if the Account on the Case has an active Entitlement.
   */
   List<Id> contactIds = new List<Id>();
   List<Id> acctIds = new List<Id>();
   for (Case c: Trigger.new){
      if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
         contactIds.add(c.ContactId);
         acctIds.add(c.AccountId);
      }
   }
   if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
      /* Added check for active entitlement */
      List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
                                                Where e.ContactId in:contactIds
                                                And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
      if(entlContacts.isEmpty()==false){
         for(Case c: Trigger.new){
            if(c.EntitlementId == null && c.ContactId!= null){
               for(EntitlementContact ec:entlContacts){
                  if(ec.ContactId==c.ContactId){
                     c.EntitlementId = ec.EntitlementId;
                     if(c.AssetId==null && ec.Entitlement.AssetId!=null)
                        c.AssetId=ec.Entitlement.AssetId;
                     break;
                  }
               } // end for
            }
         } // end for
      } else{
         List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
                                     From Entitlement e
                                     Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today];
         if(entls.isEmpty()==false){
            for(Case c: Trigger.new){
               if(c.EntitlementId == null && c.AccountId!= null){
                  for(Entitlement e:entls){
                     if(e.AccountId==c.AccountId){
                        c.EntitlementId = e.Id;
                        if(c.AssetId==null && e.AssetId!=null)
                           c.AssetId=e.AssetId;
                        break;
                     }
                  } // end for
               }
            } // end for
         }
      }
   } // end if(contactIds.isEmpty()==false)
}
  • October 26, 2016
  • Like
  • 0
Hi All,

  How can we give our own custom LastModifiedaDate  to records while inserting in test classes.

We have class which has a query

  
if (jobType == PROCESS_DEL_VIOC_FRANCHISE_RECORDS) {
            query = Database.getQueryLocator([SELECT Id FROM Lead  where RecordType.Name=:RecordTypeUtil.VIOC_Franchise_Web_lead and LastModifiedDate < LAST_N_YEARS:3]);
        }

While writing test class for this class, we are trying to create some test data. To meet above condition we have to give LastModifiedDate  which must be 3 years old. How can we write a test class in this situations.

Any help is really appreciated.

Thanks,
Naveen.
Getting visualforce page error as List has no rows for assignment to SObject.  An unexpected error has occurred. Your development organization has been notified.
Here is my page controller.

Controller-
public class MyFirstController {


    private final Account account;

    public MyFirstController () {

        account = [SELECT Id, Name, Site FROM Account

                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];

    }

 
    public Account getAccount() {

        return account;

    }

 
    public PageReference save() {

        update account;

        return null;

    }

}
 
Hi All,

I want to update the few fields of converted leads. So can you guys please help me and let me know how can update it. 

Thanks in advance

Hi All,

 

I have requirement where I have to implement Cybersource payment gateway in Salesforce.com. I am trying to use Cybersource Hosted Order Page approach to implement this functionality.

 

Cybersource has provided me some sample JSP pages which I can use in any java based web application and implement the payment gateway within that application and I am able to do that.

 

Now I have to simulate the same functionality in Salesforce.com using Visualforce and Apex. I am able to simulate most of the code in Apex but got stuck while simulating Message Authentication code and secret key. Below is the code written in java which I need to simulate in Apex.

 

 

  public String getPublicDigest(String customValues) throws Exception{
    String pub =  "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2L8taoXQvBV5xddZp58JE2i3rQauaBe1U1lEQCIYNYlIQSt4J6++F6NBgmCx1vnSCX2s4O0FI3S5b/No7QTfKkO19ofJVYBB6hdlcPStHsnYLV9mDmHuFfiR8Ebk3dUWYVCQX+eyZj99WQmYiTPIEZSAuB54jTMRQwyAE5GsVwIDAQAB";    
    BASE64Encoder encoder = new BASE64Encoder();
    Mac sha1Mac = Mac.getInstance("HmacSHA1");
    SecretKeySpec publicKeySpec = new SecretKeySpec(pub.getBytes(), "HmacSHA1");
    sha1Mac.init(publicKeySpec);
    byte[] publicBytes = sha1Mac.doFinal(customValues.getBytes());
    String publicDigest = encoder.encodeBuffer(publicBytes);
    return publicDigest.replaceAll("\n", "");
  }

Here is the code which I simulated in Apex but the key generated is still invalid.

 

 

    public String getPublicDigest(String customValues){
	String secretKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2L8taoXQvBV5xddZp58JE2i3rQauaBe1U1lEQCIYNYlIQSt4J6++F6NBgmCx1vnSCX2s4O0FI3S5b/No7QTfKkO19ofJVYBB6hdlcPStHsnYLV9mDmHuFfiR8Ebk3dUWYVCQX+eyZj99WQmYiTPIEZSAuB54jTMRQwyAE5GsVwIDAQAB';
        //Blob blobDigest = Crypto.generateDigest('hmacSHA1', Blob.valueOf(pub));
        Blob sha1Mac = Crypto.generateMac('hmacSHA1', Blob.valueOf(customValues), EncodingUtil.base64Decode(secretKey));
        String publicDigest = Encodingutil.convertToHex(sha1Mac);
        return publicDigest;
    }

 

 

Any help is appreciated.

 

 

I was told that when I signed up as a developer, I would have access to a demo database.

I was told that I would use my logon user name and password to logon to Sales Force.

 

I copied the VB code from the PDF and appears to work, but I am getting an error:

 

"Invalid username, password, security token; or user locked out."

 

I assume the User name and/or password is not the correct one to use.

 

I did use WireShark to confirm Internet traffic was occuring when trying to login.

 

Any help would be appreciated,

Ira

  • January 18, 2010
  • Like
  • 0