• Drebin
  • NEWBIE
  • 25 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 5
    Replies
HI there,

I try with a custom script to upsert a QuoteLineItem but I face a problem with the SBQQ__Quote__c field, which is a Master-Detail of the Quote object.

This is my code :
export function onBeforeCalculate(quoteModel, quoteLineModels, conn) {
  console.log('ytjtuio');
  console.log(quoteModel);
  console.log(quoteLineModels.length);
  console.log(quoteLineModels);
  
  
if(quoteLineModels.length >= 0)
{
  for( var i = 0; i < quoteLineModels.length; i++) {
   var quoteline = conn.sobject("SBQQ__QuoteLine__c").upsert({
           SBQQ__Product__c : quoteLineModels[i]._unproxiedModel.record.SBQQ__Product__c,
           SBQQ__OriginalQuoteLineId__c : quoteLineModels[i]._unproxiedModel.record.SBQQ__Quote__c,
           SBQQ__Quote__c : quoteLineModels[i]._unproxiedModel.record.SBQQ__Quote__c
           }, 'SBQQ__OriginalQuoteLineId__c',
           function(err, rets) {
  if (err) { return console.error(err); }
      console.log("Upserted Successfully");
    }
  );
  }
}
  return Promise.resolve();
}
When I do a save of the LineItems, I have this error : "INVALID_FIELD: The value provided for foreign key reference SBQQ__Quote__r is not a nested SObject". I tried with "SBQQ__Quote__c" field and I have this error : "INVALID_FIELD_FOR_INSERT_UPDATE: Unable to create/update fields: SBQQ__Quote__c. Please check the security settings of this field and verify that it is read/write for your profile or permission set."

Thanks for your help !
  • March 13, 2019
  • Like
  • 0
Hi,

I have a class that updates the PriceBookEntry of all the products in each available currency, but I have an "Apex CPU Time Limit" error when I test the code.
public class Update_Product_Price implements Schedulable {
    
    public void Update_Price()
    {
        Decimal unitPriceEuro = 0;
        list<PriceBookEntry> listProductPrice = [SELECT Product2Id, UnitPrice, CurrencyIsoCode  FROM PriceBookEntry];
        list<Currency_Rate__c> listExchangeCurrency = [SELECT CHF__c, CNY__c, CZK__c, DKK__c, GBP__c, NOK__c, PLN__c, RUB__c, SEK__c, USD__c, ZAR__c  FROM Currency_Rate__c];
        
        PriceBookEntry pbe = new PriceBookEntry();
        Map<Id, PriceBookEntry> listOfPriceBookEntry = new Map<Id, PriceBookEntry>();
        
        for (PriceBookEntry StandardPrice : listProductPrice) {   
            
            unitPriceEuro = -1;
            if(StandardPrice.CurrencyIsoCode == 'EUR')
            {
                unitPriceEuro = StandardPrice.UnitPrice;
                System.debug('Currency code : ' +  StandardPrice.CurrencyIsoCode + ' Unit price : ' + StandardPrice.UnitPrice);
                System.debug(unitPriceEuro);                      
                
                for (PriceBookEntry StandardPrice_2 : listProductPrice) {
                    if(StandardPrice_2.CurrencyIsoCode == 'CHF' && unitPriceEuro != -1 || unitPriceEuro == null)
                    {     
                        StandardPrice_2.UnitPrice = unitPriceEuro * listExchangeCurrency[0].CHF__c;
                    }
                    if(StandardPrice_2.CurrencyIsoCode == 'CNY' && unitPriceEuro != -1)
                    {            
                        StandardPrice_2.UnitPrice = unitPriceEuro * listExchangeCurrency[0].CNY__c;
                    }
                    if(StandardPrice_2.CurrencyIsoCode == 'CZK' && unitPriceEuro != -1)
                    {            
                        StandardPrice_2.UnitPrice = unitPriceEuro * listExchangeCurrency[0].CZK__c;
                    }
                    if(StandardPrice_2.CurrencyIsoCode == 'DKK' && unitPriceEuro != -1)
                    {            
                        StandardPrice_2.UnitPrice = unitPriceEuro * listExchangeCurrency[0].DKK__c;
                    }
                    if(StandardPrice_2.CurrencyIsoCode == 'GBP' && unitPriceEuro != -1)
                    {            
                        StandardPrice_2.UnitPrice = unitPriceEuro * listExchangeCurrency[0].GBP__c;
                    }
                    if(StandardPrice_2.CurrencyIsoCode == 'NOK' && unitPriceEuro != -1)
                    {            
                        StandardPrice_2.UnitPrice = unitPriceEuro * listExchangeCurrency[0].NOK__c;
                    }
                    if(StandardPrice_2.CurrencyIsoCode == 'PLN' && unitPriceEuro != -1)
                    {            
                        StandardPrice_2.UnitPrice = unitPriceEuro * listExchangeCurrency[0].PLN__c;
                    }
                    if(StandardPrice_2.CurrencyIsoCode == 'RUB' && unitPriceEuro != -1)
                    {            
                        StandardPrice_2.UnitPrice = unitPriceEuro * listExchangeCurrency[0].RUB__c;
                    }
                    if(StandardPrice_2.CurrencyIsoCode == 'SEK' && unitPriceEuro != -1)
                    {            
                        StandardPrice_2.UnitPrice = unitPriceEuro * listExchangeCurrency[0].SEK__c;
                    }
                    if(StandardPrice_2.CurrencyIsoCode == 'USD' && unitPriceEuro != -1)
                    {            
                        StandardPrice_2.UnitPrice = unitPriceEuro * listExchangeCurrency[0].USD__c;
                    }
                    if(StandardPrice_2.CurrencyIsoCode == 'ZAR' && unitPriceEuro != -1)
                    {            
                        StandardPrice_2.UnitPrice = unitPriceEuro * listExchangeCurrency[0].ZAR__c;
                    }
                    pbe = StandardPrice_2;
                    listOfPriceBookEntry.put(pbe.Id, pbe);
                }
            }        
        }
        update listOfPriceBookEntry.values();
    }
    
    public void execute (SchedulableContext sc) {
        Update_Price();
    }
    
    
}

Can someone help me on this, I totally stuck right now.
Thanks
  • April 16, 2018
  • Like
  • 0
Hi,

I need to create a visualforce page to allow some users without admin rights to add values to a picklist.
I have this VF code :
<apex:page controller="dynamicpicklist" sidebar="false" >
    <apex:form >
        <apex:sectionHeader title="Dynamic Picklist" subtitle="Reusable code"/>
        <apex:pageblock >
            <apex:pageBlockSection title="Dynamic picklist" columns="1">
                <apex:pageblocksectionItem >
                    <apex:outputlabel value="Picklist" for="values" />
                    <apex:selectList value="{!test}" size="1" id="values">
                        <apex:actionSupport event="onchange" reRender="newvalue" />
                        <apex:selectOptions value="{!picklistnames}"/>
                    </apex:selectList>
                </apex:pageblocksectionItem>                                        
                <apex:outputpanel id="newvalue">
                        <div style="position:relative;left:75px;">             
                            <apex:outputlabel value="New value" for="newval" />
                            <apex:inputText value="{!newval}" id="newval"/>
                            <apex:commandbutton action="{!saverec}" value="Add!"/>
                        </div>
                </apex:outputpanel>             
            </apex:pageblocksection>
        </apex:pageblock>
    </apex:form>
</apex:page>

And this APEX code :
public class dynamicpicklist
{
    public List<SelectOption> statusOptions { get;set; }
    public String test{get; set;}
    
    public List<SelectOption> getpicklistnames()
    {
        Schema.DescribeFieldResult statusFieldDescription = Case.Test__c.getDescribe();
        statusOptions = new list<SelectOption>();
        
        for (Schema.Picklistentry picklistEntry : statusFieldDescription.getPicklistValues())
        {
            statusOptions.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel(), false));
        }
        return statusOptions;
    }
    
    public String newval{get; set;}
    
    public void saverec()
    {
        Case newrec = new Case(Test__c=newval);
        insert newrec;
        newval=NULL;
    }
}

The value is added in the picklist but it is inactive. Can you help me to set the new value active by default ?
Thanks for the help.
 
  • September 26, 2017
  • Like
  • 0
Hi everyone,

I have this apex class for insert a new lead :
public class LeadClass
{
    public ContentVersion cont {get;set;}
    public String theValue {get;set;}
    public String company {get;set;}
    public String plate {get;set;}
    
    public LeadClass() {
        cont = new ContentVersion();
    }
    
    public PageReference NewLead(){
        List<User> updatedUsers = new List<User>();
        Decimal score = 0;
        List<User> myUsers = [SELECT Id, PhotoLead_Points__c
                              FROM User
                              WHERE Id=:userinfo.getuserId()];
        
        for (User myUser: myUsers) {
            myUser.PhotoLead_Points__c += 50;
            score = myUser.PhotoLead_Points__c;
            updatedUsers.add(myUser);
        }
        update updatedUsers;
        
        DateTime dt = DateTime.now();
        String formattedDt = dt.format('MM-dd-yyyy  hh:mm:ss');
        cont.PathOnClient = 'file' + Datetime.now() + '.jpg';
        cont.title = 'On the road ' + formattedDt;
        cont.Origin = 'H';
        upsert cont;
        
        Lead l = new Lead(PhotoLead_Image__c=cont.id, Company=company, Status='Open',LastName='On the road ' + formattedDt, Photo_location__c=theValue, Licence_plate__c=plate);
        insert l;
        
        PageReference pr = new PageReference('/'+l.id);
        return pr;
    }
    
    public PageReference doCancel()
    {
        return new PageReference('/00Q/o');
    }
    
    public PageReference game()
    {
        return new PageReference('/apex/Gamification');
    }
}
I tried to make a test class for this but i am still with a 0% code coverage :
@isTest 
public class LeadClassTest
{
    static testMethod void testMethod1() 
    {
        Lead newLead = new Lead() ;
        newLead.LastName = 'Swain';
        newLead.Company = 'BlueWave';
        newLead.Status = 'contacted';
        newLead.Photo_location__c = 'France';
        newLead.Licence_plate__c = 'GG-258-HH';
        insert newLead;
        
        User userToCreate = new User();
        
        // Do you recognize these fields?
        userToCreate.FirstName = 'Titi';
        userToCreate.LastName = 'Toto';
        userToCreate.Email = 'bdgdf@gmail.com';
        userToCreate.Username = 'fgnfy@gmail.com';
        userToCreate.Alias = 'huhu';
        userToCreate.ProfileId = '01er0010000iTqy';
        userToCreate.PhotoLead_Points__c = 50;
        insert userToCreate;
        
        userToCreate =[select IsActive from User  limit 1];
        userToCreate.IsActive = false;
        userToCreate.PhotoLead_Points__c = 100;
        update userToCreate;
        
    }
}
Any help would be appreaciated.
Thanks !
  • January 31, 2017
  • Like
  • 0
Hi everyone,

I have this trigger to delete a document when a lead is deleted :
trigger DeleteImageLead on Lead (before delete) {

    if (Trigger.isDelete) {
        for (Lead l : Trigger.old)
        {
            List<ContentDocument> myFeed = [SELECT LatestPublishedVersionId FROM ContentDocument WHERE Id In (SELECT ContentDocumentId FROM ContentVersion WHERE Id =:l.PhotoLead_Image__c)];
            delete myFeed;
        }
    }
}
When I deploy it on a production environment, I have a code coverage error because it is 0%.
Can you please help me with to make an apex test class for this code ? I tried to develop it but I'm still with 0% code coverage

Thanks a lot !

Frédéric
 
  • January 27, 2017
  • Like
  • 0
Hi everyone,

I realized an app which take photos and create leads with it. I save the image in a ContentVersion. To show it in my new lead, i created two custom fields, one which store the ContentVersion ID of the image and another one with the formula to display the image in the lead detail with the following formula : IMAGE('/sfc/servlet.shepherd/version/download/' & PhotoLead_Image__c, "Chatter Image", 250, 250).

Now, i need that when the status of a lead changes to "Converted", the image corresponding to this lead is deleted.

I tried to create a trigger for this but I'm completely blocked.

Can you help please me with this trigger ?

Thanks.
  • November 17, 2016
  • Like
  • 0
Hi everyone,

I have this apex class for insert a new lead :
public class LeadClass
{
    public ContentVersion cont {get;set;}
    public String theValue {get;set;}
    public String company {get;set;}
    public String plate {get;set;}
    
    public LeadClass() {
        cont = new ContentVersion();
    }
    
    public PageReference NewLead(){
        List<User> updatedUsers = new List<User>();
        Decimal score = 0;
        List<User> myUsers = [SELECT Id, PhotoLead_Points__c
                              FROM User
                              WHERE Id=:userinfo.getuserId()];
        
        for (User myUser: myUsers) {
            myUser.PhotoLead_Points__c += 50;
            score = myUser.PhotoLead_Points__c;
            updatedUsers.add(myUser);
        }
        update updatedUsers;
        
        DateTime dt = DateTime.now();
        String formattedDt = dt.format('MM-dd-yyyy  hh:mm:ss');
        cont.PathOnClient = 'file' + Datetime.now() + '.jpg';
        cont.title = 'On the road ' + formattedDt;
        cont.Origin = 'H';
        upsert cont;
        
        Lead l = new Lead(PhotoLead_Image__c=cont.id, Company=company, Status='Open',LastName='On the road ' + formattedDt, Photo_location__c=theValue, Licence_plate__c=plate);
        insert l;
        
        PageReference pr = new PageReference('/'+l.id);
        return pr;
    }
    
    public PageReference doCancel()
    {
        return new PageReference('/00Q/o');
    }
    
    public PageReference game()
    {
        return new PageReference('/apex/Gamification');
    }
}
I tried to make a test class for this but i am still with a 0% code coverage :
@isTest 
public class LeadClassTest
{
    static testMethod void testMethod1() 
    {
        Lead newLead = new Lead() ;
        newLead.LastName = 'Swain';
        newLead.Company = 'BlueWave';
        newLead.Status = 'contacted';
        newLead.Photo_location__c = 'France';
        newLead.Licence_plate__c = 'GG-258-HH';
        insert newLead;
        
        User userToCreate = new User();
        
        // Do you recognize these fields?
        userToCreate.FirstName = 'Titi';
        userToCreate.LastName = 'Toto';
        userToCreate.Email = 'bdgdf@gmail.com';
        userToCreate.Username = 'fgnfy@gmail.com';
        userToCreate.Alias = 'huhu';
        userToCreate.ProfileId = '01er0010000iTqy';
        userToCreate.PhotoLead_Points__c = 50;
        insert userToCreate;
        
        userToCreate =[select IsActive from User  limit 1];
        userToCreate.IsActive = false;
        userToCreate.PhotoLead_Points__c = 100;
        update userToCreate;
        
    }
}
Any help would be appreaciated.
Thanks !
  • January 31, 2017
  • Like
  • 0
Hi everyone,

I have this trigger to delete a document when a lead is deleted :
trigger DeleteImageLead on Lead (before delete) {

    if (Trigger.isDelete) {
        for (Lead l : Trigger.old)
        {
            List<ContentDocument> myFeed = [SELECT LatestPublishedVersionId FROM ContentDocument WHERE Id In (SELECT ContentDocumentId FROM ContentVersion WHERE Id =:l.PhotoLead_Image__c)];
            delete myFeed;
        }
    }
}
When I deploy it on a production environment, I have a code coverage error because it is 0%.
Can you please help me with to make an apex test class for this code ? I tried to develop it but I'm still with 0% code coverage

Thanks a lot !

Frédéric
 
  • January 27, 2017
  • Like
  • 0
Hi everyone,

I realized an app which take photos and create leads with it. I save the image in a ContentVersion. To show it in my new lead, i created two custom fields, one which store the ContentVersion ID of the image and another one with the formula to display the image in the lead detail with the following formula : IMAGE('/sfc/servlet.shepherd/version/download/' & PhotoLead_Image__c, "Chatter Image", 250, 250).

Now, i need that when the status of a lead changes to "Converted", the image corresponding to this lead is deleted.

I tried to create a trigger for this but I'm completely blocked.

Can you help please me with this trigger ?

Thanks.
  • November 17, 2016
  • Like
  • 0