• annoyingmouse
  • NEWBIE
  • 90 Points
  • Member since 2012

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

Hi All,

 

This is something of an issue for me at the minute as it's making me pull my hair out.

 

I want all new Contacts to default to a "Public" Account and I've written this trigger:

 

trigger PopulateAccountNameForNewContact on Contact (before insert, before update){
    system.debug(' ************ WORKING HERE ************ ');
    for (Contact contact: Trigger.new){
        try{
            for (Account a :[select id, Name from account where Name = 'Public' LIMIT 1]){
                if (contact.Account == null){
                    contact.Account = a;    
                    system.debug('DEBUG: Update Contact setting Account to ' + a);
                }else{
                    system.debug('DEBUG: The contact is not null - nothing to do');
                }
            }          
        }catch (DMLException e){
            system.debug('contact execution failed: '+ e);
        }    
    }
}

 

It's not working though... any ideas what I'm doing wrong?

 

Cheers in advance,

 

Dom

Hi All,

 

I'm trying to retrieve jpeg attachments from a Custom object and I can query for them ("SELECT Id, Name, Body from Attachment WHERE ParentId='"+Id+"'") but I'm getting lost trying to add them to my hybrid application.

 

I end up with this response:

 

{
    "totalSize": 1,
    "done": true,
    "records": [
        {
            "attributes": {
                "type": "Attachment",
                "url": "/services/data/v23.0/sobjects/Attachment/00PD000000Bvp9dMAB"
            },
            "Id": "00PD000000Bvp9dMAB",
            "Name": "building-foundation-2.jpg",
            "Body": "/services/data/v23.0/sobjects/Attachment/00PD000000Bvp9dMAB/Body"
        }
    ]
}

 

But I don't know what to do with it, any ideas?

 

I'm also trying to add further images from the Android Camera but I'm having no joy trying to figure out how to add attachments - any help appreciated.

 

Cheers,

 

Dom

HI there,

 

I've a custom object with a number of custom fields and a requirement to make one of those fields a read only field that equals the name of the user who created the record.

 

I first tried a Formula with CreatedById.Name but that's not accepted.

 

I've also tried to create a trigger on a text field but that caused all sorts of errors and exceptions:

 

trigger updateOfficer on Application__c (before insert) {

  for(Application__c a: Trigger.new){

    a.Officer__c = a.CreatedBy.Name;

  }

}

 

I'm hoping it's possible to use a Formula but if that's not going to work then I'll happily use a trigger but might need to some pointers... ;-)

 

Cheers,

 

Dom

Hi all,

 

goodness, I'm really hitting these boards at the minute!

 

I've a custom Address object and I need to prevent duplications. I've created a formula field which concatenates everything so I need a trigger to check that the result of the formula field is unique before I insert or update.

 

So far I've got this:

 

 

trigger uniqueAddress on Address__c (before insert, before update) {
    List<Address__c> c = [select OneLineAddress__c from Address__c where OneLineAddress__c = ];
    If(c.size() > 0){
        "Address already exists within the Application!";
    }
}

 

I'm stuck for what to put after the "OneLineAddress__c ="

 

Any ideas out there? I'm sure it's something really simple but I've got no idea about how to access the object calling the trigger...

 

Cheers,

 

Dom

Hi there,

 

I've a custom address object that I presently save with the auto-number thingy. I use it in a junction object to a custom person object but when I try to create a new junction between a person and an address I want to be able to either search on something like postcode or view objects in regards to a single line field taht my address object contains.

 

I try to do a search on address but I guess that the functionality doesn't work (though I see suggestions that it should be implemented).

 

So I'm trying to create a Workflow Rule that will update the name of the object to a single line address field that I create using a formula when the address is saved. I think that I'm doing this wrong though - can anyone point me to the resources so taht I can figure this out for myself please?

 

Cheers,

 

Dom

Don't call me Shirley!

 

So I'm working through some example AJAX stuff that I've found in the documentation and I'm trying to apply it to a custom object I've made:

 

<apex:page controller="MyController" tabStyle="Person__c">
    <apex:pageBlock title="Hello {!$User.FirstName}!">
        You are displaying People from the app.
        Click a person's name to view his or her details.
    </apex:pageBlock>
    <apex:pageBlock title="People">
        <apex:form >
            <apex:dataTable value="{!people}" var="aPerson" width="100%">
                <apex:column >
                    <apex:facet name="header">
                        <b>Name</b>
                    </apex:facet>
                    <apex:commandLink action="{!invokeService}" value="{!aPerson.FullName__c}" rerender="resultPanel">
                        <apex:param name="id" value="{!aPerson.id}"/>
                    </apex:commandLink>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <b>Number</b>
                    </apex:facet>{!aPerson.PrimaryContactNo__c}
                </apex:column>
            </apex:dataTable>  
        </apex:form>
    </apex:pageBlock>
    <apex:outputPanel id="detail">
        <apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false" title="false"/>
    </apex:outputPanel>
</apex:page>

 

With MyController looking like this:

 

public class MyController {
    public PageReference invokeService() {
        Id id = System.currentPageReference().getParameters().get('id');
        //result = [SELECT Name FROM Person__c WHERE Id=:id].Name;
        result = [SELECT DateOfBirth__c FROM Person__c WHERE Id=:id];
        return null;
    }
    public List<Person__c> getPeople() {
        return [SELECT Id, FullName__c, PrimaryContactNo__c FROM Person__c
            ORDER BY LastModifiedDate DESC LIMIT 10];
    }
}

Thing is, I keep getting this error:

 

Error: MyController Compile Error: Variable does not exist: result at line 5 column 9

 

I've tried adding ".DateOfBirth__c" to the end of the braced SOQL to no avail as the original code had ".Name" at the end...

 

Any idea as to what I'm missing?

 

Cheers,

 

Dom

Hi there,

I've a junction object between two custom objects (Person and Address, the junction object is called Person Address). Thus I've a many-to-many object.

I've got the Person page layout to display the list of Addresses associated with the Person, I'm not so bothered about the Address page displaying Persons!

I can associate a Person with an Address only when the Address has already been created. Is it possible to create a new Address whilst still on the Person page?

I'm thinking it is though it might require a custom VisualForce page, not an issue but a pointer in the right direction would be very helpful. I've been scouring Google for ages but my Google-foo must be lacking as I'm not able to see anything quite like what I need :-(.

Thanks in advance

Dom

Hi All,

 

This is something of an issue for me at the minute as it's making me pull my hair out.

 

I want all new Contacts to default to a "Public" Account and I've written this trigger:

 

trigger PopulateAccountNameForNewContact on Contact (before insert, before update){
    system.debug(' ************ WORKING HERE ************ ');
    for (Contact contact: Trigger.new){
        try{
            for (Account a :[select id, Name from account where Name = 'Public' LIMIT 1]){
                if (contact.Account == null){
                    contact.Account = a;    
                    system.debug('DEBUG: Update Contact setting Account to ' + a);
                }else{
                    system.debug('DEBUG: The contact is not null - nothing to do');
                }
            }          
        }catch (DMLException e){
            system.debug('contact execution failed: '+ e);
        }    
    }
}

 

It's not working though... any ideas what I'm doing wrong?

 

Cheers in advance,

 

Dom

Hi All,

 

I'm trying to retrieve jpeg attachments from a Custom object and I can query for them ("SELECT Id, Name, Body from Attachment WHERE ParentId='"+Id+"'") but I'm getting lost trying to add them to my hybrid application.

 

I end up with this response:

 

{
    "totalSize": 1,
    "done": true,
    "records": [
        {
            "attributes": {
                "type": "Attachment",
                "url": "/services/data/v23.0/sobjects/Attachment/00PD000000Bvp9dMAB"
            },
            "Id": "00PD000000Bvp9dMAB",
            "Name": "building-foundation-2.jpg",
            "Body": "/services/data/v23.0/sobjects/Attachment/00PD000000Bvp9dMAB/Body"
        }
    ]
}

 

But I don't know what to do with it, any ideas?

 

I'm also trying to add further images from the Android Camera but I'm having no joy trying to figure out how to add attachments - any help appreciated.

 

Cheers,

 

Dom

HI there,

 

I've a custom object with a number of custom fields and a requirement to make one of those fields a read only field that equals the name of the user who created the record.

 

I first tried a Formula with CreatedById.Name but that's not accepted.

 

I've also tried to create a trigger on a text field but that caused all sorts of errors and exceptions:

 

trigger updateOfficer on Application__c (before insert) {

  for(Application__c a: Trigger.new){

    a.Officer__c = a.CreatedBy.Name;

  }

}

 

I'm hoping it's possible to use a Formula but if that's not going to work then I'll happily use a trigger but might need to some pointers... ;-)

 

Cheers,

 

Dom

Hi all,

 

goodness, I'm really hitting these boards at the minute!

 

I've a custom Address object and I need to prevent duplications. I've created a formula field which concatenates everything so I need a trigger to check that the result of the formula field is unique before I insert or update.

 

So far I've got this:

 

 

trigger uniqueAddress on Address__c (before insert, before update) {
    List<Address__c> c = [select OneLineAddress__c from Address__c where OneLineAddress__c = ];
    If(c.size() > 0){
        "Address already exists within the Application!";
    }
}

 

I'm stuck for what to put after the "OneLineAddress__c ="

 

Any ideas out there? I'm sure it's something really simple but I've got no idea about how to access the object calling the trigger...

 

Cheers,

 

Dom

Hi there,

 

I've a custom address object that I presently save with the auto-number thingy. I use it in a junction object to a custom person object but when I try to create a new junction between a person and an address I want to be able to either search on something like postcode or view objects in regards to a single line field taht my address object contains.

 

I try to do a search on address but I guess that the functionality doesn't work (though I see suggestions that it should be implemented).

 

So I'm trying to create a Workflow Rule that will update the name of the object to a single line address field that I create using a formula when the address is saved. I think that I'm doing this wrong though - can anyone point me to the resources so taht I can figure this out for myself please?

 

Cheers,

 

Dom

Don't call me Shirley!

 

So I'm working through some example AJAX stuff that I've found in the documentation and I'm trying to apply it to a custom object I've made:

 

<apex:page controller="MyController" tabStyle="Person__c">
    <apex:pageBlock title="Hello {!$User.FirstName}!">
        You are displaying People from the app.
        Click a person's name to view his or her details.
    </apex:pageBlock>
    <apex:pageBlock title="People">
        <apex:form >
            <apex:dataTable value="{!people}" var="aPerson" width="100%">
                <apex:column >
                    <apex:facet name="header">
                        <b>Name</b>
                    </apex:facet>
                    <apex:commandLink action="{!invokeService}" value="{!aPerson.FullName__c}" rerender="resultPanel">
                        <apex:param name="id" value="{!aPerson.id}"/>
                    </apex:commandLink>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <b>Number</b>
                    </apex:facet>{!aPerson.PrimaryContactNo__c}
                </apex:column>
            </apex:dataTable>  
        </apex:form>
    </apex:pageBlock>
    <apex:outputPanel id="detail">
        <apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false" title="false"/>
    </apex:outputPanel>
</apex:page>

 

With MyController looking like this:

 

public class MyController {
    public PageReference invokeService() {
        Id id = System.currentPageReference().getParameters().get('id');
        //result = [SELECT Name FROM Person__c WHERE Id=:id].Name;
        result = [SELECT DateOfBirth__c FROM Person__c WHERE Id=:id];
        return null;
    }
    public List<Person__c> getPeople() {
        return [SELECT Id, FullName__c, PrimaryContactNo__c FROM Person__c
            ORDER BY LastModifiedDate DESC LIMIT 10];
    }
}

Thing is, I keep getting this error:

 

Error: MyController Compile Error: Variable does not exist: result at line 5 column 9

 

I've tried adding ".DateOfBirth__c" to the end of the braced SOQL to no avail as the original code had ".Name" at the end...

 

Any idea as to what I'm missing?

 

Cheers,

 

Dom

Hi there,

I've a junction object between two custom objects (Person and Address, the junction object is called Person Address). Thus I've a many-to-many object.

I've got the Person page layout to display the list of Addresses associated with the Person, I'm not so bothered about the Address page displaying Persons!

I can associate a Person with an Address only when the Address has already been created. Is it possible to create a new Address whilst still on the Person page?

I'm thinking it is though it might require a custom VisualForce page, not an issue but a pointer in the right direction would be very helpful. I've been scouring Google for ages but my Google-foo must be lacking as I'm not able to see anything quite like what I need :-(.

Thanks in advance

Dom

I just found out the way you can implement dynamic redirect with Flows embedded in a VF page. Here is an example of the VF page and the controller which redirect the user to the detail page of a Lead created within the Flow.

 

VF Page:

<apex:page controller="myAutoInsuranceController" sidebar="false" showHeader="false" >
<flow:interview name="Auto_Insurance_Quote" interview="{!myAutoFlow}" finishLocation="{!nextPage}"/>
</apex:page>

 

Controller:

public class myAutoInsuranceController {

public Flow.Interview.Auto_Insurance_Quote myAutoFlow { get; set; }

public String getmyID() {
if (myAutoFlow==null) return '';
else return myAutoFlow.vaLeadID;
}

public PageReference getNextPage(){
PageReference p = new PageReference('/' + getmyID() );
p.setRedirect(true);
return p;
}

}