• Shane Jay Hayes
  • NEWBIE
  • 10 Points
  • Member since 2015
  • Chief Information Officer
  • Net Claims Now


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 5
    Questions
  • 3
    Replies
I have a button on my account object that launches a VF page and in turn a Flow.  It works great!  
 
<apex:page standardController="Account" tabstyle="Account">
  <h1>Create a New Claim</h1>
  <flow:interview name="Create_a_Claim" finishLocation="{!URLFOR('/home/home.jsp')}">
  <apex:param name="Service_Provider" value="{!Account.Id}"/>
  <apex:param name="ClaimPOC" value="{!Account.Primary_Point_of_Contact__c}"/>
  </flow:interview>
</apex:page>

I need to create a new button that I will put into a VF page on the custom home screen for my Community users.  This button will obviously be on the home page and not the acount so I am having problems figuring out how to write the new VF page so it will gather the Users account ID and User ID.  Any and all help is appreciated.  Thank you in advance for any assistance.  If I am doing the hard way or there is an easier way just scream!
I have a couple of nearly identical Apex classes that I am trying to get test classes done for. Each uses a different object.  I was able to the the one that calls on the Account to work perfectly.  Now I am just trying to tweak it to get the other one that calls on a custom object to work equally perfect.  I keep getting an "invalid type" error.  Okay so here is the class I am trying to write the test class for:
 
public class CauseLossControllerEXT {
public blob picture { get; set; }
    public String errorMessage { get; set; }
    public Attachment	newAttach {get; set;}
    private final Claims__c claim;
    private final String  ERROR_IMG_TYPE    = 'The image must be in .jpg, .gif or .png format';   
    private Set<String> imagesTypes         = new Set<String> {'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif'};
    private Set<String> notAllowedTypes     = new Set<String> {'application/octet-stream'};
    private ApexPages.StandardController stdController;

    public CauseLossControllerEXT(ApexPages.StandardController stdController) {
        this.claim = (Claims__c)stdController.getRecord();
        this.stdController = stdController;
    }

    public PageReference save() {
        errorMessage = '';
        try {
            upsert claim;
            if (picture != null) {
                Attachment attachment = new Attachment();
                attachment.body = picture;
                attachment.name = 'causeofloss_' + claim.id;
                attachment.Description = 'Cause of Loss Photo';
                attachment.parentid = claim.id;
                insert attachment;
                claim.CauseofLossURL__c = '/servlet/servlet.FileDownload?file='
                                          + attachment.id;
                update claim;
            }
            return new ApexPages.StandardController(claim).view();
        } catch(System.Exception ex) {
            errorMessage = ex.getMessage();
            return null;
        }
    }
}

Here is the class I successfully wrote the test class for:
 
public class CompanyLogoControllerEXT {
public blob picture { get; set; }
    public String errorMessage { get; set; }
    public Attachment	newAttach {get; set;}
    private final Account account;
    private final String  ERROR_IMG_TYPE    = 'The image must be in .jpg, .gif or .png format';   
    private Set<String> imagesTypes         = new Set<String> {'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif'};
    private Set<String> notAllowedTypes     = new Set<String> {'application/octet-stream'};
    private ApexPages.StandardController stdController;

    public CompanyLogoControllerEXT(ApexPages.StandardController stdController) {
        this.account = (Account)stdController.getRecord();
        this.stdController = stdController;
    }

    public PageReference save() {
        errorMessage = '';
        try {
            upsert account;
            if (picture != null) {
                Attachment newAttach = new Attachment();
                newAttach.body = picture;
                newAttach.name = 'companylogo_' + account.id;
                newAttach.Description = 'Company Logo';
                newAttach.parentid = account.id;
                insert newAttach;
                account.CompLogoURL__c = '/servlet/servlet.FileDownload?file='
                                          + newAttach.id;
                update account;
            }
            return new ApexPages.StandardController(account).view();
        } catch(System.Exception ex) {
            errorMessage = ex.getMessage();
            return null;
        }
    }
}

Here is the SUCCESSFUL test class (100% coverage)
 
@isTest
public class CompanyLogoControllerEXTTest {
	@isTest
    static void testCompanyLogo() {
        Account acc=new Account();
        acc.Name='testAcc';
        ApexPages.StandardController sc = new ApexPages.StandardController( acc );
    	CompanyLogoControllerEXT comp=new CompanyLogoControllerEXT(sc);       
        String str='testblob';
        comp.picture=Blob.valueof(str);
        comp.save();
        delete acc;
        comp.save();
    }
}

I am trying to tweak that successful test class for the first class above (the CauseLossControllerEXT)

I got this far, below, but I know I have something wrong with the tweak.  Getting "invalid type" error on line 5
 
@isTest
public class CauseLossControllerEXTtest {
	@isTest
    static void testCauseLoss() {
        Claims__C acc=new claim();
        acc.Name='testAcc';
        ApexPages.StandardController sc = new ApexPages.StandardController( acc );
    	CauseLossControllerEXT comp=new CauseLossControllerEXT(sc);       
        String str='testblob';
        comp.picture=Blob.valueof(str);
        comp.save();
        delete acc;
        comp.save();
    }
}

Any help is greatly appreciated.
Probably not the best subject but I was having trouble trying to figure out what to call this.  I have a working Apex class that I use to upload photos.  I know want to add a line that will also update a custom field on the custom object when the photo is uploaded.  Below is the section of the current code.
 
public Boolean saveCurrentPicture(){
      Savepoint sp = Database.setSavepoint();
      try{
        delete [ Select Id From Attachment where ParentId =: this.parentId and name = 'During Mitigation' limit 1 ];
      this.newAttach.parentId = this.parentId;
          this.newAttach.name = 'During Mitigation';
          this.newAttach.Description = 'DuringMitPhoto';
          insert this.newAttach;
          return true;
      } 
      catch( Exception e ){
        this.error += ERROR_NO_SAVE+'<br/>';
        Database.rollback( sp );
        return false;
      }
    }

I would like to add this.
 
scope.DuringMitigationURL__c = '/servlet/servlet.FileDownload?file='
                                          + attachment.id;

I have a similar class that I am trying to combine into one function.  It currently uses the code I want to put into the original code top.  You can see that here:
 
public class DuringMitigationControllerEXT {
public blob picture { get; set; }
    public String errorMessage { get; set; }
    private final Room_Scope_Sheet__c scope;
    private final String  ERROR_IMG_TYPE    = 'The image must be in .jpg, .gif or .png format';   
    private Set<String> imagesTypes         = new Set<String> {'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif'};
    private Set<String> notAllowedTypes     = new Set<String> {'application/octet-stream'};
    private ApexPages.StandardController stdController;

    public DuringMitigationControllerEXT(ApexPages.StandardController stdController) {
        this.scope = (Room_Scope_Sheet__c)stdController.getRecord();
        this.stdController = stdController;
    }

    public PageReference save() {
        errorMessage = '';
        try {
            upsert scope;
            if (picture != null) {
                Attachment attachment = new Attachment();
                attachment.body = picture;
                attachment.name = 'duringmitigation_' + scope.id;
                attachment.Description = 'During Mitigation Photo';
                attachment.parentid = scope.id;
                insert attachment;
                scope.DuringMitigationURL__c = '/servlet/servlet.FileDownload?file='
                                          + attachment.id;
                update scope;
            }
            return new ApexPages.StandardController(scope).view();
        } catch(System.Exception ex) {
            errorMessage = ex.getMessage();
            return null;
        }
    }
}

So someone tell a noob what he is doing wrong.  I believe I am trying to fit a square hole in a round peg.
The below button works great on the full site but on Salesforce1 it throws a bad URL error.  See button setup below.  Any help/guidance is much appreciated.

Button setup
I have a VF element on my object, this element is used to upload an image to the object.  When I hit the upload or delete button it performs the action but then refreshes the object page within the VF element.  I would like it to refresh the entire object.  Hopefully this make sense lol.

Here is the current apex:commandbutton code: 
 
<apex:commandButton id="Accept" action="{!uploadAction}" value="Upload" onclick="return verifyNameLength();"></apex:commandButton>
            <apex:commandButton id="Delete" action="{!deleteAction}" value="Delete" rendered="{!hasPicture}" onclick="return confirm('Are you sure you want to delete the current image?')"></apex:commandButton>
Right now it looks like this (still building) before clicking anything

Before
After hitting upload or delete is looks like

After
The easiest way to fix this would be to have the button performs its action then refresh the entire object page.

Any help is appreciated!
 
I have a couple of nearly identical Apex classes that I am trying to get test classes done for. Each uses a different object.  I was able to the the one that calls on the Account to work perfectly.  Now I am just trying to tweak it to get the other one that calls on a custom object to work equally perfect.  I keep getting an "invalid type" error.  Okay so here is the class I am trying to write the test class for:
 
public class CauseLossControllerEXT {
public blob picture { get; set; }
    public String errorMessage { get; set; }
    public Attachment	newAttach {get; set;}
    private final Claims__c claim;
    private final String  ERROR_IMG_TYPE    = 'The image must be in .jpg, .gif or .png format';   
    private Set<String> imagesTypes         = new Set<String> {'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif'};
    private Set<String> notAllowedTypes     = new Set<String> {'application/octet-stream'};
    private ApexPages.StandardController stdController;

    public CauseLossControllerEXT(ApexPages.StandardController stdController) {
        this.claim = (Claims__c)stdController.getRecord();
        this.stdController = stdController;
    }

    public PageReference save() {
        errorMessage = '';
        try {
            upsert claim;
            if (picture != null) {
                Attachment attachment = new Attachment();
                attachment.body = picture;
                attachment.name = 'causeofloss_' + claim.id;
                attachment.Description = 'Cause of Loss Photo';
                attachment.parentid = claim.id;
                insert attachment;
                claim.CauseofLossURL__c = '/servlet/servlet.FileDownload?file='
                                          + attachment.id;
                update claim;
            }
            return new ApexPages.StandardController(claim).view();
        } catch(System.Exception ex) {
            errorMessage = ex.getMessage();
            return null;
        }
    }
}

Here is the class I successfully wrote the test class for:
 
public class CompanyLogoControllerEXT {
public blob picture { get; set; }
    public String errorMessage { get; set; }
    public Attachment	newAttach {get; set;}
    private final Account account;
    private final String  ERROR_IMG_TYPE    = 'The image must be in .jpg, .gif or .png format';   
    private Set<String> imagesTypes         = new Set<String> {'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif'};
    private Set<String> notAllowedTypes     = new Set<String> {'application/octet-stream'};
    private ApexPages.StandardController stdController;

    public CompanyLogoControllerEXT(ApexPages.StandardController stdController) {
        this.account = (Account)stdController.getRecord();
        this.stdController = stdController;
    }

    public PageReference save() {
        errorMessage = '';
        try {
            upsert account;
            if (picture != null) {
                Attachment newAttach = new Attachment();
                newAttach.body = picture;
                newAttach.name = 'companylogo_' + account.id;
                newAttach.Description = 'Company Logo';
                newAttach.parentid = account.id;
                insert newAttach;
                account.CompLogoURL__c = '/servlet/servlet.FileDownload?file='
                                          + newAttach.id;
                update account;
            }
            return new ApexPages.StandardController(account).view();
        } catch(System.Exception ex) {
            errorMessage = ex.getMessage();
            return null;
        }
    }
}

Here is the SUCCESSFUL test class (100% coverage)
 
@isTest
public class CompanyLogoControllerEXTTest {
	@isTest
    static void testCompanyLogo() {
        Account acc=new Account();
        acc.Name='testAcc';
        ApexPages.StandardController sc = new ApexPages.StandardController( acc );
    	CompanyLogoControllerEXT comp=new CompanyLogoControllerEXT(sc);       
        String str='testblob';
        comp.picture=Blob.valueof(str);
        comp.save();
        delete acc;
        comp.save();
    }
}

I am trying to tweak that successful test class for the first class above (the CauseLossControllerEXT)

I got this far, below, but I know I have something wrong with the tweak.  Getting "invalid type" error on line 5
 
@isTest
public class CauseLossControllerEXTtest {
	@isTest
    static void testCauseLoss() {
        Claims__C acc=new claim();
        acc.Name='testAcc';
        ApexPages.StandardController sc = new ApexPages.StandardController( acc );
    	CauseLossControllerEXT comp=new CauseLossControllerEXT(sc);       
        String str='testblob';
        comp.picture=Blob.valueof(str);
        comp.save();
        delete acc;
        comp.save();
    }
}

Any help is greatly appreciated.

Hi,

 

I have a custom object which has attachments.

I want to take the recent attachment and copy that link on to my record (custom field).

How can i do that??

 

 

We are looking for a Salesforce Developer to join our team of amazing Salesforce engineers. We are an established Salesforce end user with a highly customized org and complete executive buy-in for the Salesforce platform. You will work on highly challenging projects on a day to day basis. This is a once in a lifetime opportunity.

Qualified Candidates will have the following skills and experience:
- 2+ Salesforce Experience
- Hands on APEX/Visualforce/SOQL 
- API's and basic Architectural skills preferred 
- Salesforce.com Certified Developer preferred
- Sales and Service Cloud project experience 
- Ability to turn technical requirements into Business Solutions

Location: Weston, FL.

The job posting is not online yet, but reach out to me via twitter (@luiseluciani) if you are interested, I am the hiring manager. Sorry no visa sponsorship, you must have a valid US work permit. 

Some of the benefits we offer:

100% Employer paid health coverage for employee and family (includes medical PPO plan, choice of dental plan, prescription and vision)
100% Employer paid health coverage for same sex married couples
100% Employer paid life insurance to match 1x annual salary
100% Employer paid long term disability
$10,000 spouse life insurance
Restricted Stock Units granted to every regular full-time employee
401k Retirement Savings Plan with 35% company match on every dollar of employee contribution
Paid Time Off starting with 15 days on 1st year of employment
Paid ‘UltiService’ Days (2 days per year/ per employee for charity work)
Online health, wellness and work-life balance service
Tuition/Certification Reimbursements
Paid Maternity/Paternity/Adoption Leave
Flexible Spending Accounts
Credit Union
One remote day per week

Read more about Ultimate Software here: http://www.ultimatesoftware.com/careers-at-ultimate

Check out the glassdoor reviews here: http://www.glassdoor.com/Overview/Working-at-Ultimate-Software-EI_IE7900.11,28.htm

You can reach me via twitter https://twitter.com/luiseluciani
Work REMOTELY for this fast growing Silver Level Partner!!Great Salary and Benefits, Work/Life Balance. If interested please contact me: nancy@tech2resources.com.  Posting:  http://jobs.tech2resources.com/Salesforce-Developer-Jobs-in-DC-Metro-area-DC/2679562
Hi there!

We are looking for a contractor for some Salesforce development work -- probably about 80 hours in the next couple of months but someone who can grow into a long term partner.  Prefer an experienced independent contractor, preferably US/Canada based.  I work for a financial services company based in NYC.

Please contact me at tmlesnick at gmail dot com with details of your experience.

Thank you!

Tom