You need to sign in to do that
Don't have an account?
Marry Stein
apex update does not work
Hello guys,
pretty simple, but i can not figure out, where the error comes from.
I would appreciate your help !
Thank you,
Marry
pretty simple, but i can not figure out, where the error comes from.
public class UpdateBillingAdress { public static void retrieveAdress (Opportunity opp){ Account billAcc = [ Select ShippingStreet, ShippingCity, ShippingPostalCode, ShippingCountry FROM Account WHERE Id =: opp.umsatz_durch_Account__c ]; Account shipAcc = [ Select BillingStreet, BillingCity, BillingPostalCode, BillingCountry FROM Account WHERE Id =: opp.AccountId ]; Boolean condition = ( !String.isBlank(billAcc.ShippingStreet) && !String.isBlank(billAcc.ShippingPostalCode) && !String.isBlank(billAcc.ShippingCity) && !String.isBlank(billAcc.ShippingCountry) ); if(condition){ shipAcc.BillingStreet = billAcc.ShippingStreet; shipAcc.BillingPostalCode = billAcc.ShippingPostalCode; shipAcc.BillingCity = billAcc.ShippingCity; shipAcc.BillingCountry = billAcc.ShippingCountry; shipAcc.alternative_Rechnungsanschrift__c = true; update shipAcc; } } }
@isTest public class TestUpdateBillingAdress { @isTest static void testUpdate(){ Account billAcc = DataFactory.createAccount(); Account shipAcc = DataFactory.createAccount(); insert billAcc; insert shipAcc; Opportunity opp = DataFactory.createOpportunity('40 - Converted/Demo agreed', shipAcc.Id); opp.umsatz_durch_Account__c = billAcc.Id; insert opp; shipAcc.BillingStreet = ' '; shipAcc.BillingCity = ' '; shipAcc.BillingPostalCode = ' '; shipAcc.BillingCountry = ' '; shipAcc.alternative_Rechnungsanschrift__c = true; update shipAcc; Boolean condition = ( !String.isBlank(billAcc.ShippingStreet) && !String.isBlank(billAcc.ShippingPostalCode) && !String.isBlank(billAcc.ShippingCity) && !String.isBlank(billAcc.ShippingCountry) ); System.debug('condition' + condition); UpdateBillingAdress.retrieveAdress(opp); System.assertEquals(shipAcc.BillingStreet, billAcc.ShippingStreet); // this should be true } }
I would appreciate your help !
Thank you,
Marry
All Answers
What is the error message you are seeing?
Thanks
Thank you swetha
Your function checks for the condition that ALL of your shipping fields are NOT blank. It appears that if even ONE of them is blank, then the condition is false. If the condition is false, then your shipping address info is not copied into your billing address info.
So in your test, are you 100% sure that ALL of your shipping fields are NOT blank? We can't see what your data factory returns, so we don't know whether your default account has shipping address information in every field.
UpdateBillingAdress.retrieveAdress(opp);
shipAcc = [select BillingStreet from Account where id =:shipAcc.id];
billAcc= [select BillingStreet from Account where id =:billAcc.id]; //you may not need this line.
System.assertEquals(shipAcc.BillingStreet, billAcc.ShippingStreet); // this should be true
Were you able to fix the issue based on above inputs? If so, please mark the helpful answer as best to close this thread. I am happy to look further if you need assistance.Thanks
It looks like our team of experts can help you resolve this ticket. We have Salesforce global help-desk support and you can log a case and our Customer Success Agents will help you solve this issue. You can also speak to them on live chat. Click on the below link to contact our help-desk. Trust me it is a support service that we are offering for free!
https://jbshelpdesk.secure.force.com
Thanks,
Jarvis SFDC team