• David Holland
  • NEWBIE
  • 0 Points
  • Member since 2012

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

Hi everyone. I have a JS/JQuery function, which also calls a remote action from a controller.

 

I have written it so that it completes the remote action first, as the results from this is needed later on. However, it is firing the loop before computing the remote action, meaning I am not populating the fields I need to.

 

Below is the code:

 

function UpdateTotals(){

var EntityId = 'a1Mc00000001aaw';
var CurrentReg = 0;
var ProjReg = 0;

Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.VWPCareTradeExtension.getFeesList}',
EntityId,
function(result, event){
if (event.status) {
CurrentReg = result.Current_Registration__c;
ProjReg = result.Projected_Registration__c;
alert('First:' + CurrentReg);

} else if (event.type === 'exception') {
alert('There is No Fee Record for that Entity.');
} else {
alert('Something Has Gone Wrong, please check all details and try again.');
}
},
{escape: true}
);


for (var i=1;i<6;i++){

alert (i+CurrentReg);
var Type = j$("select[id$=Type"+i+"]").val();

//if (Type=='CTA' || Type='FMT'){

j$("input[id$=Registration"+i+"]").val(CurrentReg);
//}


// Passes all values to function, which resolves to numbers, or null (so we do not get any NaN errors).
var abdir = getFieldValue("ABDir"+i);
var abdep = getFieldValue("ABDepreciation"+i);
var abman = getFieldValue("ABManage"+i);
var abban = getFieldValue("ABBank"+i);
var abexc = getFieldValue("Excessive"+i);
var dir = getFieldValue("NDir"+i);
var dep = getFieldValue("NDepreciation"+i);
var man = getFieldValue("NManage"+i);
var ban = getFieldValue("NBank"+i);
var equ = getFieldValue("NEquipment"+i);
var othPerson = getFieldValue("OtherPerson"+i);
var feeInc = getFieldValue("FeeInc"+i);
var otherInc = getFieldValue("OtherInc"+i);
var wage = getFieldValue("Wages"+i);
var otherwage = getFieldValue("OtherWages"+i);
var rate = getFieldValue("Rates"+i);
var refuse = getFieldValue("Refuse"+i);
var heat = getFieldValue("Heat"+i);
var water = getFieldValue("Water"+i);
var repair = getFieldValue("Repair"+i);
var insure = getFieldValue("Insure"+i);
var rent = getFieldValue("Rent"+i);
var otherProp = getFieldValue("PropOther"+i);
var food = getFieldValue("Food"+i);
var laundry = getFieldValue("Laundry"+i);
var car = getFieldValue("Car"+i);
var account = getFieldValue("Account"+i);
var uniform = getFieldValue("Uniform"+i);
var medical = getFieldValue("Medical"+i);
var welfare = getFieldValue("Welfare"+i);
var stationary = getFieldValue("Stationary"+i);
var regFees = getFieldValue("RegFees"+i);
var market = getFieldValue("Market"+i);
var sundries = getFieldValue("Sundries"+i);
var otherOper = getFieldValue("OtherOper"+i);
var reg = getFieldValue("Registration"+i);
var averageFill = getFieldValue("AverageFill"+i);

//Subtotals

var propTotal = rate+refuse+heat+water+repair+insure+otherProp;
var operTotal = food+laundry+car+account+uniform+medical+welfare+stationary+regFees+market+sundries+otherOper;
var personTotal = dir+dep+man+ban+equ+othPerson;
var totalWages = wage+otherwage;
var totalInc = feeInc+otherInc;
var abTotal = abdir+abdep+abman+abban+abexc;
var ebitda = totalInc-totalWages-propTotal-operTotal-personTotal;
var totalOther = propTotal+operTotal+personTotal;
var totalTotal = totalOther+totalWages;

j$("input[id$=TotalInc"+i+"]").val(totalInc);
j$("input[id$=TotalWages"+i+"]").val(totalWages );
j$("input[id$=PropTotal"+i+"]").val(propTotal);
j$("input[id$=OperTotal"+i+"]").val(operTotal);
j$("input[id$=PersonTotal"+i+"]").val(personTotal);
j$("input[id$=ABTotal"+i+"]").val(abTotal);
j$("input[id$=TotalOther"+i+"]").val(totalOther);
j$("input[id$=TotalTotal"+i+"]").val(totalTotal);
j$("input[id$=EBITDA"+i+"]").val(ebitda);
j$("input[id$=EBITDAR"+i+"]").val(ebitda+rent);
j$("input[id$=EBITDAAdj"+i+"]").val(abTotal+ebitda);
j$("input[id$=EBITDAPB"+i+"]").val(reg!=0?((abTotal+ebitda)/reg).toFixed(2):0);
j$("input[id$=Expenses"+i+"]").val(totalTotal);
j$("input[id$=ExpensesPRPW"+i+"]").val(averageFill!=0?(((totalTotal)/averageFill)/52).toFixed(2):0);
j$("input[id$=NPC"+i+"]").val(totalOther);
j$("input[id$=NPCPRPW"+i+"]").val(averageFill!=0?(((totalOther)/averageFill)/52).toFixed(2):0);

}
}
function getFieldValue(fieldName){

if (!isNaN(parseInt(j$("input[id$="+fieldName+"]").val(),10))){
return (parseInt(j$("input[id$="+fieldName+"]").val(),10));
}
else {
return 0;
}
}

 

The alerts(i+reg) is firing before the alert('First:'+reg), meaning I am not populating the data.

I discovered earlier how to translate all the "Section Headings" on a standard page layout.

 

I now wonder whether there is any way to reference these in a visualforce Page without having to create a custom label:

 

For example, for fields we can use this notation:

 

{!$ObjectType.My_Object__c.Fields.Name.Label}.

 

Is there a similar way to reference the section headings?!

 

Thanks

I am looking into Translation workbench and see how you translate fields, workflows etc.

 

However, is there a way to translate the section headers on a standard page layout as I don't see this option?

 

Many thanks

 

David 

I have overwritten the Contact Overview page with a visualforce page. There are buttons next to the phone numbers which allow users to call people using a 'Click to Call' function (HTTP callout to an external site).

 

This was all working fine until this morning, where I have come in and discovered this error:

 

"sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"

 

I wondered if there was any way in my HTTP callout in my Apex coding to just ignore certificates and do the callout without this check?

 

Any help would be greatly appreciated.

Hi all.

 

Below is a snippet from my page.

 

<apex:pageBlockSection title="Freehold Inspection Information" id="Freehold" rendered="{!pageCount=5}">
<apex:pageBlockSectionItem >
<apex:outputText > Inspected As Freehold </apex:outputText>
<apex:actionRegion >
<apex:inputField value="{!Transaction__c.Inspected_As_Freehold__c}">
<apex:actionSupport reRender="FHExpecSection" event="onchange"/>
</apex:inputField>
</apex:actionRegion>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection id="FHExpecSection" rendered="{!pageCount=5 && Transaction__c.Inspected_As_Freehold__c=True}">
<apex:inputField value="{!Transaction__c.Inspection_FH_C_C_Expected_Realisation__c}" required="{!Transaction__c.Inspected_As_Freehold__c=True}" />
<apex:inputField value="{!Transaction__c.Inspection_FH_Vendor_Expectation__c}" required="{!Transaction__c.Inspected_As_Freehold__c=True}" />
<apex:inputField value="{!Transaction__c.Inspection_FH_C_C_Asking_Price__c}" required="{!Transaction__c.Inspected_As_Freehold__c=True}" />
</apex:pageBlockSection>

 

The problem is, that FHExpecSection is not rerendering when the checkbox is ticked. I have no idea why, when the exact same formula works if I attach it to each seperate input field. 

 

Anyone have any ideas why this is not working?!

Hi everyone.

 

I am creating a VF Page and displaying number merge fields.

 

<apex:pageBlockSectionItem >
<apex:outputText styleClass="dataInput" value="{0, number, ###,###,###}">
<apex:param value="{!Performance_Projection__c.L_Cap_Inv_Am_A__c}"/>
</apex:outputText>
</apex:pageBlockSectionItem>

 

I am trying to do:

 

 {!Performance_Projection__c.L_Cap_Inv_Am_P__c==0?10:5}

 

But am receiving 'Error: Syntax error'

 

I am sure it is a simple syntax error and I just can't see how I am going wrong

Hi everyone.

I have created a new 'Geolocation' field on a custom object and am trying to get a trigger to fire which will populate the latitude and longitude via a callout to Google Maps.

I have added Google Maps to the remote site settings. This is in a Sandbox environment.

CLASS:

public class LocationCallouts {
 
     @future (callout=true)  // future method needed to run callouts from Triggers
      static public void getLocation(id Id){
        // gather account info
        Transaction__c t = [SELECT Street__c, City__c, County__c, Country__c, Postcode__c FROM Transaction__c WHERE id =: Id];
 
        // create an address string
        String address = '';
        if (t.Street__c!= null)
            address += t.Street__c+', ';
        if (t.City__c!= null)
            address += t.City__c+', ';
        if (t.County__c!= null)
            address += t.County__c+', ';
        if (t.Postcode__c != null)
            address += t.Postcode__c +', ';
        if (t.Country__c!= null)
            address += t.Country__c;
 
        address = EncodingUtil.urlEncode(address, 'UTF-8');
 
        // build callout
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setMethod('GET');
        req.setTimeout(60000);
 
        try{
            // callout
            HttpResponse res = h.send(req);
 
            // parse coordinates from response
            JSONParser parser = JSON.createParser(res.getBody());
            double lat = null;
            double lon = null;
            while (parser.nextToken() != null) {
                if (parser.getText() == 'coordinates'){
                       parser.nextToken(); // object start
                           String txt = parser.getText();
                           parser.nextToken();
                           if (txt == 'lat')
                               lat = parser.getDoubleValue();
                           else if (txt == 'lng')
                               lon = parser.getDoubleValue();
                }
            }
 
            // update coordinates if we get back
            if (lat!= null){
                t.Location__Latitude__s = lat;
                t.Location__Longitude__s = lon;
                update t;
            }
 
        } catch (Exception e) {
        }
    }
}

TRIGGER:


// Trigger runs getLocation() on Transaction
trigger SetGeolocation on Transaction__c (after insert, after update) {
    for (Transaction__c t : trigger.new){
        if (t.Location__Latitude__s == null){
            LocationCallouts.getLocation(t.id);
        }
    }
}

I am sure I have just done something stupid but cannot see what I have done wrong!!

Any help would be greatly appreciated.

I am looking into Translation workbench and see how you translate fields, workflows etc.

 

However, is there a way to translate the section headers on a standard page layout as I don't see this option?

 

Many thanks

 

David 

I would like to have a conditional section for a Contact based upon a custom attribute that I have added.

 

Is it possible to hide / show a section that I have added to the Contact page using the attribute value

 

Thanks in advance.

 

Whatty

Hi everyone.

I have created a new 'Geolocation' field on a custom object and am trying to get a trigger to fire which will populate the latitude and longitude via a callout to Google Maps.

I have added Google Maps to the remote site settings. This is in a Sandbox environment.

CLASS:

public class LocationCallouts {
 
     @future (callout=true)  // future method needed to run callouts from Triggers
      static public void getLocation(id Id){
        // gather account info
        Transaction__c t = [SELECT Street__c, City__c, County__c, Country__c, Postcode__c FROM Transaction__c WHERE id =: Id];
 
        // create an address string
        String address = '';
        if (t.Street__c!= null)
            address += t.Street__c+', ';
        if (t.City__c!= null)
            address += t.City__c+', ';
        if (t.County__c!= null)
            address += t.County__c+', ';
        if (t.Postcode__c != null)
            address += t.Postcode__c +', ';
        if (t.Country__c!= null)
            address += t.Country__c;
 
        address = EncodingUtil.urlEncode(address, 'UTF-8');
 
        // build callout
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setMethod('GET');
        req.setTimeout(60000);
 
        try{
            // callout
            HttpResponse res = h.send(req);
 
            // parse coordinates from response
            JSONParser parser = JSON.createParser(res.getBody());
            double lat = null;
            double lon = null;
            while (parser.nextToken() != null) {
                if (parser.getText() == 'coordinates'){
                       parser.nextToken(); // object start
                           String txt = parser.getText();
                           parser.nextToken();
                           if (txt == 'lat')
                               lat = parser.getDoubleValue();
                           else if (txt == 'lng')
                               lon = parser.getDoubleValue();
                }
            }
 
            // update coordinates if we get back
            if (lat!= null){
                t.Location__Latitude__s = lat;
                t.Location__Longitude__s = lon;
                update t;
            }
 
        } catch (Exception e) {
        }
    }
}

TRIGGER:


// Trigger runs getLocation() on Transaction
trigger SetGeolocation on Transaction__c (after insert, after update) {
    for (Transaction__c t : trigger.new){
        if (t.Location__Latitude__s == null){
            LocationCallouts.getLocation(t.id);
        }
    }
}

I am sure I have just done something stupid but cannot see what I have done wrong!!

Any help would be greatly appreciated.